feat(settings): 重构液态玻璃设置并更新品牌图标

This commit is contained in:
2026-10-30 16:35:50 +08:00
parent 5c8b6ed136
commit c2f0549568
27 changed files with 449 additions and 43 deletions
+1
View File
@@ -11,6 +11,7 @@
| [testing-capabilities.md](testing-capabilities.md) | 当前智能体测试能力实测、环境限制与验证边界 | | [testing-capabilities.md](testing-capabilities.md) | 当前智能体测试能力实测、环境限制与验证边界 |
| [development.md](development.md) | 开发环境搭建、构建调试、测试 Target 添加与协作规范 | | [development.md](development.md) | 开发环境搭建、构建调试、测试 Target 添加与协作规范 |
| [implementation-plan.md](implementation-plan.md) | 已定稿方案、阶段顺序与实施进度 | | [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-a-validation.md](stage-a-validation.md) | A 阶段采样、资源及 UI 验证记录 |
| [stage-b-validation.md](stage-b-validation.md) | B 阶段面板、外观与三语验证记录 | | [stage-b-validation.md](stage-b-validation.md) | B 阶段面板、外观与三语验证记录 |
| [roadmap.md](roadmap.md) | 版本路线图与里程碑 | | [roadmap.md](roadmap.md) | 版本路线图与里程碑 |
+12 -5
View File
@@ -4,7 +4,7 @@
Kymo 是一款 macOS 菜单栏常驻的资源监控工具,设计目标为「轻量、低功耗、无干扰」: Kymo 是一款 macOS 菜单栏常驻的资源监控工具,设计目标为「轻量、低功耗、无干扰」:
- **常驻形态**:使用 SwiftUI 原生 `MenuBarExtra`(window 样式),无 Dock 图标、无常驻窗口; - **常驻形态**:使用 SwiftUI 原生 `MenuBarExtra`(window 样式),平时无 Dock 图标、无常驻窗口;设置窗口打开期间临时显示 Dock 图标并提供常规窗口焦点;
- **数据驱动**:采样器定时采集系统指标 → 汇成统一快照 → 驱动菜单栏文本与面板 UI; - **数据驱动**:采样器定时采集系统指标 → 汇成统一快照 → 驱动菜单栏文本与面板 UI;
- **可扩展**:新增监控项只需新增一个采样器并注册,不改动既有 UI 结构; - **可扩展**:新增监控项只需新增一个采样器并注册,不改动既有 UI 结构;
- **低功耗**:单一调度器统一驱动采样,频率可配置,面板不可见时降低非必要刷新。 - **低功耗**:单一调度器统一驱动采样,频率可配置,面板不可见时降低非必要刷新。
@@ -41,7 +41,7 @@ Kymo 是一款 macOS 菜单栏常驻的资源监控工具,设计目标为「
`MemoryMonitor` 与 `getloadavg`,返回 Sendable `MetricsSnapshot`,再回 MainActor 整体发布。 `MemoryMonitor` 与 `getloadavg`,返回 Sendable `MetricsSnapshot`,再回 MainActor 整体发布。
默认每次采样完成后等待 2s,不会重叠采样;当前刷新间隔尚未接入设置。 默认每次采样完成后等待 2s,不会重叠采样;当前刷新间隔尚未接入设置。
菜单栏标签采用 `Label`(单个 gauge 图标 + 单个文本标题),所有指标合入标题, 菜单栏标签采用 `Label`(品牌模板图标 + 单个文本标题),所有指标合入标题,
以 CPU / GPU / MEM 短标签区分;GPU 不可用时移除对应片段。此前多 Image/Text 的 HStack 以 CPU / GPU / MEM 短标签区分;GPU 不可用时移除对应片段。此前多 Image/Text 的 HStack
在用户最新构建中仅显示一个百分比,已改写以避免依赖多个独立标签节点的转换;修复后的双指标显示已通过用户重新运行后的局部截图验收。 在用户最新构建中仅显示一个百分比,已改写以避免依赖多个独立标签节点的转换;修复后的双指标显示已通过用户重新运行后的局部截图验收。
@@ -64,9 +64,10 @@ GPU 的 IOReport spike 能枚举本机通道,但订阅返回空,当前快照
- 数值与悬浮过渡仅在可见行启用,遵循减少动态效果;面板关闭不挂载独立动画时钟。趋势追加样本时使用 0.35 秒位置插值,满容量保留一个出场点并裁剪;首次显示、非连续更新和减少动态效果直接显示当前历史。仅每次可见更新安排一次可取消任务,无周期动画时钟。 - 数值与悬浮过渡仅在可见行启用,遵循减少动态效果;面板关闭不挂载独立动画时钟。趋势追加样本时使用 0.35 秒位置插值,满容量保留一个出场点并裁剪;首次显示、非连续更新和减少动态效果直接显示当前历史。仅每次可见更新安排一次可取消任务,无周期动画时钟。
- 面板沿用 MenuBarExtra 系统窗口背景,不叠加整块自绘玻璃;操作按钮使用系统 `.glass`。TV1 的真实材质融合验收尚未完成,不能由离屏渲染认定通过。 - 面板沿用 MenuBarExtra 系统窗口背景,不叠加整块自绘玻璃;操作按钮使用系统 `.glass`。TV1 的真实材质融合验收尚未完成,不能由离屏渲染认定通过。
- `AppearancePreferences` 仅依赖 Foundation / Observation,持久化外观、系统/六种预设/自选 RGB 强调色。UI 层 `AppearanceStyle` 将偏好映射为明确的深/浅色及窗口级 NSAppearance / Color。跟随系统从全局偏好 AppleInterfaceStyle 独立解析,监听系统主题通知及 NSApp effectiveAppearance 变化后刷新;为 SwiftUI 同时提供非 nil 的 preferredColorScheme 与 colorScheme 环境,避免返回 nil 和失焦后重新继承窗口残留模式。用户持久化值仍为 system,App 全局 appearance 不被修改。该系统偏好键/主题通知属于平台约定,系统动态切换仍需实机验证;外观覆盖作用于面板与设置,不作用于菜单栏标签。 - `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 以容纳语言区。 - `LanguagePreferences` 独立持久化 system / zh-Hans / zh-Hant / en,仅依赖 Foundation / Observation。App 将同一 locale 注入面板与设置,切换即时生效;系统模式按 Locale.preferredLanguages 匹配已支持语言,无法匹配回退 en,不修改 AppleLanguages。外侧详情的独立 NSHostingView 显式转发 locale;UI 的 AppLocalization 为原生窗口标题与色块辅助标签查找对应 lproj,避免其沿用进程启动语言。系统菜单与 NSColorPanel 的系统文案由 macOS 管理。语言自称保留原文。
- App 注入同一个偏好仓库,注册独立 Settings 场景;Settings 特性当前实现语言与外观表单,不横向引用 MenuBar 特性。 - App 注入同一个偏好仓库,注册独立 Settings 场景;设置采用 `NavigationSplitView` 侧边栏,分为外观、语言、关于。内容卡片、选择控件与侧边栏使用系统液态玻璃/材质,关于页展示品牌图标和 Bundle 实际版本,不写死版本号。
- 显式设置 `LSUIElement=true` 保持默认无 Dock;设置视图出现切换 `.regular` 并激活,Settings 自己的窗口观察器在重新成为 key 时保持 `.regular`、关闭时恢复 `.accessory`。该 R14 实现为引入设置场景所需而前置,Dock 随设置开关已通过用户本机反馈验收。 - 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,避免拦截正常控件。 - 自选强调色使用设置特性持有的 `CustomColorPicker` 控制系统 NSColorPanel;选 custom 延迟到下一次主线程调度后打开。色块使用固定 44×26pt 原生 NSButton,直接在 bounds 内绘制 RGB(不使用可缩放的符号图像),保留 target/action 并允许失焦首次点击,面板显式 makeKeyAndOrderFront / orderFrontRegardless,连续回写 RGB,可重复打开,设置关闭时仅清理自身持有的颜色面板。记录入口请求与可见状态日志以便定位。窗口观察/外观/详情锚点 NSView 的 hitTest 均返回 nil,避免拦截正常控件。
- 用户文案集中在 `Resources/Localizable.xcstrings`,覆盖 en / zh-Hans / zh-Hant;指标缩写、品牌、版本及单位保留通用写法。 - 用户文案集中在 `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 进程。底部实际视觉、关闭面板后长时间空闲不锁屏/息屏以及关闭开关后恢复系统策略,待用户验收。 2026-10-30 验证:Debug 构建通过;独立核心检查在普通进程与带主应用沙盒权限的临时 .app 中均通过,实际查询本进程断言,覆盖默认关闭、连续三次开关、开启后两类断言存在、关闭/服务销毁后消失。CLI 检查器直接加沙盒签名会在 libsecinit 初始化阶段退出,改用完整 .app 包后通过,未更改产品权限。当前没有 Xcode 测试 Target。UI 自动化 getApp 本轮构建超时;本轮仅退出自动化启动的测试副本,保留用户 Xcode 进程。底部实际视觉、关闭面板后长时间空闲不锁屏/息屏以及关闭开关后恢复系统策略,待用户验收。
底部液态玻璃样式调整:Debug 构建通过;实际面板中的玻璃质感及悬停视觉待用户重新运行验收。 底部液态玻璃样式调整:Debug 构建通过;实际面板中的玻璃质感及悬停视觉待用户重新运行验收。
### 设置窗口置前与品牌更新(2026-10-30)
设置入口顺序改为先切换常规激活策略,再产生窗口展示请求,最后调用 `openSettings`。窗口观察器只响应明确请求和活动应用通知,以 `makeKeyAndOrderFront`、`orderFrontRegardless` 置前,未使用 floating 层级或常驻置顶。检查覆盖首次显示、其他窗口抢占焦点后恢复、`orderOut` 后重开、最小化后恢复、普通窗口层级,以及关闭事件恢复 accessory 策略。命令行直接启动的 AppKit 检查进程在 macOS 上不会自动成为活动应用;完整 `.app` 包启动后全部通过。UI 自动化读取本轮窗口仍超时,侧边栏、玻璃视觉及相关页面切换待用户验收。
Debug 构建通过;现有外观、自选颜色、系统/浅色/深色切换、三语偏好与真实构建资源回归检查通过。AppIcon 已核对 16–1024 px 完整尺寸和透明通道,最大 1024 px 版已人工检查白色圆角底与 SVG 仪表盘形状。菜单栏模板图及 Dock 图标缓存刷新需在用户重新运行后确认。
+29
View File
@@ -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 图标显示与多窗口遮挡的手感由用户重新运行后验收。
+5 -3
View File
@@ -9,19 +9,21 @@ import SwiftUI
/// 应用入口。 /// 应用入口。
/// ///
/// Kymo 是一款菜单栏常驻应用:不显示 Dock 图标与主窗口, /// Kymo 是一款菜单栏常驻应用:平时不显示 Dock 图标与主窗口,
/// 通过 `MenuBarExtra` 场景在系统菜单栏展示状态并承载监控面板。 /// 通过 `MenuBarExtra` 场景在系统菜单栏展示状态并承载监控面板。
/// 打开设置期间临时使用常规应用激活策略,以便设置窗口正常获得焦点。
@main @main
struct kymoApp: App { struct kymoApp: App {
@State private var metrics = MetricsStore() @State private var metrics = MetricsStore()
@State private var keepAwake = KeepAwakeService() @State private var keepAwake = KeepAwakeService()
@State private var settingsPresentation = SettingsPresentation()
@State private var appearance = AppearancePreferences() @State private var appearance = AppearancePreferences()
@State private var language = LanguagePreferences() @State private var language = LanguagePreferences()
var body: some Scene { var body: some Scene {
MenuBarExtra { MenuBarExtra {
MenuPanelView(metrics: metrics, preferences: appearance, keepAwake: keepAwake) MenuPanelView(metrics: metrics, preferences: appearance, keepAwake: keepAwake, settingsPresentation: settingsPresentation)
.environment(\.locale, language.locale) .environment(\.locale, language.locale)
} label: { } label: {
MenuBarLabel(snapshot: metrics.snapshot) MenuBarLabel(snapshot: metrics.snapshot)
@@ -29,7 +31,7 @@ struct kymoApp: App {
.menuBarExtraStyle(.window) .menuBarExtraStyle(.window)
Settings { Settings {
AppearanceSettingsView(preferences: appearance, language: language) AppearanceSettingsView(preferences: appearance, language: language, presentation: settingsPresentation)
.environment(\.locale, language.locale) .environment(\.locale, language.locale)
} }
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1002 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1002 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

@@ -1,51 +1,61 @@
{ {
"images" : [ "images" : [
{ {
"filename" : "AppIcon-16@1x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "1x", "scale" : "1x",
"size" : "16x16" "size" : "16x16"
}, },
{ {
"filename" : "AppIcon-16@2x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "2x", "scale" : "2x",
"size" : "16x16" "size" : "16x16"
}, },
{ {
"filename" : "AppIcon-32@1x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "1x", "scale" : "1x",
"size" : "32x32" "size" : "32x32"
}, },
{ {
"filename" : "AppIcon-32@2x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "2x", "scale" : "2x",
"size" : "32x32" "size" : "32x32"
}, },
{ {
"filename" : "AppIcon-128@1x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "1x", "scale" : "1x",
"size" : "128x128" "size" : "128x128"
}, },
{ {
"filename" : "AppIcon-128@2x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "2x", "scale" : "2x",
"size" : "128x128" "size" : "128x128"
}, },
{ {
"filename" : "AppIcon-256@1x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "1x", "scale" : "1x",
"size" : "256x256" "size" : "256x256"
}, },
{ {
"filename" : "AppIcon-256@2x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "2x", "scale" : "2x",
"size" : "256x256" "size" : "256x256"
}, },
{ {
"filename" : "AppIcon-512@1x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "1x", "scale" : "1x",
"size" : "512x512" "size" : "512x512"
}, },
{ {
"filename" : "AppIcon-512@2x.png",
"idiom" : "mac", "idiom" : "mac",
"scale" : "2x", "scale" : "2x",
"size" : "512x512" "size" : "512x512"
@@ -55,4 +65,4 @@
"author" : "xcode", "author" : "xcode",
"version" : 1 "version" : 1
} }
} }
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><rect x="80" y="80" width="864" height="864" rx="192" fill="#fff"/><path d="M512 85.333333c235.648 0 426.666667 191.018667 426.666667 426.666667s-191.018667 426.666667-426.666667 426.666667S85.333333 747.648 85.333333 512 276.352 85.333333 512 85.333333z m196.096 230.570667a25.429333 25.429333 0 0 0-32.554667-2.858667c-123.306667 86.528-192.853333 137.813333-208.810666 153.685334a64 64 0 0 0 90.538666 90.538666c9.344-9.386667 60.501333-78.976 153.514667-208.938666a25.173333 25.173333 0 0 0-2.688-32.426667zM746.666667 469.333333a42.666667 42.666667 0 1 0 0 85.333334 42.666667 42.666667 0 0 0 0-85.333334z m-469.333334 0a42.666667 42.666667 0 1 0 0 85.333334 42.666667 42.666667 0 0 0 0-85.333334z m98.901334-153.429333a42.666667 42.666667 0 1 0-60.330667 60.330667 42.666667 42.666667 0 0 0 60.330667-60.330667zM512 234.666667a42.666667 42.666667 0 1 0 0 85.333333 42.666667 42.666667 0 0 0 0-85.333333z" transform="translate(154 154) scale(.7)" fill="#2c2c2c"/></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

+15
View File
@@ -0,0 +1,15 @@
{
"images": [
{
"filename": "BrandLogo.svg",
"idiom": "universal"
}
],
"info": {
"author": "xcode",
"version": 1
},
"properties": {
"preserves-vector-representation": true
}
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path d="M512 85.333333c235.648 0 426.666667 191.018667 426.666667 426.666667s-191.018667 426.666667-426.666667 426.666667S85.333333 747.648 85.333333 512 276.352 85.333333 512 85.333333z m196.096 230.570667a25.429333 25.429333 0 0 0-32.554667-2.858667c-123.306667 86.528-192.853333 137.813333-208.810666 153.685334a64 64 0 0 0 90.538666 90.538666c9.344-9.386667 60.501333-78.976 153.514667-208.938666a25.173333 25.173333 0 0 0-2.688-32.426667zM746.666667 469.333333a42.666667 42.666667 0 1 0 0 85.333334 42.666667 42.666667 0 0 0 0-85.333334z m-469.333334 0a42.666667 42.666667 0 1 0 0 85.333334 42.666667 42.666667 0 0 0 0-85.333334z m98.901334-153.429333a42.666667 42.666667 0 1 0-60.330667 60.330667 42.666667 42.666667 0 0 0 60.330667-60.330667zM512 234.666667a42.666667 42.666667 0 1 0 0 85.333333 42.666667 42.666667 0 0 0 0-85.333333z" fill="#2c2c2c"/></svg>

After

Width:  |  Height:  |  Size: 931 B

+16
View File
@@ -0,0 +1,16 @@
{
"images": [
{
"filename": "BrandMark.svg",
"idiom": "universal"
}
],
"info": {
"author": "xcode",
"version": 1
},
"properties": {
"preserves-vector-representation": true,
"template-rendering-intent": "template"
}
}
@@ -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 }
}
+5 -1
View File
@@ -10,7 +10,11 @@ struct MenuBarLabel: View {
Text(verbatim: title) Text(verbatim: title)
.monospacedDigit() .monospacedDigit()
} icon: { } icon: {
Image(systemName: "gauge") Image("BrandMark")
.renderingMode(.template)
.resizable()
.scaledToFit()
.frame(width: 18, height: 18)
} }
.labelStyle(.titleAndIcon) .labelStyle(.titleAndIcon)
} }
+6 -1
View File
@@ -5,6 +5,7 @@ struct MenuPanelView: View {
let metrics: MetricsStore let metrics: MetricsStore
let preferences: AppearancePreferences let preferences: AppearancePreferences
let keepAwake: KeepAwakeService let keepAwake: KeepAwakeService
let settingsPresentation: SettingsPresentation
@Environment(\.openSettings) private var openSettings @Environment(\.openSettings) private var openSettings
var body: some View { var body: some View {
@@ -210,7 +211,11 @@ struct MenuPanelView: View {
} }
.help(metrics.isPaused ? Text("action.resume") : Text("action.pause")) .help(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
.accessibilityLabel(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) Image(systemName: "gearshape").frame(width: 20, height: 20)
} }
.help(Text("action.settings")).accessibilityLabel(Text("action.settings")) .help(Text("action.settings")).accessibilityLabel(Text("action.settings"))
@@ -1,30 +1,83 @@
import SwiftUI import SwiftUI
import AppKit 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 { struct AppearanceSettingsView: View {
@Bindable var preferences: AppearancePreferences @Bindable var preferences: AppearancePreferences
@Bindable var language: LanguagePreferences @Bindable var language: LanguagePreferences
let presentation: SettingsPresentation
@Environment(\.locale) private var locale @Environment(\.locale) private var locale
@State private var colorPicker = CustomColorPicker() @State private var colorPicker = CustomColorPicker()
@State private var selection: SettingsPage? = .appearance
var body: some View { var body: some View {
Form { NavigationSplitView {
Section("settings.language") { List(selection: $selection) {
Picker("language.title", selection: $language.language) { ForEach(SettingsPage.allCases) { page in
Text("language.system").tag(AppLanguage.system) Label(page.title, systemImage: page.symbol).tag(page)
Text(verbatim: "简体中文").tag(AppLanguage.simplifiedChinese)
Text(verbatim: "繁體中文").tag(AppLanguage.traditionalChinese)
Text(verbatim: "English").tag(AppLanguage.english)
} }
} }
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) { Picker("appearance.title", selection: $preferences.appearance) {
Text("appearance.system").tag(AppAppearance.system) Text("appearance.system").tag(AppAppearance.system)
Text("appearance.light").tag(AppAppearance.light) Text("appearance.light").tag(AppAppearance.light)
Text("appearance.dark").tag(AppAppearance.dark) Text("appearance.dark").tag(AppAppearance.dark)
} }
.labelsHidden()
.pickerStyle(.segmented) .pickerStyle(.segmented)
}
Divider()
HStack {
Text("accent.title").font(.headline)
Spacer()
Picker("accent.title", selection: $preferences.accent) { Picker("accent.title", selection: $preferences.accent) {
Text("accent.system").tag(AccentChoice.system) Text("accent.system").tag(AccentChoice.system)
Text("accent.blue").tag(AccentChoice.blue) Text("accent.blue").tag(AccentChoice.blue)
@@ -35,31 +88,84 @@ struct AppearanceSettingsView: View {
Text("accent.pink").tag(AccentChoice.pink) Text("accent.pink").tag(AccentChoice.pink)
Text("accent.custom").tag(AccentChoice.custom) Text("accent.custom").tag(AccentChoice.custom)
} }
if preferences.accent == .custom { .labelsHidden()
HStack { .fixedSize()
Text("accent.custom") .buttonStyle(.glass)
Spacer() }
CustomColorWell(preferences: preferences, picker: colorPicker) if preferences.accent == .custom {
.frame(width: 44, height: 26) 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<Content: View>(@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"
}
}
} }
@@ -4,18 +4,25 @@ import AppKit
/// Keep the app discoverable while its settings window is open, including reopen. /// Keep the app discoverable while its settings window is open, including reopen.
struct SettingsWindowLifecycle: NSViewRepresentable { struct SettingsWindowLifecycle: NSViewRepresentable {
var title: String var title: String
var requestID: UInt64 = 0
var onClose: () -> Void = {} var onClose: () -> Void = {}
func makeNSView(context: Context) -> WindowObserverView { WindowObserverView() } func makeNSView(context: Context) -> WindowObserverView { WindowObserverView() }
func updateNSView(_ nsView: WindowObserverView, context: Context) { func updateNSView(_ nsView: WindowObserverView, context: Context) {
nsView.onClose = onClose nsView.onClose = onClose
nsView.title = title nsView.title = title
nsView.requestID = requestID
} }
final class WindowObserverView: NSView { final class WindowObserverView: NSView {
override func hitTest(_ point: NSPoint) -> NSView? { nil } override func hitTest(_ point: NSPoint) -> NSView? { nil }
var onClose: () -> Void = {} var onClose: () -> Void = {}
var title = "" { didSet { window?.title = title } } var title = "" { didSet { window?.title = title } }
var requestID: UInt64 = 0 {
didSet { if oldValue != requestID { schedulePresentation() } }
}
private var presentationTask: Task<Void, Never>?
private var needsPresentation = false
private var tokens: [NSObjectProtocol] = [] private var tokens: [NSObjectProtocol] = []
override func viewDidMoveToWindow() { override func viewDidMoveToWindow() {
@@ -24,6 +31,17 @@ struct SettingsWindowLifecycle: NSViewRepresentable {
tokens.removeAll() tokens.removeAll()
guard let window else { return } guard let window else { return }
window.title = title 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, tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.didBecomeKeyNotification,
object: window, queue: .main) { _ in object: window, queue: .main) { _ in
MainActor.assumeIsolated { MainActor.assumeIsolated {
@@ -33,12 +51,36 @@ struct SettingsWindowLifecycle: NSViewRepresentable {
tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification, tokens.append(NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification,
object: window, queue: .main) { [weak self] _ in object: window, queue: .main) { [weak self] _ in
MainActor.assumeIsolated { MainActor.assumeIsolated {
self?.presentationTask?.cancel()
self?.needsPresentation = false
self?.onClose() self?.onClose()
NSApp.setActivationPolicy(.accessory) 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) } }
} }
} }
+88
View File
@@ -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" "version": "1.0"
+13
View File
@@ -95,3 +95,16 @@ swiftc -module-cache-path /private/tmp/kymo-check-cache \
``` ```
检查真实 IOKit 请求的创建、重复开关与生命周期释放;测试结束不保留唤醒断言。不能替代实际空闲锁屏、息屏及面板视觉验收。 检查真实 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` 启动。检查首次展示、焦点恢复、隐藏重开、最小化恢复、普通窗口层级及关闭生命周期;不替代实际多窗口场景与视觉验收。
+59
View File
@@ -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))
}
}