|
1 | 1 | #![allow(deprecated)] |
2 | | -use super::{is_main_window, shared_hide_window, shared_set_always_on_top, shared_show_window}; |
3 | 2 | use crate::MAIN_WINDOW_LABEL; |
4 | 3 | use tauri::{AppHandle, Runtime, WebviewWindow, command}; |
5 | 4 | use tauri_nspanel::{CollectionBehavior, ManagerExt, PanelLevel}; |
6 | 5 |
|
7 | | -pub enum MacOSPanelStatus { |
| 6 | +enum MacOSPanelStatus { |
8 | 7 | Show, |
9 | 8 | Hide, |
10 | 9 | SetAlwaysOnTop(bool), |
11 | 10 | } |
12 | 11 |
|
13 | | -#[command] |
14 | | -pub async fn show_window<R: Runtime>(app_handle: AppHandle<R>, window: WebviewWindow<R>) { |
15 | | - if is_main_window(&window) { |
16 | | - set_macos_panel(&app_handle, &window, MacOSPanelStatus::Show); |
17 | | - } else { |
18 | | - shared_show_window(&app_handle, &window); |
19 | | - } |
20 | | -} |
21 | | - |
22 | | -#[command] |
23 | | -pub async fn hide_window<R: Runtime>(app_handle: AppHandle<R>, window: WebviewWindow<R>) { |
24 | | - if is_main_window(&window) { |
25 | | - set_macos_panel(&app_handle, &window, MacOSPanelStatus::Hide); |
26 | | - } else { |
27 | | - shared_hide_window(&app_handle, &window); |
28 | | - } |
| 12 | +fn is_main_window<R: Runtime>(window: &WebviewWindow<R>) -> bool { |
| 13 | + window.label() == MAIN_WINDOW_LABEL |
29 | 14 | } |
30 | 15 |
|
31 | | -#[command] |
32 | | -pub async fn set_always_on_top<R: Runtime>( |
33 | | - app_handle: AppHandle<R>, |
34 | | - window: WebviewWindow<R>, |
35 | | - always_on_top: bool, |
36 | | -) { |
37 | | - if is_main_window(&window) { |
38 | | - set_macos_panel( |
39 | | - &app_handle, |
40 | | - &window, |
41 | | - MacOSPanelStatus::SetAlwaysOnTop(always_on_top), |
42 | | - ); |
43 | | - } else { |
44 | | - shared_set_always_on_top(&app_handle, &window, always_on_top); |
45 | | - } |
46 | | -} |
47 | | - |
48 | | -pub fn set_macos_panel<R: Runtime>( |
| 16 | +fn set_macos_panel<R: Runtime>( |
49 | 17 | app_handle: &AppHandle<R>, |
50 | 18 | window: &WebviewWindow<R>, |
51 | 19 | status: MacOSPanelStatus, |
@@ -91,6 +59,49 @@ pub fn set_macos_panel<R: Runtime>( |
91 | 59 | } |
92 | 60 | } |
93 | 61 |
|
| 62 | +#[command] |
| 63 | +pub async fn show_window<R: Runtime>(app_handle: AppHandle<R>, window: WebviewWindow<R>) { |
| 64 | + if is_main_window(&window) { |
| 65 | + set_macos_panel(&app_handle, &window, MacOSPanelStatus::Show); |
| 66 | + } else { |
| 67 | + let _ = window.show(); |
| 68 | + let _ = window.unminimize(); |
| 69 | + let _ = window.set_focus(); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +#[command] |
| 74 | +pub async fn hide_window<R: Runtime>(app_handle: AppHandle<R>, window: WebviewWindow<R>) { |
| 75 | + if is_main_window(&window) { |
| 76 | + set_macos_panel(&app_handle, &window, MacOSPanelStatus::Hide); |
| 77 | + } else { |
| 78 | + let _ = window.hide(); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +#[command] |
| 83 | +pub async fn set_always_on_top<R: Runtime>( |
| 84 | + app_handle: AppHandle<R>, |
| 85 | + window: WebviewWindow<R>, |
| 86 | + always_on_top: bool, |
| 87 | +) { |
| 88 | + if is_main_window(&window) { |
| 89 | + return set_macos_panel( |
| 90 | + &app_handle, |
| 91 | + &window, |
| 92 | + MacOSPanelStatus::SetAlwaysOnTop(always_on_top), |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + if always_on_top { |
| 97 | + let _ = window.set_always_on_bottom(false); |
| 98 | + let _ = window.set_always_on_top(true); |
| 99 | + } else { |
| 100 | + let _ = window.set_always_on_top(false); |
| 101 | + let _ = window.set_always_on_bottom(true); |
| 102 | + } |
| 103 | +} |
| 104 | + |
94 | 105 | #[command] |
95 | 106 | pub async fn set_taskbar_visibility<R: Runtime>(app_handle: AppHandle<R>, visible: bool) { |
96 | 107 | let _ = app_handle.set_dock_visibility(visible); |
|
0 commit comments