Try to weak-link ScreenCaptureKit always (#28585)

Closes #ISSUE

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Conrad Irwin 2025-04-11 11:38:14 -06:00 committed by GitHub
parent 66b3e03baa
commit c2e3134963
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 8 additions and 12 deletions

View file

@ -7,8 +7,6 @@ fn main() {
if cfg!(target_os = "macos") {
println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.15.7");
// Weakly link ScreenCaptureKit to ensure can be used on macOS 10.15+.
println!("cargo:rustc-link-arg=-Wl,-weak_framework,ScreenCaptureKit");
}
// Populate git sha environment variable if git is available

View file

@ -77,8 +77,8 @@ mod macos {
fn generate_dispatch_bindings() {
println!("cargo:rustc-link-lib=framework=System");
println!("cargo:rustc-link-lib=framework=ScreenCaptureKit");
println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h");
// weak link to support Catalina
println!("cargo:rustc-link-arg=-Wl,-weak_framework,ScreenCaptureKit");
let bindings = bindgen::Builder::default()
.header("src/platform/mac/dispatch.h")

View file

@ -2,7 +2,7 @@ use super::{
BoolExt,
attributed_string::{NSAttributedString, NSMutableAttributedString},
events::key_to_native,
renderer, screen_capture,
is_macos_version_at_least, renderer, screen_capture,
};
use crate::{
Action, AnyWindowHandle, BackgroundExecutor, ClipboardEntry, ClipboardItem, ClipboardString,
@ -22,8 +22,8 @@ use cocoa::{
},
base::{BOOL, NO, YES, id, nil, selector},
foundation::{
NSArray, NSAutoreleasePool, NSBundle, NSData, NSInteger, NSProcessInfo, NSRange, NSString,
NSUInteger, NSURL,
NSArray, NSAutoreleasePool, NSBundle, NSData, NSInteger, NSOperatingSystemVersion,
NSProcessInfo, NSRange, NSString, NSUInteger, NSURL,
},
};
use core_foundation::{
@ -553,7 +553,8 @@ impl Platform for MacPlatform {
}
fn is_screen_capture_supported(&self) -> bool {
true
let min_version = NSOperatingSystemVersion::new(12, 3, 0);
is_macos_version_at_least(min_version)
}
fn screen_capture_sources(

View file

@ -37,9 +37,6 @@ pub struct MacScreenCaptureStream {
sc_stream_output: id,
}
#[link(name = "ScreenCaptureKit", kind = "framework")]
unsafe extern "C" {}
static mut DELEGATE_CLASS: *const Class = ptr::null();
static mut OUTPUT_CLASS: *const Class = ptr::null();
const FRAME_CALLBACK_IVAR: &str = "frame_callback";

View file

@ -1568,7 +1568,7 @@ extern "C" fn window_will_exit_fullscreen(this: &Object, _: Sel, _: id) {
}
}
fn is_macos_version_at_least(version: NSOperatingSystemVersion) -> bool {
pub(crate) fn is_macos_version_at_least(version: NSOperatingSystemVersion) -> bool {
unsafe { NSProcessInfo::processInfo(nil).isOperatingSystemAtLeastVersion(version) }
}