22mod app;
33mod util;
44
5- use std:: str:: FromStr ;
6-
75use app:: { invoke, menu:: set_system_tray, window} ;
86use invoke:: { download_file, download_file_by_binary} ;
7+ use std:: str:: FromStr ;
8+ use std:: sync:: { Arc , Mutex } ;
9+ use std:: time:: { Duration , Instant } ;
10+
911use tauri:: Manager ;
1012use tauri_plugin_global_shortcut:: { GlobalShortcutExt , Shortcut } ;
1113use tauri_plugin_window_state:: Builder as windowStatePlugin;
1214use util:: { get_data_dir, get_pake_config} ;
1315use window:: get_window;
1416
15- #[ cfg( target_os = "macos" ) ]
16- use std:: time:: Duration ;
17-
1817pub fn run_app ( ) {
1918 let ( pake_config, tauri_config) = get_pake_config ( ) ;
2019
@@ -24,9 +23,18 @@ pub fn run_app() {
2423
2524 // Save the value of toggle_app_shortcut before pake_config is moved
2625 let activation_shortcut = pake_config. windows [ 0 ] . activation_shortcut . clone ( ) ;
26+ let init_fullscreen = pake_config. windows [ 0 ] . fullscreen . clone ( ) ;
27+
28+ let window_state_plugin = if init_fullscreen {
29+ windowStatePlugin:: default ( )
30+ . with_state_flags ( tauri_plugin_window_state:: StateFlags :: FULLSCREEN )
31+ . build ( )
32+ } else {
33+ windowStatePlugin:: default ( ) . build ( )
34+ } ;
2735
2836 tauri_app
29- . plugin ( windowStatePlugin :: default ( ) . build ( ) )
37+ . plugin ( window_state_plugin )
3038 . plugin ( tauri_plugin_oauth:: init ( ) )
3139 . plugin ( tauri_plugin_http:: init ( ) )
3240 . plugin ( tauri_plugin_shell:: init ( ) )
@@ -38,6 +46,7 @@ pub fn run_app() {
3846 let data_dir = get_data_dir ( & app. app_handle ( ) , tauri_config. clone ( ) ) ;
3947
4048 let _window = get_window ( app, & pake_config, data_dir) ;
49+
4150 // Prevent initial shaking
4251 _window. show ( ) . unwrap ( ) ;
4352
@@ -50,18 +59,34 @@ pub fn run_app() {
5059 if !activation_shortcut. is_empty ( ) {
5160 let app_handle = app. app_handle ( ) . clone ( ) ;
5261 let shortcut_hotkey = Shortcut :: from_str ( & activation_shortcut. as_str ( ) ) . unwrap ( ) ;
62+ let last_triggered = Arc :: new ( Mutex :: new ( Instant :: now ( ) ) ) ;
5363
5464 app_handle
5565 . plugin (
5666 tauri_plugin_global_shortcut:: Builder :: new ( )
57- . with_handler ( move |app, event, _shortcut| {
58- if shortcut_hotkey. eq ( event) {
59- let window = app. get_webview_window ( "pake" ) . unwrap ( ) ;
60- match window. is_visible ( ) . unwrap ( ) {
61- true => window. hide ( ) . unwrap ( ) ,
62- false => {
63- window. show ( ) . unwrap ( ) ;
64- window. set_focus ( ) . unwrap ( ) ;
67+ . with_handler ( {
68+ let last_triggered = Arc :: clone ( & last_triggered) ;
69+ move |app, event, _shortcut| {
70+ // Fixed the bug of tauri's hidden call, which caused repeated execution
71+ let now = Instant :: now ( ) ;
72+ let mut last = last_triggered. lock ( ) . unwrap ( ) ;
73+ if now. duration_since ( * last) < Duration :: from_millis ( 500 ) {
74+ return ;
75+ }
76+ * last = now;
77+
78+ if shortcut_hotkey. eq ( event) {
79+ let window = app. get_webview_window ( "pake" ) . unwrap ( ) ;
80+ let is_visible = window. is_visible ( ) . unwrap ( ) ;
81+
82+ match is_visible {
83+ true => {
84+ window. minimize ( ) . unwrap ( ) ;
85+ }
86+ false => {
87+ window. unminimize ( ) . unwrap ( ) ;
88+ window. set_focus ( ) . unwrap ( ) ;
89+ }
6590 }
6691 }
6792 }
0 commit comments