feat(windows): Phase 6 C2 — close-to-tray + Settings toggle 持久化
- ui/settings-page.slint: SettingsToggleRow 的 toggled callback
从 (bool) 改成 (string, bool) — 把 row 自己的 label + 新 value
一起交给 caller;row 内部先 value=!value 再 emit;value 改
in-out property 让内部可以 flip;SettingsPage 加 callback
toggle-persist(string, bool);7 个真 toggle 全部 wire 到
toggle-persist(Notifications 4 + Startup 3)
- ui/app.slint: MainWindow 加 in-out property ×7 +
setting-toggled(string, bool) callback;启动从 ActiveConfig
装载;SettingsPage section 把 7 个 property forward 给 page +
toggle-persist 转接到 root.setting-toggled
- src/lib.rs:
· 启动从 ActiveConfig 读 7 个 toggle 设到 MainWindow
· 新 on_setting_toggled 回调:load AppConfig → 按 label 改
对应字段 → save_config;start_with_windows 额外调
startup::set_enabled 写 HKCU Run(Phase 6 C1)
· on_close_requested 看 close_to_tray:true 时
window().hide() + KeepWindowShown;false 时保持原来的
HideWindow 行为
避坑:
- Slint 1.x callback 不能直接用 label 区分,必须 caller 传
string 参数;改造 (bool) → (string, bool)
- 设置 in-out property 让 row 内部能 flip value 然后 emit
新值(caller 收到的就是 post-flip 值)
- close_to_tray 在 UI MainWindow 上是 in-out property,Rust
端用 get_close_to_tray() 实时读,所以 toggle 立刻影响
close_requested 行为(不需要重启)
- on_close_requested 内部读 get_close_to_tray 要 upgrade()
MainWindow weak handle,捕获空时 fallback false(默认
close 而不是 hide)
验证:cargo build / build --release 都 exit 0,0 warning
- cargo test: 15 passed; 0 failed
- debug 35.64 MB, subsystem = WINDOWS_CUI
- release 9.78 MB, subsystem = WINDOWS_GUI
This commit is contained in:
@@ -61,6 +61,21 @@ export component MainWindow inherits Window {
|
||||
// Rust persists it into `state.json::last_theme`.
|
||||
callback appearance-changed-persist(int);
|
||||
|
||||
// ── Phase 6 C2: live AppConfig toggles (Settings page) ─────────
|
||||
// Forwarded from SettingsPage so the Rust runtime can:
|
||||
// 1. Persist into `config.json`
|
||||
// 2. For `start_with_windows`, also write HKCU Run.
|
||||
// 3. For `close_to_tray`, immediately affect the close-requested
|
||||
// handler below without a restart.
|
||||
in-out property <bool> desktop-notify: true;
|
||||
in-out property <bool> sound: true;
|
||||
in-out property <bool> notify-high: true;
|
||||
in-out property <bool> notify-max: true;
|
||||
in-out property <bool> start-with-windows: false;
|
||||
in-out property <bool> start-minimized: false;
|
||||
in-out property <bool> close-to-tray: true;
|
||||
callback setting-toggled(string, bool);
|
||||
|
||||
// ── Phase 3 C2: live connection status ───────────────────────
|
||||
in-out property <bool> is-connected: false;
|
||||
in-out property <string> status-text: "Disconnected";
|
||||
@@ -210,6 +225,13 @@ export component MainWindow inherits Window {
|
||||
|
||||
if root.selection == SidebarSelection.Settings: SettingsPage {
|
||||
appearance-index: root.appearance-index;
|
||||
desktop-notify: root.desktop-notify;
|
||||
sound: root.sound;
|
||||
notify-high: root.notify-high;
|
||||
notify-max: root.notify-max;
|
||||
start-with-windows: root.start-with-windows;
|
||||
start-minimized: root.start-minimized;
|
||||
close-to-tray: root.close-to-tray;
|
||||
appearance-changed(idx) => {
|
||||
root.appearance-index = idx;
|
||||
root.theme = idx == 0 ? AppearanceMode.System :
|
||||
@@ -220,6 +242,9 @@ export component MainWindow inherits Window {
|
||||
test-connection-requested => {
|
||||
root.test-connection-requested();
|
||||
}
|
||||
toggle-persist(label, value) => {
|
||||
root.setting-toggled(label, value);
|
||||
}
|
||||
}
|
||||
|
||||
// About entry stays as a simple right-pane marker; the
|
||||
|
||||
Reference in New Issue
Block a user