sync pause state
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user