fix(lightweight): persist lightweight-mode preference across sessions#2547
fix(lightweight): persist lightweight-mode preference across sessions#2547skyswordw wants to merge 1 commit intofarion1231:mainfrom
Conversation
…om runtime state The tray's "Lightweight Mode" checkbox previously toggled a single in-memory AtomicBool that doubled as both runtime state (window destroyed, dock hidden) and user preference. This caused two related bugs: 1. The preference was lost on every app restart — the menu looked persistent but behaved as session-only. 2. Tray "Open main window" reused exit_lightweight_mode, which cleared the preference along with the runtime state. macOS Reopen / single-instance / deep-link wake-ups did the same. Result: any wake-up implicitly opted the user out of lightweight mode. Split the concept: - AppSettings.lightweight_mode (persisted in ~/.cc-switch/settings.json) is the user preference; only the tray ✓ toggle writes it. get_settings_for_frontend masks it and update_settings preserves it so the frontend save_settings round-trip cannot clobber the persisted value. - LIGHTWEIGHT_RUNTIME (AtomicBool) tracks whether the window is currently destroyed; only mutated by enter/exit_lightweight_runtime. - set_lightweight_preference writes the preference and syncs runtime to match. Behavior changes (preference=true paths): - Startup enters lightweight runtime instead of normal window. - Closing the main window enters lightweight runtime, taking precedence over minimize_to_tray_on_close. - Tray "Open main window", macOS Reopen, single-instance wake-up, and deep links exit only the runtime — the preference is preserved. - Tray ✓ checkmark now reflects the preference, not the transient runtime state, so the checkmark stays lit when the user temporarily opens the window. No frontend changes; existing Tauri command names (enter_lightweight_mode / exit_lightweight_mode / is_lightweight_mode) are kept as preference-level wrappers for IPC stability. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @farion1231's task in 3m 3s —— View job Claude PR ReviewLGTM — no blocking issues. The split between persisted preference (
|
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
修复轻量模式(Lightweight Mode)的两个相关问题:
根因:
LIGHTWEIGHT_MODE一个AtomicBool同时承担"运行期是否处于轻量"和"用户是否偏好轻量"两个不同的概念,且没有持久化。What Changed
把这两个概念彻底拆开:
lightweight_mode~/.cc-switch/settings.json(设备级)LIGHTWEIGHT_RUNTIMElightweight.rs拆分为:enter_lightweight_runtime/exit_lightweight_runtime:仅操作窗口与 dockis_lightweight_runtime:当前运行期状态set_lightweight_preference:写偏好 + 同步运行期 + 刷新菜单is_lightweight_preferred:读偏好并修正各调用点的语义:
silent_startup)WindowEvent::CloseRequested:偏好=true 时关窗口直接进入轻量运行期,否则沿用minimize_to_tray_on_closeexit_lightweight_runtime,不动偏好防御前端污染:
get_settings_for_frontend把lightweightMode抹零,update_settings保留磁盘上的真值,避免save_settings携带过期值时回写 false。Tauri 命令名(
enter_lightweight_mode/exit_lightweight_mode/is_lightweight_mode)保留不变以维护 IPC 稳定性,但语义改为读写偏好。Test plan
cargo fmtcargo checkcargo clippy --lib --binscargo test --lib settings::(4/4 passed)~/.cc-switch/settings.json中lightweightMode: truelightweightMode仍为truefalseopen -a cc-switch(已运行时)→ 窗口出现但偏好仍为true,下次关窗口仍回轻量silent_startup/minimize_to_tray_on_close等)Notes
lightweightMode字段的旧 settings.json 会按#[serde(default)]落到falseset_skip_taskbar/ Linux fix 逻辑🤖 Generated with Claude Code