diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7267ff8..961b73c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -895,8 +895,7 @@ fn set_prevent_sleep(state: tauri::State<'_, AppState>, prevent: bool) { } } -#[tauri::command] -fn perform_system_action(action: crate::ipc::PostQueueAction) -> Result<(), String> { +pub(crate) fn execute_system_action(action: crate::ipc::PostQueueAction) -> Result<(), String> { match action { crate::ipc::PostQueueAction::Shutdown => { system_shutdown::shutdown().map_err(|e| e.to_string()) @@ -911,6 +910,11 @@ fn perform_system_action(action: crate::ipc::PostQueueAction) -> Result<(), Stri } } +#[tauri::command] +fn perform_system_action(action: crate::ipc::PostQueueAction) -> Result<(), String> { + execute_system_action(action) +} + #[tauri::command] async fn set_concurrent_limit(state: tauri::State<'_, AppState>, limit: usize) -> Result<(), String> { let _ = rpc_call( diff --git a/src-tauri/src/scheduler.rs b/src-tauri/src/scheduler.rs index a9397b1..ded0268 100644 --- a/src-tauri/src/scheduler.rs +++ b/src-tauri/src/scheduler.rs @@ -1,23 +1,8 @@ use tauri::{Manager, Emitter}; use chrono::{Local, Datelike}; use std::time::Duration; -use serde::Deserialize; -#[derive(Deserialize, Debug)] -struct SchedulerSettings { - enabled: bool, - #[serde(rename = "startTime")] - start_time: String, - #[serde(rename = "stopTimeEnabled")] - stop_time_enabled: bool, - #[serde(rename = "stopTime")] - stop_time: String, - everyday: bool, - #[serde(rename = "selectedDays")] - selected_days: Vec, - #[serde(rename = "postQueueAction")] - post_queue_action: String, -} + pub fn spawn_scheduler(app_handle: tauri::AppHandle) { tauri::async_runtime::spawn(async move { @@ -33,7 +18,7 @@ pub fn spawn_scheduler(app_handle: tauri::AppHandle) { if let Some(settings_str) = settings_opt { if let Ok(mut settings) = serde_json::from_str::(&settings_str) { - if let Ok(scheduler) = serde_json::from_value::(settings.get("scheduler").unwrap_or(&serde_json::json!({})).clone()) { + if let Ok(scheduler) = serde_json::from_value::(settings.get("scheduler").unwrap_or(&serde_json::json!({})).clone()) { if !scheduler.enabled { continue; } @@ -77,6 +62,10 @@ pub fn spawn_scheduler(app_handle: tauri::AppHandle) { let conn = state.conn.lock().unwrap(); let _ = crate::db::save_settings(&conn, &updated); } + + if !matches!(scheduler.post_queue_action, crate::ipc::PostQueueAction::None) { + let _ = crate::execute_system_action(scheduler.post_queue_action.clone()); + } } } }