diff --git a/plugins/settings.ts b/plugins/settings.ts index 4ca1b52..8e2fcf2 100644 --- a/plugins/settings.ts +++ b/plugins/settings.ts @@ -1,5 +1,4 @@ import { invoke } from "@tauri-apps/api/core"; -import type { Settings } from "~/types/types"; export default defineNuxtPlugin(() => { return { diff --git a/src-tauri/src/api/hotkeys.rs b/src-tauri/src/api/hotkeys.rs index a0084eb..994894b 100644 --- a/src-tauri/src/api/hotkeys.rs +++ b/src-tauri/src/api/hotkeys.rs @@ -43,7 +43,8 @@ pub fn setup(app_handle: tauri::AppHandle) { } app_handle.listen("update-shortcut", move |event| { - let payload_str = event.payload(); + let payload_str = event.payload().replace("\\\"", "\""); + let trimmed_str = payload_str.trim_matches('"'); if let Some(old_hotkey) = REGISTERED_HOTKEY.lock().unwrap().take() { let manager_guard = HOTKEY_MANAGER.lock().unwrap(); @@ -52,7 +53,7 @@ pub fn setup(app_handle: tauri::AppHandle) { } } - let payload: Vec = serde_json::from_str(payload_str).unwrap_or_default(); + let payload: Vec = serde_json::from_str(trimmed_str).unwrap_or_default(); if let Err(e) = register_shortcut(&payload) { eprintln!("Error re-registering shortcut: {:?}", e); diff --git a/src-tauri/src/db/settings.rs b/src-tauri/src/db/settings.rs index caee425..2539ab7 100644 --- a/src-tauri/src/db/settings.rs +++ b/src-tauri/src/db/settings.rs @@ -24,32 +24,6 @@ pub async fn initialize_settings(pool: &SqlitePool) -> Result<(), Box, - keybind: Vec -) -> Result<(), String> { - app_handle.emit("update-shortcut", &keybind).map_err(|e| e.to_string())?; - - let json = serde_json::to_string(&keybind).map_err(|e| e.to_string())?; - - sqlx - ::query("INSERT OR REPLACE INTO settings (key, value) VALUES ('keybind', ?)") - .bind(json) - .execute(&*pool).await - .map_err(|e| e.to_string())?; - - let _ = app_handle.track_event( - "keybind_saved", - Some(serde_json::json!({ - "keybind": keybind - })) - ); - - Ok(()) -} - #[tauri::command] pub async fn get_setting( pool: tauri::State<'_, SqlitePool>, @@ -74,7 +48,7 @@ pub async fn save_setting( sqlx ::query("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)") .bind(key.clone()) - .bind(value) + .bind(value.clone()) .execute(&*pool).await .map_err(|e| e.to_string())?; @@ -85,6 +59,10 @@ pub async fn save_setting( })) ); + if key == "keybind" { + let _ = app_handle.emit("update-shortcut", &value).map_err(|e| e.to_string())?; + } + Ok(()) } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0291cbc..179500c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -124,8 +124,6 @@ fn main() { db::history::read_image, db::settings::get_setting, db::settings::save_setting, - db::settings::save_keybind, - db::settings::get_keybind, utils::commands::fetch_page_meta ] )