fix: add macOS version detection and adjust close button frame for older versions

This commit is contained in:
Bohdan Triapitsyn
2025-12-08 01:07:48 +02:00
parent 921f691ebe
commit e2c9b8238a
+30 -2
View File
@@ -221,18 +221,24 @@ async fn desktop_open_devtools(window: WebviewWindow) -> Result<(), String> {
Ok(())
}
#[cfg(target_os = "macos")]
fn get_macos_major_version() -> isize {
use objc2_foundation::NSProcessInfo;
let process_info = NSProcessInfo::processInfo();
let version = process_info.operatingSystemVersion();
version.majorVersion
}
#[cfg(target_os = "macos")]
fn prevent_app_nap() {
use objc2_foundation::{NSActivityOptions, NSProcessInfo, NSString};
// NSActivityUserInitiated (0x00FFFFFF) | NSActivityLatencyCritical (0xFF00000000)
let options = NSActivityOptions(0x00FFFFFF | 0xFF00000000);
let reason = NSString::from_str("Prevent App Nap");
let process_info = NSProcessInfo::processInfo();
let activity = process_info.beginActivityWithOptions_reason(options, &reason);
// Leak the activity token to keep it active indefinitely
std::mem::forget(activity);
info!("[macos] App Nap prevention enabled via objc2");
@@ -280,6 +286,28 @@ fn main() {
} else {
info!("[desktop:vibrancy] Applied macOS Sidebar vibrancy to main window");
}
let macos_version = get_macos_major_version();
info!("[macos] Detected macOS version: {}", macos_version);
if macos_version < 26 {
use objc::{msg_send, sel, sel_impl, runtime::Object};
if let Ok(ns_window) = window.ns_window() {
unsafe {
let ns_window = ns_window.cast::<Object>();
let close_button: *mut Object = msg_send![ns_window, standardWindowButton: 0u64];
if !close_button.is_null() {
let superview: *mut Object = msg_send![close_button, superview];
if !superview.is_null() {
let frame: ((f64, f64), (f64, f64)) = msg_send![superview, frame];
let new_frame = ((frame.0.0, frame.0.1 - 6.0), frame.1);
let _: () = msg_send![superview, setFrame: new_frame];
}
}
}
}
}
}
if let Some(saved) = &stored_state {