diff --git a/package.json b/package.json index e044b1f5..d9b47c34 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@headlessui/react": "^2.1.10", "@tauri-apps/api": ">=2.0.0", "@tauri-apps/plugin-autostart": "~2", - "@tauri-apps/plugin-global-shortcut": "~2", + "@tauri-apps/plugin-global-shortcut": "~2.0.0", "@tauri-apps/plugin-http": "~2.0.1", "@tauri-apps/plugin-os": "^2.0.0", "@tauri-apps/plugin-shell": ">=2.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9839dac0..acf323c8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,7 +18,7 @@ importers: specifier: ~2 version: 2.0.0 '@tauri-apps/plugin-global-shortcut': - specifier: ~2 + specifier: ~2.0.0 version: 2.0.0 '@tauri-apps/plugin-http': specifier: ~2.0.1 diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index c02ed01b..900d1653 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -42,6 +42,7 @@ "global-shortcut:allow-is-registered", "global-shortcut:allow-register", "global-shortcut:allow-unregister", + "global-shortcut:allow-unregister-all", { "identifier": "http:default", "allow": [ diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7cff6b03..b0bf4dbb 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -167,14 +167,18 @@ fn enable_shortcut(app: &mut tauri::App) { #[tauri::command] fn change_shortcut( app: tauri::AppHandle, - window: tauri::Window, + _window: tauri::Window, key: String, ) -> Result<(), String> { use std::fs::File; use std::io::Write; use tauri_plugin_global_shortcut::ShortcutState; - remove_shortcut(&app)?; + if let Err(e) = remove_shortcut(&app) { + eprintln!("Failed to remove old shortcut: {}", e); + } + + let main_window = app.get_webview_window("main").unwrap(); let shortcut: Shortcut = key .parse() @@ -184,11 +188,11 @@ fn change_shortcut( if scut == &shortcut { if let ShortcutState::Pressed = event.state() { println!("Command+B Pressed!"); - if window.is_focused().unwrap() { - window.hide().unwrap(); + if main_window.is_focused().unwrap() { + main_window.hide().unwrap(); } else { - window.show().unwrap(); - window.set_focus().unwrap(); + main_window.show().unwrap(); + main_window.set_focus().unwrap(); } } } @@ -240,14 +244,12 @@ fn remove_shortcut(app: &tauri::AppHandle) -> Result<(), String> fn enable_tray(app: &mut tauri::App) { use tauri::{ - image::Image, + // image::Image, menu::{MenuBuilder, MenuItem}, tray::TrayIconBuilder, webview::WebviewBuilder, }; - let image = Image::from_path("icons/32x32.png").unwrap(); - let quit_i = MenuItem::with_id(app, "quit", "Quit Coco", true, None::<&str>).unwrap(); let settings_i = MenuItem::with_id(app, "settings", "Settings", true, None::<&str>).unwrap(); let open_i = MenuItem::with_id(app, "open", "Open Coco", true, None::<&str>).unwrap(); @@ -261,7 +263,7 @@ fn enable_tray(app: &mut tauri::App) { .unwrap(); let _tray = TrayIconBuilder::new() - .icon(image) + .icon(app.default_window_icon().unwrap().clone()) .menu(&menu) .on_menu_event(|app, event| match event.id.as_ref() { "show" => {