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:
Tunglies
2025-03-20 06:01:38 +08:00
Unverified
parent 33d54b27f4
commit 7fa1767645
9 changed files with 172 additions and 48 deletions

View File

@@ -28,8 +28,8 @@ export const LiteModeViewer = forwardRef<DialogRef>((props, ref) => {
open: () => {
setOpen(true);
setValues({
autoEnterLiteMode: verge?.auto_enter_lite_mode ?? false,
autoEnterLiteModeDelay: verge?.auto_enter_lite_mode_delay ?? 10,
autoEnterLiteMode: verge?.enable_auto_light_weight_mode ?? false,
autoEnterLiteModeDelay: verge?.auto_light_weight_minutes ?? 10,
});
},
close: () => setOpen(false),
@@ -38,8 +38,8 @@ export const LiteModeViewer = forwardRef<DialogRef>((props, ref) => {
const onSave = useLockFn(async () => {
try {
await patchVerge({
auto_enter_lite_mode: values.autoEnterLiteMode,
auto_enter_lite_mode_delay: values.autoEnterLiteModeDelay,
enable_auto_light_weight_mode: values.autoEnterLiteMode,
auto_light_weight_minutes: values.autoEnterLiteModeDelay,
});
setOpen(false);
} catch (err: any) {

View File

@@ -739,8 +739,8 @@ interface IVergeConfig {
tun_tray_icon?: boolean;
enable_tray_speed?: boolean;
enable_tun_mode?: boolean;
auto_enter_lite_mode?: boolean;
auto_enter_lite_mode_delay?: number;
enable_auto_light_weight_mode?: boolean;
auto_light_weight_minutes?: number;
enable_auto_launch?: boolean;
enable_silent_start?: boolean;
enable_system_proxy?: boolean;