mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 13:14:04 +02:00
fix: reregister of hotkey not working
This commit is contained in:
parent
617c1737b7
commit
416e2f020d
4 changed files with 8 additions and 32 deletions
|
@ -1,5 +1,4 @@
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import type { Settings } from "~/types/types";
|
|
||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin(() => {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -43,7 +43,8 @@ pub fn setup(app_handle: tauri::AppHandle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
app_handle.listen("update-shortcut", move |event| {
|
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() {
|
if let Some(old_hotkey) = REGISTERED_HOTKEY.lock().unwrap().take() {
|
||||||
let manager_guard = HOTKEY_MANAGER.lock().unwrap();
|
let manager_guard = HOTKEY_MANAGER.lock().unwrap();
|
||||||
|
@ -52,7 +53,7 @@ pub fn setup(app_handle: tauri::AppHandle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let payload: Vec<String> = serde_json::from_str(payload_str).unwrap_or_default();
|
let payload: Vec<String> = serde_json::from_str(trimmed_str).unwrap_or_default();
|
||||||
|
|
||||||
if let Err(e) = register_shortcut(&payload) {
|
if let Err(e) = register_shortcut(&payload) {
|
||||||
eprintln!("Error re-registering shortcut: {:?}", e);
|
eprintln!("Error re-registering shortcut: {:?}", e);
|
||||||
|
|
|
@ -24,32 +24,6 @@ pub async fn initialize_settings(pool: &SqlitePool) -> Result<(), Box<dyn std::e
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn save_keybind(
|
|
||||||
app_handle: tauri::AppHandle,
|
|
||||||
pool: tauri::State<'_, SqlitePool>,
|
|
||||||
keybind: Vec<String>
|
|
||||||
) -> 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]
|
#[tauri::command]
|
||||||
pub async fn get_setting(
|
pub async fn get_setting(
|
||||||
pool: tauri::State<'_, SqlitePool>,
|
pool: tauri::State<'_, SqlitePool>,
|
||||||
|
@ -74,7 +48,7 @@ pub async fn save_setting(
|
||||||
sqlx
|
sqlx
|
||||||
::query("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)")
|
::query("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)")
|
||||||
.bind(key.clone())
|
.bind(key.clone())
|
||||||
.bind(value)
|
.bind(value.clone())
|
||||||
.execute(&*pool).await
|
.execute(&*pool).await
|
||||||
.map_err(|e| e.to_string())?;
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,6 @@ fn main() {
|
||||||
db::history::read_image,
|
db::history::read_image,
|
||||||
db::settings::get_setting,
|
db::settings::get_setting,
|
||||||
db::settings::save_setting,
|
db::settings::save_setting,
|
||||||
db::settings::save_keybind,
|
|
||||||
db::settings::get_keybind,
|
|
||||||
utils::commands::fetch_page_meta
|
utils::commands::fetch_page_meta
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue