diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index f22abf0..6cb2231 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -7,6 +7,7 @@ ], "permissions": [ "core:default", + "core:window:allow-hide", "opener:default", "clipboard-manager:default", "clipboard-manager:allow-write-text", diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9f72896..648161a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -274,16 +274,23 @@ pub fn run() { .build(tauri::generate_context!()).unwrap(); app.run(|app, event| { - if let tauri::RunEvent::WindowEvent { - event: tauri::WindowEvent::CloseRequested { api, .. }, - .. - } = event - { - api.prevent_close(); - app.get_webview_window("main") - .unwrap() - .hide() - .expect("To hide the window"); - } + if let tauri::RunEvent::WindowEvent { label, event, .. } = event { + if label == "main" { + match event { + tauri::WindowEvent::CloseRequested { api, .. } => { + api.prevent_close(); + if let Some(window) = app.get_webview_window("main") { + let _ = window.hide(); + } + } + tauri::WindowEvent::Focused(false) => { + if let Some(window) = app.get_webview_window("main") { + let _ = window.hide(); + } + } + _ => {} + } + } + } }); } \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index d0bfc0d..2b4192a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -16,6 +16,7 @@ import SnippetForm from '$lib/components/SnippetForm.svelte'; import ImportSnippets from '$lib/components/ImportSnippets.svelte'; import SearchSnippets from '$lib/components/SearchSnippets.svelte'; + import { getCurrentWindow } from '@tauri-apps/api/window'; const storePlugin: PluginInfo = { title: 'Discover Extensions', @@ -138,6 +139,14 @@ viewManager.showSettings(); return; } + + if (event.key === 'Escape') { + if (currentView === 'command-palette') { + event.preventDefault(); + getCurrentWindow().hide(); + console.log('hide'); + } + } } function handleSavePreferences(pluginName: string, values: Record) {