use objc2::MainThreadMarker;
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy};
use tauri_runtime::RuntimeInitArgs;
use tauri_runtime_wry::{WindowBuilderWrapper, WryWindowDispatcher};
pub(crate) fn runtime_init_args(app_id: Option<&str>) -> Result<RuntimeInitArgs, String> {
let _ = app_id;
Ok(RuntimeInitArgs::default())
}
pub(crate) fn display_places_windows() -> bool {
false
}
pub(crate) fn transparent_window(
builder: WindowBuilderWrapper,
transparent: bool,
) -> WindowBuilderWrapper {
let _ = transparent;
builder
}
#[cfg(feature = "tauri-webview-test-support")]
pub(crate) fn client_logical_size(
window: &WryWindowDispatcher<()>,
) -> Result<Option<(f64, f64)>, String> {
use objc2_app_kit::NSView;
use tauri_runtime::WindowDispatch as _;
use wry::raw_window_handle::RawWindowHandle;
let handle = window.window_handle().map_err(|error| error.to_string())?;
let RawWindowHandle::AppKit(handle) = handle.as_raw() else {
return Err("unexpected native window handle".into());
};
let view = unsafe { handle.ns_view.cast::<NSView>().as_ref() };
let content = view
.window()
.and_then(|window| window.contentView())
.ok_or("the view has no window content view")?;
let size = content.frame().size;
Ok(Some((size.width, size.height)))
}
pub(crate) fn exclude_from_taskbar(window: &WryWindowDispatcher<()>) -> Result<(), String> {
let _ = window;
let main_thread = MainThreadMarker::new()
.ok_or("the activation policy can only change on the main thread")?;
let application = NSApplication::sharedApplication(main_thread);
if application.activationPolicy() == NSApplicationActivationPolicy::Accessory
|| application.setActivationPolicy(NSApplicationActivationPolicy::Accessory)
{
Ok(())
} else {
Err("AppKit refused the accessory activation policy".into())
}
}
#[cfg(feature = "tauri-webview-test-support")]
pub(crate) fn verify_presentation(
_window: &WryWindowDispatcher<()>,
_webview: Option<&wry::WebView>,
expected: &crate::tauri::ExpectedPresentation<'_>,
) -> Result<(), String> {
let crate::tauri::ExpectedPresentation {
app_id,
decorations,
transparent,
skip_taskbar,
} = expected;
let _ = (app_id, decorations, transparent);
if *skip_taskbar {
let main_thread =
MainThreadMarker::new().ok_or("presentation check ran off the main thread")?;
let policy = NSApplication::sharedApplication(main_thread).activationPolicy();
if policy != NSApplicationActivationPolicy::Accessory {
return Err(format!(
"skip-taskbar window left the activation policy at {policy:?}"
));
}
}
Ok(())
}