diff --git a/docs/README.md b/docs/README.md index 173ff43..98bfc43 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,6 +11,7 @@ | [testing-capabilities.md](testing-capabilities.md) | 当前智能体测试能力实测、环境限制与验证边界 | | [development.md](development.md) | 开发环境搭建、构建调试、测试 Target 添加与协作规范 | | [implementation-plan.md](implementation-plan.md) | 已定稿方案、阶段顺序与实施进度 | +| [settings-brand-plan.md](settings-brand-plan.md) | 设置窗口展示、侧边栏、液态玻璃与品牌图标实施记录 | | [stage-a-validation.md](stage-a-validation.md) | A 阶段采样、资源及 UI 验证记录 | | [stage-b-validation.md](stage-b-validation.md) | B 阶段面板、外观与三语验证记录 | | [roadmap.md](roadmap.md) | 版本路线图与里程碑 | diff --git a/docs/architecture.md b/docs/architecture.md index 9ce0021..9d432c2 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -4,7 +4,7 @@ Kymo 是一款 macOS 菜单栏常驻的资源监控工具,设计目标为「轻量、低功耗、无干扰」: -- **常驻形态**:使用 SwiftUI 原生 `MenuBarExtra`(window 样式),无 Dock 图标、无常驻窗口; +- **常驻形态**:使用 SwiftUI 原生 `MenuBarExtra`(window 样式),平时无 Dock 图标、无常驻窗口;设置窗口打开期间临时显示 Dock 图标并提供常规窗口焦点; - **数据驱动**:采样器定时采集系统指标 → 汇成统一快照 → 驱动菜单栏文本与面板 UI; - **可扩展**:新增监控项只需新增一个采样器并注册,不改动既有 UI 结构; - **低功耗**:单一调度器统一驱动采样,频率可配置,面板不可见时降低非必要刷新。 @@ -41,7 +41,7 @@ Kymo 是一款 macOS 菜单栏常驻的资源监控工具,设计目标为「 `MemoryMonitor` 与 `getloadavg`,返回 Sendable `MetricsSnapshot`,再回 MainActor 整体发布。 默认每次采样完成后等待 2s,不会重叠采样;当前刷新间隔尚未接入设置。 -菜单栏标签采用 `Label`(单个 gauge 图标 + 单个文本标题),所有指标合入标题, +菜单栏标签采用 `Label`(品牌模板图标 + 单个文本标题),所有指标合入标题, 以 CPU / GPU / MEM 短标签区分;GPU 不可用时移除对应片段。此前多 Image/Text 的 HStack 在用户最新构建中仅显示一个百分比,已改写以避免依赖多个独立标签节点的转换;修复后的双指标显示已通过用户重新运行后的局部截图验收。 @@ -64,9 +64,10 @@ GPU 的 IOReport spike 能枚举本机通道,但订阅返回空,当前快照 - 数值与悬浮过渡仅在可见行启用,遵循减少动态效果;面板关闭不挂载独立动画时钟。趋势追加样本时使用 0.35 秒位置插值,满容量保留一个出场点并裁剪;首次显示、非连续更新和减少动态效果直接显示当前历史。仅每次可见更新安排一次可取消任务,无周期动画时钟。 - 面板沿用 MenuBarExtra 系统窗口背景,不叠加整块自绘玻璃;操作按钮使用系统 `.glass`。TV1 的真实材质融合验收尚未完成,不能由离屏渲染认定通过。 - `AppearancePreferences` 仅依赖 Foundation / Observation,持久化外观、系统/六种预设/自选 RGB 强调色。UI 层 `AppearanceStyle` 将偏好映射为明确的深/浅色及窗口级 NSAppearance / Color。跟随系统从全局偏好 AppleInterfaceStyle 独立解析,监听系统主题通知及 NSApp effectiveAppearance 变化后刷新;为 SwiftUI 同时提供非 nil 的 preferredColorScheme 与 colorScheme 环境,避免返回 nil 和失焦后重新继承窗口残留模式。用户持久化值仍为 system,App 全局 appearance 不被修改。该系统偏好键/主题通知属于平台约定,系统动态切换仍需实机验证;外观覆盖作用于面板与设置,不作用于菜单栏标签。 -- `LanguagePreferences` 独立持久化 system / zh-Hans / zh-Hant / en,仅依赖 Foundation / Observation。App 将同一 locale 注入面板与设置,切换即时生效;系统模式按 Locale.preferredLanguages 匹配已支持语言,无法匹配回退 en,不修改 AppleLanguages。外侧详情的独立 NSHostingView 显式转发 locale;UI 的 AppLocalization 为原生窗口标题与色块辅助标签查找对应 lproj,避免其沿用进程启动语言。系统菜单与 NSColorPanel 的系统文案由 macOS 管理。语言自称保留原文,设置表单为 460×340pt 以容纳语言区。 -- App 注入同一个偏好仓库,注册独立 Settings 场景;Settings 特性当前实现语言与外观表单,不横向引用 MenuBar 特性。 -- 显式设置 `LSUIElement=true` 保持默认无 Dock;设置视图出现切换 `.regular` 并激活,Settings 自己的窗口观察器在重新成为 key 时保持 `.regular`、关闭时恢复 `.accessory`。该 R14 实现为引入设置场景所需而前置,Dock 随设置开关已通过用户本机反馈验收。 +- `LanguagePreferences` 独立持久化 system / zh-Hans / zh-Hant / en,仅依赖 Foundation / Observation。App 将同一 locale 注入面板与设置,切换即时生效;系统模式按 Locale.preferredLanguages 匹配已支持语言,无法匹配回退 en,不修改 AppleLanguages。外侧详情的独立 NSHostingView 显式转发 locale;UI 的 AppLocalization 为原生窗口标题与色块辅助标签查找对应 lproj,避免其沿用进程启动语言。系统菜单与 NSColorPanel 的系统文案由 macOS 管理。语言自称保留原文。 +- App 注入同一个偏好仓库,注册独立 Settings 场景;设置采用 `NavigationSplitView` 侧边栏,分为外观、语言、关于。内容卡片、选择控件与侧边栏使用系统液态玻璃/材质,关于页展示品牌图标和 Bundle 实际版本,不写死版本号。 +- App 持有一个与 UI 无关的 `SettingsPresentation` 请求状态,并向 MenuBar 与 Settings 注入同一实例。菜单入口先切换 `.regular`,递增请求并调用 `openSettings`;设置窗口观察器在请求变化时取消旧任务、等待 SwiftUI 排序后激活应用、将窗口置前并清除最小化。只使用普通窗口层级,不永久置顶;活动应用通知补充处理激活竞态,隐藏后重开与最小化恢复走同一路径。窗口关闭时恢复 `.accessory`,保留 `LSUIElement=true` 的默认无 Dock 行为。 +- 品牌图标由用户提供的 dashboard-3-fill.svg 仪表盘路径派生:菜单栏 `BrandMark` 为透明模板矢量,随明暗菜单栏系统着色;AppIcon 全尺寸与关于页 `BrandLogo` 使用白色圆角背景及原深灰图形。Dock/Finder 使用 AppIcon 资源,不增加自绘 Dock 生命周期。 - 自选强调色使用设置特性持有的 `CustomColorPicker` 控制系统 NSColorPanel;选 custom 延迟到下一次主线程调度后打开。色块使用固定 44×26pt 原生 NSButton,直接在 bounds 内绘制 RGB(不使用可缩放的符号图像),保留 target/action 并允许失焦首次点击,面板显式 makeKeyAndOrderFront / orderFrontRegardless,连续回写 RGB,可重复打开,设置关闭时仅清理自身持有的颜色面板。记录入口请求与可见状态日志以便定位。窗口观察/外观/详情锚点 NSView 的 hitTest 均返回 nil,避免拦截正常控件。 - 用户文案集中在 `Resources/Localizable.xcstrings`,覆盖 en / zh-Hans / zh-Hant;指标缩写、品牌、版本及单位保留通用写法。 @@ -151,3 +152,9 @@ App 持有进程级 `KeepAwakeService`(Core/Services,MainActor + Observable 2026-10-30 验证:Debug 构建通过;独立核心检查在普通进程与带主应用沙盒权限的临时 .app 中均通过,实际查询本进程断言,覆盖默认关闭、连续三次开关、开启后两类断言存在、关闭/服务销毁后消失。CLI 检查器直接加沙盒签名会在 libsecinit 初始化阶段退出,改用完整 .app 包后通过,未更改产品权限。当前没有 Xcode 测试 Target。UI 自动化 getApp 本轮构建超时;本轮仅退出自动化启动的测试副本,保留用户 Xcode 进程。底部实际视觉、关闭面板后长时间空闲不锁屏/息屏以及关闭开关后恢复系统策略,待用户验收。 底部液态玻璃样式调整:Debug 构建通过;实际面板中的玻璃质感及悬停视觉待用户重新运行验收。 + +### 设置窗口置前与品牌更新(2026-10-30) + +设置入口顺序改为先切换常规激活策略,再产生窗口展示请求,最后调用 `openSettings`。窗口观察器只响应明确请求和活动应用通知,以 `makeKeyAndOrderFront`、`orderFrontRegardless` 置前,未使用 floating 层级或常驻置顶。检查覆盖首次显示、其他窗口抢占焦点后恢复、`orderOut` 后重开、最小化后恢复、普通窗口层级,以及关闭事件恢复 accessory 策略。命令行直接启动的 AppKit 检查进程在 macOS 上不会自动成为活动应用;完整 `.app` 包启动后全部通过。UI 自动化读取本轮窗口仍超时,侧边栏、玻璃视觉及相关页面切换待用户验收。 + +Debug 构建通过;现有外观、自选颜色、系统/浅色/深色切换、三语偏好与真实构建资源回归检查通过。AppIcon 已核对 16–1024 px 完整尺寸和透明通道,最大 1024 px 版已人工检查白色圆角底与 SVG 仪表盘形状。菜单栏模板图及 Dock 图标缓存刷新需在用户重新运行后确认。 diff --git a/docs/settings-brand-plan.md b/docs/settings-brand-plan.md new file mode 100644 index 0000000..8d01b02 --- /dev/null +++ b/docs/settings-brand-plan.md @@ -0,0 +1,29 @@ +# 设置窗口与品牌图标实施计划 + +## 目标与范围 + +修复菜单栏打开设置时偶发被其他窗口遮挡;设置采用侧边栏导航、液态玻璃控件与关于页;使用用户提供的 dashboard-3-fill.svg 替换菜单栏、Dock/应用及关于页图标。保留原 SVG 仪表盘形状与深灰色,需要底色的应用图标使用白色圆角底。 + +涉及 App 场景装配、MenuBar 打开设置入口、Settings 视图与窗口生命周期、Core 的纯展示请求状态、Assets 图标和三语资源。保留现有外观、语言、自选颜色逻辑,不增加更新器、联网功能或登录项。 + +## 实施步骤 + +1. 导入规范化 SVG;生成 macOS AppIcon 全尺寸及关于页图标,菜单栏使用透明模板图适配明暗。 +2. App 持有无 UI 依赖的设置展示请求状态,注入两个特性;MenuBar 先切换 regular 策略再请求 Settings 场景,Settings 生命周期对每次请求激活并将具体窗口置前,避免永久置顶。 +3. 设置改为外观、语言、关于三个侧边栏项目。窗口使用原生导航与半透明背景,分组卡片及操作控件使用液态玻璃;关于页展示 Logo、真实构建版本及产品简介,不编造版权/许可证信息。 +4. 构建与本机窄范围检查;记录可验证结果及 UI/主观验收边界,按功能提交。 + +## 验证与风险 + +- Debug 构建、图标完整性和源形状核对、三语完整性、现有外观/本地化核心检查。 +- 检查新建、重复打开/关闭再打开的设置请求均触发窗口置前,窗口不使用 floating 级别;不改变外观和语言存储键。 +- 尽量实测设置导航、颜色选择和窗口层级;已有用户 Xcode 进程不退出、不替换其构建。UI 工具受阻时如实记录,玻璃质感与实际多窗口遮挡由用户验收。 +- 原生模板菜单图标随系统着色;Dock 的图标缓存可能需要退出并重新启动应用刷新。 + +## 进展 + +- 已检查现有实现:菜单入口在 accessory 策略下先 activate/openSettings;regular 策略仅在设置视图 onAppear 中切换,重复打开缺少面向实际窗口的置前请求。 +- 已完成品牌 SVG 导入、菜单栏模板图、AppIcon 全尺寸和关于页图标;Debug 构建通过。 +- 已完成设置侧边栏、关于页、液态玻璃内容卡片和窗口展示请求链路。 +- 已完成首次展示、焦点恢复、隐藏重开、最小化恢复和普通窗口层级检查;外观及三语回归通过。 +- UI 自动化仍超时;设置页实际视觉、菜单栏/Dock 图标显示与多窗口遮挡的手感由用户重新运行后验收。 diff --git a/kymo/App/kymoApp.swift b/kymo/App/kymoApp.swift index b1ee653..f503f5f 100644 --- a/kymo/App/kymoApp.swift +++ b/kymo/App/kymoApp.swift @@ -9,19 +9,21 @@ import SwiftUI /// 应用入口。 /// -/// Kymo 是一款菜单栏常驻应用:不显示 Dock 图标与主窗口, +/// Kymo 是一款菜单栏常驻应用:平时不显示 Dock 图标与主窗口, /// 通过 `MenuBarExtra` 场景在系统菜单栏展示状态并承载监控面板。 +/// 打开设置期间临时使用常规应用激活策略,以便设置窗口正常获得焦点。 @main struct kymoApp: App { @State private var metrics = MetricsStore() @State private var keepAwake = KeepAwakeService() + @State private var settingsPresentation = SettingsPresentation() @State private var appearance = AppearancePreferences() @State private var language = LanguagePreferences() var body: some Scene { MenuBarExtra { - MenuPanelView(metrics: metrics, preferences: appearance, keepAwake: keepAwake) + MenuPanelView(metrics: metrics, preferences: appearance, keepAwake: keepAwake, settingsPresentation: settingsPresentation) .environment(\.locale, language.locale) } label: { MenuBarLabel(snapshot: metrics.snapshot) @@ -29,7 +31,7 @@ struct kymoApp: App { .menuBarExtraStyle(.window) Settings { - AppearanceSettingsView(preferences: appearance, language: language) + AppearanceSettingsView(preferences: appearance, language: language, presentation: settingsPresentation) .environment(\.locale, language.locale) } } diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-128@1x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-128@1x.png new file mode 100644 index 0000000..fbee1da Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-128@1x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-128@2x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-128@2x.png new file mode 100644 index 0000000..7270df1 Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-128@2x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-16@1x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-16@1x.png new file mode 100644 index 0000000..700ccbe Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-16@1x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-16@2x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-16@2x.png new file mode 100644 index 0000000..19dfb09 Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-16@2x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-256@1x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-256@1x.png new file mode 100644 index 0000000..7270df1 Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-256@1x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-256@2x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-256@2x.png new file mode 100644 index 0000000..332d267 Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-256@2x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-32@1x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-32@1x.png new file mode 100644 index 0000000..19dfb09 Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-32@1x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-32@2x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-32@2x.png new file mode 100644 index 0000000..320d3cf Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-32@2x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-512@1x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-512@1x.png new file mode 100644 index 0000000..332d267 Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-512@1x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png new file mode 100644 index 0000000..1b19533 Binary files /dev/null and b/kymo/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png differ diff --git a/kymo/Assets.xcassets/AppIcon.appiconset/Contents.json b/kymo/Assets.xcassets/AppIcon.appiconset/Contents.json index 3f00db4..0aa8bac 100644 --- a/kymo/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/kymo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,51 +1,61 @@ { "images" : [ { + "filename" : "AppIcon-16@1x.png", "idiom" : "mac", "scale" : "1x", "size" : "16x16" }, { + "filename" : "AppIcon-16@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "16x16" }, { + "filename" : "AppIcon-32@1x.png", "idiom" : "mac", "scale" : "1x", "size" : "32x32" }, { + "filename" : "AppIcon-32@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "32x32" }, { + "filename" : "AppIcon-128@1x.png", "idiom" : "mac", "scale" : "1x", "size" : "128x128" }, { + "filename" : "AppIcon-128@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "128x128" }, { + "filename" : "AppIcon-256@1x.png", "idiom" : "mac", "scale" : "1x", "size" : "256x256" }, { + "filename" : "AppIcon-256@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "256x256" }, { + "filename" : "AppIcon-512@1x.png", "idiom" : "mac", "scale" : "1x", "size" : "512x512" }, { + "filename" : "AppIcon-512@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "512x512" @@ -55,4 +65,4 @@ "author" : "xcode", "version" : 1 } -} +} \ No newline at end of file diff --git a/kymo/Assets.xcassets/BrandLogo.imageset/BrandLogo.svg b/kymo/Assets.xcassets/BrandLogo.imageset/BrandLogo.svg new file mode 100644 index 0000000..0a67246 --- /dev/null +++ b/kymo/Assets.xcassets/BrandLogo.imageset/BrandLogo.svg @@ -0,0 +1 @@ + diff --git a/kymo/Assets.xcassets/BrandLogo.imageset/Contents.json b/kymo/Assets.xcassets/BrandLogo.imageset/Contents.json new file mode 100644 index 0000000..f23cc45 --- /dev/null +++ b/kymo/Assets.xcassets/BrandLogo.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images": [ + { + "filename": "BrandLogo.svg", + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + }, + "properties": { + "preserves-vector-representation": true + } +} diff --git a/kymo/Assets.xcassets/BrandMark.imageset/BrandMark.svg b/kymo/Assets.xcassets/BrandMark.imageset/BrandMark.svg new file mode 100644 index 0000000..988f7fc --- /dev/null +++ b/kymo/Assets.xcassets/BrandMark.imageset/BrandMark.svg @@ -0,0 +1 @@ + diff --git a/kymo/Assets.xcassets/BrandMark.imageset/Contents.json b/kymo/Assets.xcassets/BrandMark.imageset/Contents.json new file mode 100644 index 0000000..527ea5a --- /dev/null +++ b/kymo/Assets.xcassets/BrandMark.imageset/Contents.json @@ -0,0 +1,16 @@ +{ + "images": [ + { + "filename": "BrandMark.svg", + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + }, + "properties": { + "preserves-vector-representation": true, + "template-rendering-intent": "template" + } +} diff --git a/kymo/Core/Services/SettingsPresentation.swift b/kymo/Core/Services/SettingsPresentation.swift new file mode 100644 index 0000000..fae2934 --- /dev/null +++ b/kymo/Core/Services/SettingsPresentation.swift @@ -0,0 +1,7 @@ +import Observation + +/// A UI-independent intent shared by the menu entry and the settings scene. +@MainActor @Observable final class SettingsPresentation { + private(set) var requestID: UInt64 = 0 + func request() { requestID &+= 1 } +} diff --git a/kymo/Features/MenuBar/MenuBarLabel.swift b/kymo/Features/MenuBar/MenuBarLabel.swift index 249de1a..1a43684 100644 --- a/kymo/Features/MenuBar/MenuBarLabel.swift +++ b/kymo/Features/MenuBar/MenuBarLabel.swift @@ -10,7 +10,11 @@ struct MenuBarLabel: View { Text(verbatim: title) .monospacedDigit() } icon: { - Image(systemName: "gauge") + Image("BrandMark") + .renderingMode(.template) + .resizable() + .scaledToFit() + .frame(width: 18, height: 18) } .labelStyle(.titleAndIcon) } diff --git a/kymo/Features/MenuBar/MenuPanelView.swift b/kymo/Features/MenuBar/MenuPanelView.swift index 0b7aea5..eef6186 100644 --- a/kymo/Features/MenuBar/MenuPanelView.swift +++ b/kymo/Features/MenuBar/MenuPanelView.swift @@ -5,6 +5,7 @@ struct MenuPanelView: View { let metrics: MetricsStore let preferences: AppearancePreferences let keepAwake: KeepAwakeService + let settingsPresentation: SettingsPresentation @Environment(\.openSettings) private var openSettings var body: some View { @@ -210,7 +211,11 @@ struct MenuPanelView: View { } .help(metrics.isPaused ? Text("action.resume") : Text("action.pause")) .accessibilityLabel(metrics.isPaused ? Text("action.resume") : Text("action.pause")) - Button { NSApp.activate(); openSettings() } label: { + Button { + NSApp.setActivationPolicy(.regular) + settingsPresentation.request() + openSettings() + } label: { Image(systemName: "gearshape").frame(width: 20, height: 20) } .help(Text("action.settings")).accessibilityLabel(Text("action.settings")) diff --git a/kymo/Features/Settings/AppearanceSettingsView.swift b/kymo/Features/Settings/AppearanceSettingsView.swift index 7363a63..d0a2816 100644 --- a/kymo/Features/Settings/AppearanceSettingsView.swift +++ b/kymo/Features/Settings/AppearanceSettingsView.swift @@ -1,30 +1,83 @@ import SwiftUI import AppKit -/// B-stage appearance controls; general/modules/permissions remain D-stage work. +/// Settings navigation owns presentation only; persisted preferences remain in Core. struct AppearanceSettingsView: View { @Bindable var preferences: AppearancePreferences @Bindable var language: LanguagePreferences + let presentation: SettingsPresentation @Environment(\.locale) private var locale @State private var colorPicker = CustomColorPicker() + @State private var selection: SettingsPage? = .appearance var body: some View { - Form { - Section("settings.language") { - Picker("language.title", selection: $language.language) { - Text("language.system").tag(AppLanguage.system) - Text(verbatim: "简体中文").tag(AppLanguage.simplifiedChinese) - Text(verbatim: "繁體中文").tag(AppLanguage.traditionalChinese) - Text(verbatim: "English").tag(AppLanguage.english) + NavigationSplitView { + List(selection: $selection) { + ForEach(SettingsPage.allCases) { page in + Label(page.title, systemImage: page.symbol).tag(page) } } - Section("settings.appearance") { + .listStyle(.sidebar) + .navigationSplitViewColumnWidth(min: 160, ideal: 175, max: 200) + .safeAreaInset(edge: .bottom) { + HStack(spacing: 8) { + Image("BrandLogo").resizable().frame(width: 34, height: 34) + Text(verbatim: "Kymo").font(.headline) + Spacer() + } + .padding(12) + } + } detail: { + ScrollView { + VStack(alignment: .leading, spacing: 22) { + Text((selection ?? .appearance).title) + .font(.largeTitle.bold()) + switch selection ?? .appearance { + case .appearance: appearancePage + case .language: languagePage + case .about: aboutPage + } + } + .frame(maxWidth: 480, alignment: .leading) + .padding(28) + .frame(maxWidth: .infinity, alignment: .topLeading) + } + .background(.regularMaterial) + } + .navigationSplitViewStyle(.balanced) + .background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale), + requestID: presentation.requestID, + onClose: { colorPicker.close() })) + .onChange(of: preferences.accent) { _, choice in + if choice == .custom { + Task { @MainActor in + await Task.yield() + guard preferences.accent == .custom else { return } + colorPicker.show(for: preferences) + } + } else { colorPicker.close() } + } + .onChange(of: selection) { _, _ in colorPicker.close() } + .frame(minWidth: 680, idealWidth: 740, minHeight: 450, idealHeight: 500) + .modifier(AppearanceStyle(preferences: preferences)) + } + + private var appearancePage: some View { + glassCard { + VStack(alignment: .leading, spacing: 12) { + Text("appearance.title").font(.headline) Picker("appearance.title", selection: $preferences.appearance) { Text("appearance.system").tag(AppAppearance.system) Text("appearance.light").tag(AppAppearance.light) Text("appearance.dark").tag(AppAppearance.dark) } + .labelsHidden() .pickerStyle(.segmented) + } + Divider() + HStack { + Text("accent.title").font(.headline) + Spacer() Picker("accent.title", selection: $preferences.accent) { Text("accent.system").tag(AccentChoice.system) Text("accent.blue").tag(AccentChoice.blue) @@ -35,31 +88,84 @@ struct AppearanceSettingsView: View { Text("accent.pink").tag(AccentChoice.pink) Text("accent.custom").tag(AccentChoice.custom) } - if preferences.accent == .custom { - HStack { - Text("accent.custom") - Spacer() - CustomColorWell(preferences: preferences, picker: colorPicker) - .frame(width: 44, height: 26) - } + .labelsHidden() + .fixedSize() + .buttonStyle(.glass) + } + if preferences.accent == .custom { + Divider() + HStack { + Text("accent.custom").font(.headline) + Spacer() + CustomColorWell(preferences: preferences, picker: colorPicker) + .frame(width: 44, height: 26) } } } - .background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale), onClose: { colorPicker.close() })) - .onChange(of: preferences.accent) { _, choice in - if choice == .custom { - Task { @MainActor in - await Task.yield() - guard preferences.accent == .custom else { return } - colorPicker.show(for: preferences) - } - } - else { colorPicker.close() } - } - .onAppear { NSApp.setActivationPolicy(.regular); NSApp.activate() } - .formStyle(.grouped) - .frame(width: 460, height: 340) - .modifier(AppearanceStyle(preferences: preferences)) } + private var languagePage: some View { + glassCard { + HStack { + Text("language.title").font(.headline) + Spacer() + Picker("language.title", selection: $language.language) { + Text("language.system").tag(AppLanguage.system) + Text(verbatim: "简体中文").tag(AppLanguage.simplifiedChinese) + Text(verbatim: "繁體中文").tag(AppLanguage.traditionalChinese) + Text(verbatim: "English").tag(AppLanguage.english) + } + .labelsHidden() + .fixedSize() + .buttonStyle(.glass) + } + Text("language.immediate").font(.callout).foregroundStyle(.secondary) + } + } + + private var aboutPage: some View { + glassCard { + VStack(spacing: 16) { + Image("BrandLogo").resizable().scaledToFit().frame(width: 112, height: 112) + .accessibilityHidden(true) + Text(verbatim: "Kymo").font(.system(size: 28, weight: .bold)) + Text("about.version \(version)").font(.callout).foregroundStyle(.secondary) + Text("about.description").multilineTextAlignment(.center).foregroundStyle(.secondary) + } + .frame(maxWidth: .infinity).padding(.vertical, 16) + } + } + + private var version: String { + let bundle = Bundle.main + let version = bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "--" + let build = bundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "--" + return "\(version) (\(build))" + } + + private func glassCard(@ViewBuilder content: () -> Content) -> some View { + VStack(alignment: .leading, spacing: 18, content: content) + .padding(22) + .frame(maxWidth: .infinity, alignment: .leading) + .glassEffect(.regular, in: .rect(cornerRadius: 22)) + } +} + +private enum SettingsPage: String, CaseIterable, Identifiable { + case appearance, language, about + var id: String { rawValue } + var title: LocalizedStringKey { + switch self { + case .appearance: "settings.appearance" + case .language: "settings.language" + case .about: "settings.about" + } + } + var symbol: String { + switch self { + case .appearance: "paintpalette" + case .language: "globe" + case .about: "info.circle" + } + } } diff --git a/kymo/Features/Settings/SettingsWindowLifecycle.swift b/kymo/Features/Settings/SettingsWindowLifecycle.swift index 1ee43c5..3f83530 100644 --- a/kymo/Features/Settings/SettingsWindowLifecycle.swift +++ b/kymo/Features/Settings/SettingsWindowLifecycle.swift @@ -4,18 +4,25 @@ import AppKit /// Keep the app discoverable while its settings window is open, including reopen. struct SettingsWindowLifecycle: NSViewRepresentable { var title: String + var requestID: UInt64 = 0 var onClose: () -> Void = {} func makeNSView(context: Context) -> WindowObserverView { WindowObserverView() } func updateNSView(_ nsView: WindowObserverView, context: Context) { nsView.onClose = onClose nsView.title = title + nsView.requestID = requestID } final class WindowObserverView: NSView { override func hitTest(_ point: NSPoint) -> NSView? { nil } var onClose: () -> Void = {} var title = "" { didSet { window?.title = title } } + var requestID: UInt64 = 0 { + didSet { if oldValue != requestID { schedulePresentation() } } + } + private var presentationTask: Task? + private var needsPresentation = false private var tokens: [NSObjectProtocol] = [] override func viewDidMoveToWindow() { @@ -24,6 +31,17 @@ struct SettingsWindowLifecycle: NSViewRepresentable { tokens.removeAll() guard let window else { return } window.title = title + window.titlebarAppearsTransparent = true + window.isOpaque = false + window.backgroundColor = .clear + schedulePresentation() + tokens.append(NotificationCenter.default.addObserver(forName: NSApplication.didBecomeActiveNotification, + object: NSApp, queue: .main) { [weak self] _ in + MainActor.assumeIsolated { + guard let self, self.needsPresentation else { return } + self.presentWindow() + } + }) tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.didBecomeKeyNotification, object: window, queue: .main) { _ in MainActor.assumeIsolated { @@ -33,12 +51,36 @@ struct SettingsWindowLifecycle: NSViewRepresentable { tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification, object: window, queue: .main) { [weak self] _ in MainActor.assumeIsolated { + self?.presentationTask?.cancel() + self?.needsPresentation = false self?.onClose() NSApp.setActivationPolicy(.accessory) } }) } - deinit { for token in tokens { NotificationCenter.default.removeObserver(token) } } + private func schedulePresentation() { + guard window != nil else { return } + needsPresentation = true + NSApp.setActivationPolicy(.regular) + presentationTask?.cancel() + presentationTask = Task { @MainActor [weak self] in + // Allow accessory → regular and SwiftUI's openSettings ordering to settle. + await Task.yield() + guard !Task.isCancelled, let self, self.needsPresentation else { return } + self.presentWindow() + } + } + + private func presentWindow() { + guard let window else { return } + if window.isMiniaturized { window.deminiaturize(nil) } + NSApp.activate() + window.makeKeyAndOrderFront(nil) + window.orderFrontRegardless() + if NSApp.isActive { needsPresentation = false } + } + + deinit { presentationTask?.cancel(); for token in tokens { NotificationCenter.default.removeObserver(token) } } } } diff --git a/kymo/Resources/Localizable.xcstrings b/kymo/Resources/Localizable.xcstrings index e14ac2f..0e84265 100644 --- a/kymo/Resources/Localizable.xcstrings +++ b/kymo/Resources/Localizable.xcstrings @@ -1759,6 +1759,94 @@ } } } + }, + "settings.about": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "About" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "关于" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "關於" + } + } + } + }, + "language.immediate": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Changes apply immediately. Your choice is saved for the next launch." + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "切换后立即生效,下次启动保留所选语言。" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "切換後立即生效,下次啟動保留所選語言。" + } + } + } + }, + "about.version %@": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Version %@" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "版本 %@" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "版本 %@" + } + } + } + }, + "about.description": { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "A lightweight macOS menu bar monitor for system resources." + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "轻量的 macOS 菜单栏系统资源监控工具。" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "輕量的 macOS 選單列系統資源監控工具。" + } + } + } } }, "version": "1.0" diff --git a/kymoTests/README.md b/kymoTests/README.md index 573720f..0008e7b 100644 --- a/kymoTests/README.md +++ b/kymoTests/README.md @@ -95,3 +95,16 @@ swiftc -module-cache-path /private/tmp/kymo-check-cache \ ``` 检查真实 IOKit 请求的创建、重复开关与生命周期释放;测试结束不保留唤醒断言。不能替代实际空闲锁屏、息屏及面板视觉验收。 + +## 设置窗口展示检查 + +检查必须作为完整 `.app` 启动,直接运行 CLI 可执行文件时 macOS 不会自动激活测试应用: + +```bash +swiftc -module-cache-path /private/tmp/kymo-settings-cache \ + kymo/Core/Services/SettingsPresentation.swift \ + kymo/Features/Settings/SettingsWindowLifecycle.swift \ + kymoTests/SettingsWindowChecks.swift -o /private/tmp/kymo-settings-checks +``` + +将临时可执行文件放入带 Info.plist 并已完成代码签名的临时 `.app/Contents/MacOS`,再用 `open -n -W` 启动。检查首次展示、焦点恢复、隐藏重开、最小化恢复、普通窗口层级及关闭生命周期;不替代实际多窗口场景与视觉验收。 diff --git a/kymoTests/SettingsWindowChecks.swift b/kymoTests/SettingsWindowChecks.swift new file mode 100644 index 0000000..97e9008 --- /dev/null +++ b/kymoTests/SettingsWindowChecks.swift @@ -0,0 +1,59 @@ +import AppKit +import SwiftUI + +@main struct SettingsWindowChecks { + @MainActor static func main() { + _ = NSApplication.shared + Task { @MainActor in + await runChecks() + NSApp.terminate(nil) + } + NSApp.run() + } + + @MainActor static func runChecks() async { + let request = SettingsPresentation() + request.request() + precondition(request.requestID == 1) + request.request() + precondition(request.requestID == 2) + let window = NSWindow(contentRect: NSRect(x: 100, y: 100, width: 680, height: 450), + styleMask: [.titled, .closable, .miniaturizable], backing: .buffered, defer: false) + window.isReleasedWhenClosed = false + let view = SettingsWindowLifecycle.WindowObserverView() + var closed = false + view.onClose = { closed = true } + view.title = "Settings checks" + window.contentView = view + await settle() + precondition(window.isVisible && window.isKeyWindow) + precondition(window.level == .normal) + let other = NSWindow(contentRect: window.frame, styleMask: [.titled], backing: .buffered, defer: false) + other.isReleasedWhenClosed = false + other.makeKeyAndOrderFront(nil) + precondition(other.isKeyWindow) + view.requestID = request.requestID + await settle() + precondition(window.isKeyWindow) + window.orderOut(nil) + precondition(!window.isVisible) + request.request() + view.requestID = request.requestID + await settle() + precondition(window.isVisible && window.isKeyWindow) + window.miniaturize(nil) + request.request() + view.requestID = request.requestID + await settle() + precondition(!window.isMiniaturized && window.isKeyWindow) + window.close() + precondition(closed) + precondition(NSApp.activationPolicy() == .accessory) + other.close() + print("PASS: request sequence, first presentation, key-window recovery, hidden reopen, miniaturized recovery, normal level and close lifecycle") + } + + @MainActor private static func settle() async { + try? await Task.sleep(for: .milliseconds(350)) + } +}