sync pause state

This commit is contained in:
Julian Freeman
2026-03-22 15:55:06 -04:00
parent 7a82f3fb81
commit 7f9e0de193
4 changed files with 35 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use tokio::time::{interval, Duration};
use tauri::{AppHandle, Manager};
use tauri::{AppHandle, Manager, Emitter};
use xcap::Monitor;
use chrono::Local;
use std::fs;
@@ -10,13 +10,25 @@ use tauri_plugin_store::StoreExt;
pub struct AppState {
pub is_paused: Arc<AtomicBool>,
pub toggle_menu_item: std::sync::Mutex<Option<tauri::menu::MenuItem<tauri::Wry>>>,
}
#[tauri::command]
pub fn toggle_pause(state: tauri::State<'_, AppState>) -> bool {
pub fn toggle_pause(app: tauri::AppHandle, state: tauri::State<'_, AppState>) -> bool {
let current = state.is_paused.load(Ordering::SeqCst);
state.is_paused.store(!current, Ordering::SeqCst);
!current
let new_state = !current;
state.is_paused.store(new_state, Ordering::SeqCst);
// Sync with Tray
if let Some(item) = state.toggle_menu_item.lock().unwrap().as_ref() {
let text = if new_state { "恢复记录" } else { "暂停记录" };
let _ = item.set_text(text);
}
// Notify Frontend
let _ = app.emit("pause-state-changed", new_state);
new_state
}
#[tauri::command]