//! Tauri commands for the proactive scheduler. use serde::Serialize; #[derive(Serialize)] pub struct ScheduledTaskInfo { pub id: String, pub name: String, pub schedule_human: String, pub action_kind: String, pub action_text: Option, pub last_fired: Option, pub enabled: bool, pub created_at: i64, } fn schedule_human(s: &jarvis_core::scheduler::Schedule) -> String { use jarvis_core::scheduler::Schedule; match s { Schedule::Daily { hour, minute } => format!("каждый день в {:02}:{:02}", hour, minute), Schedule::Interval { seconds } => { if *seconds % 3600 == 0 { format!("каждые {} ч", seconds / 3600) } else if *seconds % 60 == 0 { format!("каждые {} мин", seconds / 60) } else { format!("каждые {} сек", seconds) } } Schedule::Once { at } => format!("один раз @ {}", at), } } #[tauri::command] pub fn scheduler_list() -> Vec { use jarvis_core::scheduler::Action; jarvis_core::scheduler::list().into_iter().map(|t| { let (action_kind, action_text) = match &t.action { Action::Speak { text } => ("speak".to_string(), Some(text.clone())), Action::Lua { script_path } => ("lua".to_string(), Some(script_path.clone())), }; ScheduledTaskInfo { id: t.id, name: t.name, schedule_human: schedule_human(&t.schedule), action_kind, action_text, last_fired: t.last_fired, enabled: t.enabled, created_at: t.created_at, } }).collect() } #[tauri::command] pub fn scheduler_remove(id: String) -> bool { jarvis_core::scheduler::remove(&id) } #[tauri::command] pub fn scheduler_clear() -> usize { jarvis_core::scheduler::clear() }