feat: integrate event tracking for hotkey actions, history management, and settings updates

This commit is contained in:
PandaDEV 2024-12-23 14:34:21 +10:00
parent 3824f24be4
commit f44be512fe
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
8 changed files with 149 additions and 36 deletions

View file

@ -3,6 +3,7 @@ use serde_json;
use sqlx::Row;
use sqlx::SqlitePool;
use tauri::{Emitter, Manager};
use tauri_plugin_aptabase::EventTracker;
#[derive(Deserialize, Serialize)]
struct KeybindSetting {
@ -26,9 +27,16 @@ pub async fn initialize_settings(pool: &SqlitePool) -> Result<(), Box<dyn std::e
#[tauri::command]
pub async fn save_keybind(
app_handle: tauri::AppHandle,
keybind: Vec<String>,
pool: tauri::State<'_, SqlitePool>,
keybind: Vec<String>,
) -> Result<(), String> {
let keybind_str = keybind.join("+");
let keybind_clone = keybind_str.clone();
app_handle
.emit("update-shortcut", &keybind_str)
.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', ?)")
@ -37,10 +45,9 @@ pub async fn save_keybind(
.await
.map_err(|e| e.to_string())?;
let keybind_str = keybind.join("+");
app_handle
.emit("update-shortcut", keybind_str)
.map_err(|e| e.to_string())?;
let _ = app_handle.track_event("keybind_saved", Some(serde_json::json!({
"keybind": keybind_clone
})));
Ok(())
}
@ -61,17 +68,22 @@ pub async fn get_setting(
#[tauri::command]
pub async fn save_setting(
app_handle: tauri::AppHandle,
pool: tauri::State<'_, SqlitePool>,
key: String,
value: String,
) -> Result<(), String> {
sqlx::query("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)")
.bind(key)
.bind(key.clone())
.bind(value)
.execute(&*pool)
.await
.map_err(|e| e.to_string())?;
let _ = app_handle.track_event("setting_saved", Some(serde_json::json!({
"key": key
})));
Ok(())
}