mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: implement auto lightweight mode timer functionality
This commit implements the automatic lightweight mode feature with timer functionality: - Rename configuration properties from auto_enter_lite_mode to enable_auto_light_weight_mode and auto_enter_lite_mode_delay to auto_light_weight_minutes for better clarity - Add window event listeners to detect when window is closed or gets focus - Implement timer system to automatically enter lightweight mode after configured time - Remove exit_lightweight_mode function as it's no longer needed with the new implementation - Update UI components to reflect the new property names - Add logging for lightweight mode operations - Initialize lightweight mode based on user configuration at startup The feature now allows users to set a timer that will automatically enter lightweight mode after closing the main window, which can be cancelled by focusing the window again.
This commit is contained in:
@@ -8,24 +8,25 @@ use std::{collections::HashMap, sync::Arc};
|
||||
type TaskID = u64;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct TimerTask {
|
||||
task_id: TaskID,
|
||||
interval_minutes: u64,
|
||||
__last_run: i64, // Timestamp of last execution
|
||||
pub struct TimerTask {
|
||||
pub task_id: TaskID,
|
||||
pub interval_minutes: u64,
|
||||
#[allow(unused)]
|
||||
pub last_run: i64, // Timestamp of last execution
|
||||
}
|
||||
|
||||
pub struct Timer {
|
||||
/// cron manager
|
||||
delay_timer: Arc<RwLock<DelayTimer>>,
|
||||
pub delay_timer: Arc<RwLock<DelayTimer>>,
|
||||
|
||||
/// save the current state - using RwLock for better read concurrency
|
||||
timer_map: Arc<RwLock<HashMap<String, TimerTask>>>,
|
||||
pub timer_map: Arc<RwLock<HashMap<String, TimerTask>>>,
|
||||
|
||||
/// increment id - kept as mutex since it's just a counter
|
||||
timer_count: Arc<Mutex<TaskID>>,
|
||||
pub timer_count: Arc<Mutex<TaskID>>,
|
||||
|
||||
/// Flag to mark if timer is initialized - atomic for better performance
|
||||
initialized: Arc<std::sync::atomic::AtomicBool>,
|
||||
pub initialized: Arc<std::sync::atomic::AtomicBool>,
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
@@ -139,7 +140,7 @@ impl Timer {
|
||||
let task = TimerTask {
|
||||
task_id: tid,
|
||||
interval_minutes: interval,
|
||||
__last_run: chrono::Local::now().timestamp(),
|
||||
last_run: chrono::Local::now().timestamp(),
|
||||
};
|
||||
|
||||
timer_map.insert(uid.clone(), task);
|
||||
@@ -161,7 +162,7 @@ impl Timer {
|
||||
let task = TimerTask {
|
||||
task_id: tid,
|
||||
interval_minutes: interval,
|
||||
__last_run: chrono::Local::now().timestamp(),
|
||||
last_run: chrono::Local::now().timestamp(),
|
||||
};
|
||||
|
||||
timer_map.insert(uid.clone(), task);
|
||||
|
||||
Reference in New Issue
Block a user