@@ -11,11 +11,11 @@ pub async fn create_draw_window(app: AppHandle) -> Result<(), String> {
1111 log:: info!( "Draw window exists, showing it" ) ;
1212 let _ = window. show ( ) ;
1313 let _ = window. set_focus ( ) ;
14-
14+
1515 // 重新设置窗口层级以覆盖菜单栏和 Dock
1616 #[ cfg( target_os = "macos" ) ]
1717 set_window_above_menubar ( & window) ?;
18-
18+
1919 let _ = window. emit ( "start-screenshot" , ( ) ) ;
2020 return Ok ( ( ) ) ;
2121 }
@@ -45,25 +45,21 @@ pub async fn create_draw_window(app: AppHandle) -> Result<(), String> {
4545 ) ;
4646
4747 // 创建新窗口
48- let window = WebviewWindowBuilder :: new (
49- & app,
50- "draw" ,
51- WebviewUrl :: App ( "pages/draw.html" . into ( ) ) ,
52- )
53- . title ( "Screenshot Editor" )
54- . position ( logical_x, logical_y)
55- . inner_size ( logical_width, logical_height)
56- . decorations ( false )
57- . transparent ( true )
58- . resizable ( false )
59- . maximizable ( false )
60- . minimizable ( false )
61- . shadow ( false )
62- . skip_taskbar ( true )
63- . always_on_top ( true )
64- . focused ( true )
65- . build ( )
66- . map_err ( |e| format ! ( "Failed to create window: {}" , e) ) ?;
48+ let window = WebviewWindowBuilder :: new ( & app, "draw" , WebviewUrl :: App ( "pages/draw.html" . into ( ) ) )
49+ . title ( "Screenshot Editor" )
50+ . position ( logical_x, logical_y)
51+ . inner_size ( logical_width, logical_height)
52+ . decorations ( false )
53+ . transparent ( true )
54+ . resizable ( false )
55+ . maximizable ( false )
56+ . minimizable ( false )
57+ . shadow ( false )
58+ . skip_taskbar ( true )
59+ . always_on_top ( true )
60+ . focused ( true )
61+ . build ( )
62+ . map_err ( |e| format ! ( "Failed to create window: {}" , e) ) ?;
6763
6864 // macOS: 设置窗口层级以覆盖菜单栏和 Dock
6965 #[ cfg( target_os = "macos" ) ]
@@ -80,25 +76,27 @@ pub async fn create_draw_window(app: AppHandle) -> Result<(), String> {
8076fn set_window_above_menubar ( window : & tauri:: WebviewWindow ) -> Result < ( ) , String > {
8177 use cocoa:: appkit:: { NSMainMenuWindowLevel , NSWindow , NSWindowCollectionBehavior } ;
8278 use cocoa:: base:: id;
83-
79+
8480 // 获取 NSWindow 指针,转换为 usize 以便在线程间传递
85- let ns_window_ptr = window. ns_window ( )
86- . map_err ( |e| format ! ( "Failed to get NSWindow: {:?}" , e) ) ? as usize ;
87-
88- window. run_on_main_thread ( move || unsafe {
89- let ns_window = ns_window_ptr as id ;
90-
91- // 设置窗口层级高于菜单栏
92- // NSMainMenuWindowLevel = 24, 我们使用 25 确保覆盖所有
93- ns_window. setLevel_ ( ( NSMainMenuWindowLevel + 1 ) as i64 ) ;
94-
95- // 设置窗口行为:可以出现在所有空间、静止、全屏辅助
96- let behavior = NSWindowCollectionBehavior :: NSWindowCollectionBehaviorCanJoinAllSpaces
97- | NSWindowCollectionBehavior :: NSWindowCollectionBehaviorStationary
98- | NSWindowCollectionBehavior :: NSWindowCollectionBehaviorFullScreenAuxiliary ;
99-
100- ns_window. setCollectionBehavior_ ( behavior) ;
101- } ) . map_err ( |e| format ! ( "Failed to set window level: {:?}" , e) )
81+ let ns_window_ptr =
82+ window. ns_window ( ) . map_err ( |e| format ! ( "Failed to get NSWindow: {:?}" , e) ) ? as usize ;
83+
84+ window
85+ . run_on_main_thread ( move || unsafe {
86+ let ns_window = ns_window_ptr as id ;
87+
88+ // 设置窗口层级高于菜单栏
89+ // NSMainMenuWindowLevel = 24, 我们使用 25 确保覆盖所有
90+ ns_window. setLevel_ ( ( NSMainMenuWindowLevel + 1 ) as i64 ) ;
91+
92+ // 设置窗口行为:可以出现在所有空间、静止、全屏辅助
93+ let behavior = NSWindowCollectionBehavior :: NSWindowCollectionBehaviorCanJoinAllSpaces
94+ | NSWindowCollectionBehavior :: NSWindowCollectionBehaviorStationary
95+ | NSWindowCollectionBehavior :: NSWindowCollectionBehaviorFullScreenAuxiliary ;
96+
97+ ns_window. setCollectionBehavior_ ( behavior) ;
98+ } )
99+ . map_err ( |e| format ! ( "Failed to set window level: {:?}" , e) )
102100}
103101
104102/// 关闭截图窗口
@@ -107,11 +105,8 @@ pub async fn close_draw_window(app: AppHandle) -> Result<(), String> {
107105 log:: info!( "API: close_draw_window called" ) ;
108106
109107 if let Some ( window) = app. get_webview_window ( "draw" ) {
110- window
111- . destroy ( )
112- . map_err ( |e| format ! ( "Failed to destroy window: {}" , e) ) ?;
108+ window. destroy ( ) . map_err ( |e| format ! ( "Failed to destroy window: {}" , e) ) ?;
113109 }
114110
115111 Ok ( ( ) )
116112}
117-
0 commit comments