use objc2::{class, msg_send, runtime::AnyObject};
use tauri::{Runtime, WebviewWindow};
const Level:isize = 25;
const CanJoinAllSpaces:u64 = 1 << 0;
const Stationary:u64 = 1 << 4;
const IgnoresCycle:u64 = 1 << 6;
const FullScreenAuxiliary:u64 = 1 << 8;
const Regular:isize = 0;
const Accessory:isize = 1;
pub fn raise<R:Runtime>(window:&WebviewWindow<R>) {
let Ok(pointer) = window.ns_window() else {
return;
};
let ns_window = pointer as *mut AnyObject;
let behavior = CanJoinAllSpaces | Stationary | IgnoresCycle | FullScreenAuxiliary;
let _ = (!ns_window.is_null()).then(|| unsafe {
let _:() = msg_send![ns_window, setLevel: Level];
let _:() = msg_send![ns_window, setCollectionBehavior: behavior];
let _:() = msg_send![ns_window, setIgnoresMouseEvents: true];
});
}
pub fn dock(visible:bool) {
let policy = match visible {
true => Regular,
false => Accessory,
};
unsafe {
let application:*mut AnyObject = msg_send![class!(NSApplication), sharedApplication];
let _ = (!application.is_null()).then(|| {
let _:bool = msg_send![application, setActivationPolicy: policy];
});
}
}