chore: upgrade tauri_nspanel to v2.1

This commit is contained in:
ayang
2025-07-21 18:16:48 +08:00
parent 93137883e6
commit d36aa0d0fc
4 changed files with 60 additions and 116 deletions

75
Cargo.lock generated
View File

@@ -734,7 +734,7 @@ checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a"
dependencies = [
"bitflags 1.3.2",
"block",
"cocoa-foundation 0.1.2",
"cocoa-foundation",
"core-foundation 0.9.4",
"core-graphics 0.22.3",
"foreign-types 0.3.2",
@@ -742,22 +742,6 @@ dependencies = [
"objc",
]
[[package]]
name = "cocoa"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad36507aeb7e16159dfe68db81ccc27571c3ccd4b76fb2fb72fc59e7a4b1b64c"
dependencies = [
"bitflags 2.9.1",
"block",
"cocoa-foundation 0.2.1",
"core-foundation 0.10.1",
"core-graphics 0.24.0",
"foreign-types 0.5.0",
"libc",
"objc",
]
[[package]]
name = "cocoa-foundation"
version = "0.1.2"
@@ -772,19 +756,6 @@ dependencies = [
"objc",
]
[[package]]
name = "cocoa-foundation"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81411967c50ee9a1fc11365f8c585f863a22a9697c89239c452292c40ba79b0d"
dependencies = [
"bitflags 2.9.1",
"block",
"core-foundation 0.10.1",
"core-graphics-types 0.2.0",
"objc",
]
[[package]]
name = "combine"
version = "4.6.7"
@@ -2962,17 +2933,6 @@ dependencies = [
"malloc_buf",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc-sys"
version = "0.3.5"
@@ -3199,15 +3159,6 @@ dependencies = [
"objc2-foundation 0.3.1",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.36.7"
@@ -3340,6 +3291,12 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "pastey"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a8cb46bdc156b1c90460339ae6bfd45ba0394e5effbaa640badb4987fdc261"
[[package]]
name = "pathdiff"
version = "0.2.3"
@@ -3908,7 +3865,7 @@ name = "rdev"
version = "0.5.0-2"
source = "git+https://github.com/ayangweb/rdev#a8d5724f4533a69958280aa4df6bf6bca042d064"
dependencies = [
"cocoa 0.24.1",
"cocoa",
"core-foundation 0.9.4",
"core-foundation-sys",
"core-graphics 0.22.3",
@@ -4933,17 +4890,13 @@ dependencies = [
[[package]]
name = "tauri-nspanel"
version = "2.0.1"
source = "git+https://github.com/ahkohd/tauri-nspanel?branch=v2#dc1563b2c71d3699dc67028080e43aade0575bcf"
version = "2.1.0"
source = "git+https://github.com/ahkohd/tauri-nspanel?branch=v2.1#10b6934444ab4f23edf8d969bbb5809930242a2e"
dependencies = [
"bitflags 2.9.1",
"block",
"cocoa 0.26.1",
"core-foundation 0.10.1",
"core-graphics 0.24.0",
"objc",
"objc-foundation",
"objc_id",
"objc2 0.6.1",
"objc2-app-kit",
"objc2-foundation 0.3.1",
"pastey",
"tauri",
]

View File

@@ -17,5 +17,5 @@ serde = "1"
serde_json = "1"
fs_extra = "1"
tauri-plugin = { version = "2", features = [ "build" ] }
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2.1" }
tauri-plugin-custom-window = { path = "./src-tauri/src/plugins/window" }

View File

@@ -1,16 +1,26 @@
#![allow(deprecated)]
use tauri::{AppHandle, Emitter, EventTarget, WebviewWindow};
use tauri_nspanel::{WebviewWindowExt, cocoa::appkit::NSWindowCollectionBehavior, panel_delegate};
use tauri_plugin_custom_window::MAIN_WINDOW_LABEL;
use tauri::{AppHandle, WebviewWindow};
use tauri_nspanel::{CollectionBehavior, StyleMask, WebviewWindowExt, tauri_panel};
#[allow(non_upper_case_globals)]
const NSWindowStyleMaskNonActivatingPanel: i32 = 1 << 7;
#[allow(non_upper_case_globals)]
const NSResizableWindowMask: i32 = 1 << 3;
const WINDOW_FOCUS_EVENT: &str = "tauri://focus";
const WINDOW_BLUR_EVENT: &str = "tauri://blur";
const WINDOW_MOVED_EVENT: &str = "tauri://move";
const WINDOW_RESIZED_EVENT: &str = "tauri://resize";
// const WINDOW_FOCUS_EVENT: &str = "tauri://focus";
// const WINDOW_BLUR_EVENT: &str = "tauri://blur";
// const WINDOW_MOVED_EVENT: &str = "tauri://move";
// const WINDOW_RESIZED_EVENT: &str = "tauri://resize";
tauri_panel! {
panel!(MainPanel {
config: {
canBecomeKeyWindow: true,
canBecomeMainWindow: false
}
})
panel_event!(PanelEventHandler {
windowDidBecomeKey(notification: &NSNotification) -> (),
windowDidResignKey(notification: &NSNotification) -> (),
windowDidMove(notification: &NSNotification) -> (),
windowDidResize(notification: &NSNotification) -> ()
})
}
pub fn platform(
app_handle: &AppHandle,
@@ -21,50 +31,32 @@ pub fn platform(
let _ = app_handle.set_dock_visibility(false);
let panel = main_window.to_panel().unwrap();
let panel = main_window.to_panel::<MainPanel>().unwrap();
panel.set_style_mask(NSWindowStyleMaskNonActivatingPanel | NSResizableWindowMask);
panel.set_style_mask(StyleMask::empty().nonactivating_panel().resizable().into());
panel.set_collection_behaviour(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces
| NSWindowCollectionBehavior::NSWindowCollectionBehaviorStationary
| NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary,
panel.set_collection_behavior(
CollectionBehavior::new()
.full_screen_auxiliary()
.can_join_all_spaces()
.into(),
);
let delegate = panel_delegate!(EcoPanelDelegate {
window_did_become_key,
window_did_resign_key,
window_did_resize,
window_did_move
let handler = PanelEventHandler::new();
handler.window_did_become_key(move |notification| {
println!("window_did_become_key {:?}", notification);
});
delegate.set_listener(Box::new(move |delegate_name: String| {
let target = EventTarget::labeled(MAIN_WINDOW_LABEL);
handler.window_did_resign_key(move |notification| {
println!("window_did_resign_key {:?}", notification);
});
let window_move_event = || {
if let Ok(position) = main_window.outer_position() {
let _ = main_window.emit_to(target.clone(), WINDOW_MOVED_EVENT, position);
}
};
handler.window_did_move(move |notification| {
println!("window_did_move {:?}", notification);
});
match delegate_name.as_str() {
"window_did_become_key" => {
let _ = main_window.emit_to(target, WINDOW_FOCUS_EVENT, true);
}
"window_did_resign_key" => {
let _ = main_window.emit_to(target, WINDOW_BLUR_EVENT, true);
}
"window_did_resize" => {
window_move_event();
if let Ok(size) = main_window.inner_size() {
let _ = main_window.emit_to(target, WINDOW_RESIZED_EVENT, size);
}
}
"window_did_move" => window_move_event(),
_ => (),
}
}));
panel.set_delegate(delegate);
handler.window_did_resize(move |notification| {
println!("window_did_resize {:?}", notification);
});
}

View File

@@ -1,8 +1,7 @@
#![allow(deprecated)]
use super::{is_main_window, shared_hide_window, shared_set_always_on_top, shared_show_window};
use crate::MAIN_WINDOW_LABEL;
use tauri::{AppHandle, Runtime, WebviewWindow, command};
use tauri_nspanel::{ManagerExt, cocoa::appkit::NSMainMenuWindowLevel};
use tauri_nspanel::{ManagerExt, PanelLevel};
pub enum MacOSPanelStatus {
Show,
@@ -60,11 +59,11 @@ pub fn set_macos_panel<R: Runtime>(
panel.show();
}
MacOSPanelStatus::Hide => {
panel.order_out(None);
panel.hide();
}
MacOSPanelStatus::SetAlwaysOnTop(always_on_top) => {
if always_on_top {
panel.set_level(NSMainMenuWindowLevel);
panel.set_level(PanelLevel::MainMenu.value());
} else {
panel.set_level(-1);
};