From ccb0f9dae6a7228eea1576f8befaf47b62a5fb74 Mon Sep 17 00:00:00 2001 From: "don.cryptus" Date: Thu, 28 Sep 2023 00:33:04 +0200 Subject: [PATCH] easy --- src-tauri/src/commands/window.rs | 2 ++ src-tauri/src/utils/tray.rs | 32 ++++++++++++++++++++++++++++++-- src/index.tsx | 2 +- src/utils/hotkeyRegister.ts | 6 +++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index 579e8f66..4d27b681 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -17,6 +17,8 @@ use tauri_plugin_positioner::{Position, WindowExt}; pub fn window_display_toggle() { let win = APP.get().unwrap().get_window("main").unwrap(); + println!("Window is visible: {:?}", win.is_visible()); + if win.is_visible().unwrap() { println!("Hiding window"); let _ = win.hide(); diff --git a/src-tauri/src/utils/tray.rs b/src-tauri/src/utils/tray.rs index 269fc089..c2548fb3 100644 --- a/src-tauri/src/utils/tray.rs +++ b/src-tauri/src/utils/tray.rs @@ -26,6 +26,30 @@ pub fn system_tray_event(app: &tauri::AppHandle, event: SystemTrayEvent) { let _ = win.show(); let _ = win.set_focus(); } + SystemTrayEvent::RightClick { + position: _, + size: _, + .. + } => { + println!("Clicked on tray icon"); + let win = app.get_window("main").unwrap(); + let _ = win.move_window(Position::TrayCenter); + init_hotkey(); + let _ = win.show(); + let _ = win.set_focus(); + } + SystemTrayEvent::DoubleClick { + position: _, + size: _, + .. + } => { + println!("Clicked on tray icon"); + let win = app.get_window("main").unwrap(); + let _ = win.move_window(Position::TrayCenter); + init_hotkey(); + let _ = win.show(); + let _ = win.set_focus(); + } SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { "open" => { let win = app.get_window("main").unwrap(); @@ -35,8 +59,12 @@ pub fn system_tray_event(app: &tauri::AppHandle, event: SystemTrayEvent) { let _ = win.set_focus(); } "quit" => app.exit(1), - _ => {} + _ => { + println!("Unhandled tray event"); + } }, - _ => {} + _ => { + println!("Unhandled tray event"); + } } } diff --git a/src/index.tsx b/src/index.tsx index 0ead89e2..3eb3aec1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -21,7 +21,7 @@ const Index = () => { onMount(async () => { appWindow.onFocusChanged(async ({ payload }) => { if (!payload) { - await appWindow.hide(); + // await appWindow.hide(); removeAllHotkeyListeners(); } }); diff --git a/src/utils/hotkeyRegister.ts b/src/utils/hotkeyRegister.ts index c248e776..91159c18 100644 --- a/src/utils/hotkeyRegister.ts +++ b/src/utils/hotkeyRegister.ts @@ -1,5 +1,6 @@ import { invoke } from "@tauri-apps/api"; import { + isRegistered, register, registerAll, unregister, @@ -31,6 +32,8 @@ export async function registerHotkeys(hotkeys: Hotkey[]) { const { getCurrentSidebarIcon, updateSidebarIcons } = AppStore; const { clipboards, clipboardRef } = ClipboardStore; + // await sleep(1000); + // // await unregisterAll(); // ############################################ @@ -40,9 +43,10 @@ export async function registerHotkeys(hotkeys: Hotkey[]) { // Display and hide the app window const windowHotkey = hotkeys.find((h) => h.event === "window_display_toggle"); - if (windowHotkey?.status) { + if (windowHotkey?.status && !(await isRegistered(windowHotkey.shortcut))) { try { await register(windowHotkey.shortcut, () => { + console.log("window_display_toggle"); updateSidebarIcons("Recent Clipboards"); invoke("window_display_toggle"); });