feat(ui): Phase 2 C3 — Settings 页 + Dialogs + 窗口状态保存

- src/storage.rs: AppState (last_window_width/height) + load/save
  atomic write 到 %APPDATA%/WindowsGotify/state.json(§18)
- ui/settings-page.slint: 5 分组(Connection / Notifications / Startup
  / Appearance / Advanced),Appearance 实时切主题(System/Light/Dark
  radio);Advanced 折叠
- ui/dialogs.slint: AboutDialog + ConfirmDialog(§54)
- ui/server-card.slint: 单 server 行(name/url/enabled toggle/edit/remove)
- ui/app.slint: settings 页切换、About 导航、theme 联动
- src/lib.rs: load_state → 启动时应用窗口尺寸;ui.window()
  .on_close_requested 在 OS 关闭前 save_state;wire about/close
  callbacks
- src/error.rs: 加 AppError::Storage(String) 变体
- Cargo.toml: 加 serde + serde_json

避坑:
- Slint 1.x 同文件内 export component 必须在引用前定义(sub-components
  移到 SettingsPage 上面)
- Slint 不支持 padding 两值简写 (padding: 0 16px) → 用 padding-* 四属性
- Slint 不支持 Rectangle 内建 border-color 覆盖 → 命名 card-border
- Slint 不支持 alignment: right → 用 spacer + horizontal-stretch: 1
- 修了一处 .slint 文件被 PowerShell Set-Content GBK 损坏的问题(已
  通过 write 工具 + UTF-8 no BOM 重写并清理 ui/ 所有 .slint)

验证:cargo build / build --release 都 exit 0,0 warning
- debug   27.55 MB, subsystem = WINDOWS_CUI
- release  8.10 MB, subsystem = WINDOWS_GUI
This commit is contained in:
2026-09-19 04:47:54 +08:00
parent 11a122216b
commit 680fbfa0ad
9 changed files with 792 additions and 51 deletions
+39 -26
View File
@@ -1,15 +1,17 @@
// Main window + sidebar (AGENTS.md §6, §7).
//
// Phase 2 C1 only lays out the chrome: 960×680 default, 760×520 minimum,
// 232px sidebar with the seven required sections. The message area /
// settings page / about dialog are still placeholders — content lands in
// C2 (messages) and C3 (settings + dialogs + sidebar Light/System).
// Phase 2 C3 wires the Settings page, About dialog, and window-state
// persistence. The Appearance section in `settings-page.slint` is the only
// settings UI that drives real state today — every other control is a
// shell that Phase 5 hooks to `AppConfig`.
import { AppearanceMode } from "./theme.slint";
import { NavItem, SectionLabel } from "./components.slint";
import { MessageItem } from "./message-card.slint";
import { MessageList } from "./message-list.slint";
import { EmptyState } from "./empty-state.slint";
import { SettingsPage } from "./settings-page.slint";
import { AboutDialog } from "./dialogs.slint";
export enum SidebarSelection {
All,
@@ -24,9 +26,7 @@ export component MainWindow inherits Window {
min-width: 760px;
min-height: 520px;
// Theme switch — Rust-controllable via `ui.set_theme(...)`. Light/System
// is wired through this single property; the sidebar children will start
// following it once C3 widens NavItem to accept palette forwarding.
// Theme switch — Rust-controllable via `ui.set_theme(...)`.
in-out property <AppearanceMode> theme: AppearanceMode.Dark;
out property <bool> is-dark: theme != AppearanceMode.Light;
@@ -51,18 +51,21 @@ export component MainWindow inherits Window {
in-out property <SidebarSelection> selection: SidebarSelection.All;
// Phase 2 C2: mock-driven message list + selection state. Set from Rust
// via `ui.set_messages(model)` in `run()`. The list / empty-state switch
// is purely driven by `messages.length` (Slint's `for` over an empty
// model is a no-op).
// ── Phase 2 C2: mock messages + selection ────────────────────
in-out property <[MessageItem]> messages;
in-out property <int> selected-message-index: -1;
// Hooks that Phase 6 (Windows Integration) wires to a real Windows
// toast. C2 logs them so the click path is observable end-to-end.
callback test-notification-clicked();
callback message-card-clicked(int);
// ── Phase 2 C3: Settings / About / window state ──────────────
// Initial appearance radio (0=System/1=Light/2=Dark). Maps 1:1 to
// AppearanceMode: System=0, Light=1, Dark=2.
in-out property <int> appearance-index: 2;
// Show About dialog (one-shot — Rust closes it after handling).
callback about-clicked();
callback close-requested-save-state();
HorizontalLayout {
// §7 Sidebar width: 220-240px.
Rectangle {
@@ -73,7 +76,6 @@ export component MainWindow inherits Window {
padding: 20px;
spacing: 6px;
// App logo / title block.
Text {
text: "Gotify";
color: text-primary;
@@ -137,12 +139,15 @@ export component MainWindow inherits Window {
NavItem {
label: "About";
selected: root.selection == SidebarSelection.About;
clicked => { root.selection = SidebarSelection.About; }
clicked => {
root.selection = SidebarSelection.About;
root.about-clicked();
}
}
}
}
// Right pane — placeholder content driven by `selection`.
// Right pane — driven by `selection`.
Rectangle {
background: bg;
@@ -174,27 +179,35 @@ export component MainWindow inherits Window {
}
}
if root.selection == SidebarSelection.Settings: Rectangle {
background: bg;
Text {
x: 24px;
y: 24px;
text: "Settings page arrives in Phase 2 C3.";
color: text-muted;
font-size: 13px;
if root.selection == SidebarSelection.Settings: SettingsPage {
appearance-index: root.appearance-index;
appearance-changed(idx) => {
root.appearance-index = idx;
root.theme = idx == 0 ? AppearanceMode.System :
idx == 1 ? AppearanceMode.Light :
AppearanceMode.Dark;
}
}
// About is rendered via a Dialog overlay — not in the right pane.
// A separate About row keeps the layout stable; the dialog is
// shown via `about-clicked` callback to Rust.
if root.selection == SidebarSelection.About: Rectangle {
background: bg;
Text {
x: 24px;
y: 24px;
text: "About dialog arrives in Phase 2 C3.";
text: "About — see the dialog.";
color: text-muted;
font-size: 13px;
}
}
}
}
// Modal About dialog — opened when the user clicks About in the sidebar.
AboutDialog {
// visible-by-default is false. Toggled via Rust by listening to
// `about-clicked`. C3 wires the bare open/close plumbing.
}
}