refactor(settings): 改用常规关于选项卡并统一蓝色强调色
This commit is contained in:
@@ -70,14 +70,13 @@ GPU 通过 IOAccelerator 的 PerformanceStatistics / Device Utilization % 读取
|
|||||||
- NetworkPathObserver 从系统路径的偏好首位接口提供默认接口名称([NWPath 接口按偏好排序](https://developer.apple.com/documentation/network/nwpath)),网络卡默认直接展示该接口的 IPv4,若无则展示 IPv6;未知不随意选择另一个接口。手动切换接口时同步展示该接口地址。getifaddrs 元数据、接口速率和路径状态仍独立采集;不把接口 IP 当作公网出口地址。
|
- NetworkPathObserver 从系统路径的偏好首位接口提供默认接口名称([NWPath 接口按偏好排序](https://developer.apple.com/documentation/network/nwpath)),网络卡默认直接展示该接口的 IPv4,若无则展示 IPv6;未知不随意选择另一个接口。手动切换接口时同步展示该接口地址。getifaddrs 元数据、接口速率和路径状态仍独立采集;不把接口 IP 当作公网出口地址。
|
||||||
- 进程表支持 CPU/内存(RSS)排序、名称/PID/路径搜索、同卡内选中路径展示/复制与读取覆盖计数。投影按采样/筛选/排序事件计算并缓存,不在 body 或滚动中重复排序;hover、搜索/焦点和选中冻结旧身份顺序,新增项追加到其后。完整路径在表下方同卡展示以保持固定行高;选中进程退出短暂提示后移除,关闭面板拆卸表并清掉路径状态。路径不持久化,不收集参数或环境变量。
|
- 进程表支持 CPU/内存(RSS)排序、名称/PID/路径搜索、同卡内选中路径展示/复制与读取覆盖计数。投影按采样/筛选/排序事件计算并缓存,不在 body 或滚动中重复排序;hover、搜索/焦点和选中冻结旧身份顺序,新增项追加到其后。完整路径在表下方同卡展示以保持固定行高;选中进程退出短暂提示后移除,关闭面板拆卸表并清掉路径状态。路径不持久化,不收集参数或环境变量。
|
||||||
- 旧 MetricRow / HoverDetailPresenter / DetailPlacement 与旧迷你趋势源码暂保留作迁移参照,正式面板已无调用;待真实 UI 回归后在 P6 清理并同步其历史检查程序,不能把源码存在理解为仍有双套交互。
|
- 旧 MetricRow / HoverDetailPresenter / DetailPlacement 与旧迷你趋势源码暂保留作迁移参照,正式面板已无调用;待真实 UI 回归后在 P6 清理并同步其历史检查程序,不能把源码存在理解为仍有双套交互。
|
||||||
- `AppearancePreferences` 仅依赖 Foundation / Observation,持久化外观、系统/六种预设/自选 RGB 强调色。UI 层 `AppearanceStyle` 将偏好映射为明确的深/浅色及窗口级 NSAppearance / Color。跟随系统从全局偏好 AppleInterfaceStyle 独立解析,监听系统主题通知及 NSApp effectiveAppearance 变化后刷新;为 SwiftUI 同时提供非 nil 的 preferredColorScheme 与 colorScheme 环境,避免返回 nil 和失焦后重新继承窗口残留模式。用户持久化值仍为 system,App 全局 appearance 不被修改。该系统偏好键/主题通知属于平台约定,系统动态切换仍需实机验证;外观覆盖作用于面板与设置,不作用于菜单栏标签。
|
- `AppearancePreferences` 仅依赖 Foundation / Observation,仅持久化外观,UI 交互强调色固定蓝色,旧 accent/RGB 存储值不再读取或写入。UI 层 `AppearanceStyle` 将偏好映射为明确的深/浅色及窗口级 NSAppearance / Color。跟随系统从全局偏好 AppleInterfaceStyle 独立解析,监听系统主题通知及 NSApp effectiveAppearance 变化后刷新;为 SwiftUI 同时提供非 nil 的 preferredColorScheme 与 colorScheme 环境,避免返回 nil 和失焦后重新继承窗口残留模式。用户持久化值仍为 system,App 全局 appearance 不被修改。该系统偏好键/主题通知属于平台约定,系统动态切换仍需实机验证;外观覆盖作用于面板与设置,不作用于菜单栏标签。
|
||||||
- 设置页外观选择使用 `GlassEffectContainer`:外层为系统液态玻璃胶囊,选中态以共享 `glassEffectID` / `matchedGeometry` 的独立玻璃胶囊在三个选项间移动;遵循减少动态效果,其他表单仍使用系统分组与原生控件。
|
- 设置页外观选择使用 `GlassEffectContainer`:外层为系统液态玻璃胶囊,选中态以共享 `glassEffectID` / `matchedGeometry` 的独立玻璃胶囊在三个选项间移动;遵循减少动态效果,其他表单仍使用系统分组与原生控件。
|
||||||
- Settings 场景的 NavigationSplitView / Form 原生承载层在切换主题时可能保留旧环境,导致标题栏与表单深浅混用。设置页单独启用 AppearanceStyle.refreshContentOnChange,以解析后的 light/dark 为内容身份刷新承载子树;页面选择、偏好与色板控制器状态仍保留在外层 AppearanceSettingsView。跟随系统解析出新的主题时采用相同路径;面板不启用重建。选择器动画限定在控件内部,不用 withAnimation 包裹整个偏好变更;主题切换会重建控件,原有跨主题玻璃位移动画不保证连续。
|
- Settings 场景的 TabView / Form 原生承载层在切换主题时可能保留旧环境,导致标题栏与表单深浅混用。设置页单独启用 AppearanceStyle.refreshContentOnChange,以解析后的 light/dark 为内容身份刷新承载子树;选项卡选择与偏好状态仍保留在外层 AppearanceSettingsView。跟随系统解析出新的主题时采用相同路径;面板不启用重建。选择器动画限定在控件内部,不用 withAnimation 包裹整个偏好变更;主题切换会重建控件,原有跨主题玻璃位移动画不保证连续。
|
||||||
- `LanguagePreferences` 独立持久化 system / zh-Hans / zh-Hant / en,仅依赖 Foundation / Observation。App 将同一 locale 注入面板与设置,切换即时生效;系统模式按 Locale.preferredLanguages 匹配已支持语言,无法匹配回退 en,不修改 AppleLanguages。外侧详情的独立 NSHostingView 显式转发 locale;UI 的 AppLocalization 为原生窗口标题与色块辅助标签查找对应 lproj,避免其沿用进程启动语言。系统菜单与 NSColorPanel 的系统文案由 macOS 管理。语言自称保留原文。
|
- `LanguagePreferences` 独立持久化 system / zh-Hans / zh-Hant / en,仅依赖 Foundation / Observation。App 将同一 locale 注入面板与设置,切换即时生效;系统模式按 Locale.preferredLanguages 匹配已支持语言,无法匹配回退 en,不修改 AppleLanguages。外侧详情的独立 NSHostingView 显式转发 locale;UI 的 AppLocalization 为原生窗口标题等文案查找对应 lproj,避免其沿用进程启动语言。系统菜单的系统文案由 macOS 管理。语言自称保留原文。
|
||||||
- App 注入同一个偏好仓库,注册独立 Settings 场景;设置采用 `NavigationSplitView` 侧边栏与系统式分组 `Form`,分为外观、语言、监控、关于。窗口、侧边栏和控件遵循 macOS 设置页的原生材质与层级,不在内容区叠加整块自绘液态玻璃卡片;关于页展示品牌图标和 Bundle 实际版本,不写死版本号。
|
- App 注入同一个偏好仓库,注册独立 Settings 场景;设置采用原生顶部 `TabView`,分为常规、关于;常规的分组 `Form` 集中外观、语言、后台刷新间隔。窗口、选项卡和控件遵循 macOS 设置页的原生材质与层级,不在内容区叠加整块自绘液态玻璃卡片;关于页展示品牌图标和 Bundle 实际版本,不写死版本号。
|
||||||
- App 持有一个与 UI 无关的 `SettingsPresentation` 请求状态,并向 MenuBar 与 Settings 注入同一实例。菜单入口先切换 `.regular`,递增请求并调用 `openSettings`;设置窗口观察器在请求变化时取消旧任务、等待 SwiftUI 排序后激活应用、将窗口置前并清除最小化。只使用普通窗口层级,不永久置顶;活动应用通知补充处理激活竞态,隐藏后重开与最小化恢复走同一路径。窗口关闭时恢复 `.accessory`,保留 `LSUIElement=true` 的默认无 Dock 行为。
|
- App 持有一个与 UI 无关的 `SettingsPresentation` 请求状态,并向 MenuBar 与 Settings 注入同一实例。菜单入口先切换 `.regular`,递增请求并调用 `openSettings`;设置窗口观察器在请求变化时取消旧任务、等待 SwiftUI 排序后激活应用、将窗口置前并清除最小化。只使用普通窗口层级,不永久置顶;活动应用通知补充处理激活竞态,隐藏后重开与最小化恢复走同一路径。窗口关闭时恢复 `.accessory`,保留 `LSUIElement=true` 的默认无 Dock 行为。
|
||||||
- 品牌图标由用户提供的 dashboard-3-fill.svg 仪表盘路径派生:菜单栏 `BrandMark` 使用 18/36/54 px 透明模板 PNG,随明暗菜单栏系统着色;AppIcon 全尺寸与关于页 `BrandLogo` 使用覆盖整张画布的不透明白色背景及原深灰图形。Dock/Finder 使用 AppIcon 资源,不增加自绘 Dock 生命周期;系统负责最终圆角蒙版,避免透明边角触发额外的灰色底板。
|
- 品牌图标由用户提供的 dashboard-3-fill.svg 仪表盘路径派生:菜单栏 `BrandMark` 使用 18/36/54 px 透明模板 PNG,随明暗菜单栏系统着色;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;指标缩写、品牌、版本及单位保留通用写法。
|
- 用户文案集中在 `Resources/Localizable.xcstrings`,覆盖 en / zh-Hans / zh-Hant;指标缩写、品牌、版本及单位保留通用写法。
|
||||||
|
|
||||||
## 4. 并发模型
|
## 4. 并发模型
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# 设置页顶部选项卡重构
|
||||||
|
|
||||||
|
## 目标与范围
|
||||||
|
|
||||||
|
设置项数量较少,四项侧栏导航改为顶部“常规 / 关于”选项卡。常规集中外观、软件语言、后台刷新间隔;关于保留品牌、版本、描述。移除强调色选择、持久化读写及自定义颜色窗口,界面交互统一蓝色;资源监控图表的语义颜色不变。
|
||||||
|
|
||||||
|
涉及 App 场景现有装配、Features/Settings 页面与颜色控件、Features/MenuBar 激活状态色、UI/AppearanceStyle、Core/AppearancePreferences、三语资源及受影响的独立检查。依赖方向保持不变。
|
||||||
|
|
||||||
|
## 实施步骤
|
||||||
|
|
||||||
|
1. 使用原生顶部 TabView 承载两页,常规使用分组 Form,继续保持应用语言即时刷新及设置窗口生命周期。
|
||||||
|
2. 删除 AccentChoice、RGB 偏好和 CustomColorPicker/Well;忽略历史 accent 存储值,不删除用户历史数据;UI 固定使用蓝色。
|
||||||
|
3. 更新旧颜色检查、三语标签与架构文档,构建并使用隔离设置窗口实测选项卡、语言、主题、刷新间隔。
|
||||||
|
|
||||||
|
## 验证与风险
|
||||||
|
|
||||||
|
运行 Debug 构建、受影响的持久化和展示检查。检查旧强调色数据不影响外观持久化;不改变采样规则。隔离 suite 与独立测试 app 避免修改用户偏好或关闭已有应用。原生控件可能受系统强调色影响,需要检查主要交互色;液态玻璃质感、真实多屏体验交由用户验收。
|
||||||
|
|
||||||
|
## 进展
|
||||||
|
|
||||||
|
- 已完成前置代码、调用链及工作区检查;原有 Localizable.xcstrings 修改保留。
|
||||||
|
|
||||||
|
## 完成与验证
|
||||||
|
|
||||||
|
- 已完成原生顶部 TabView、常规页合并和关于页保留;删除强调色偏好、颜色窗口及色块组件,固定蓝色 tint 与 AccentColor 资源。
|
||||||
|
- Debug 构建、SamplingChecks(含旧 accent 数据存在时的外观持久化)、PresentationChecks、LocalizationChecks、197 条字符串完整性检查通过。
|
||||||
|
- 隔离 app 加载实际设置源码,实测常规/关于切换、深色主题、英文即时切换;截图复核英文排版,修复刷新间隔输入框多余标签。发现输入框保持焦点时步进值未同步文本,已让步进操作同步显示值,最终修改经构建验证。
|
||||||
|
- 系统原生控件/玻璃材质的主观体验及系统强调色自定义环境仍待用户验收;未操作用户已有应用或偏好。
|
||||||
@@ -1,11 +1,20 @@
|
|||||||
{
|
{
|
||||||
"colors" : [
|
"colors": [
|
||||||
{
|
{
|
||||||
"idiom" : "universal"
|
"idiom": "universal",
|
||||||
|
"color": {
|
||||||
|
"color-space": "srgb",
|
||||||
|
"components": {
|
||||||
|
"alpha": "1.000",
|
||||||
|
"blue": "1.000",
|
||||||
|
"green": "0.478",
|
||||||
|
"red": "0.000"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info": {
|
||||||
"author" : "xcode",
|
"author": "xcode",
|
||||||
"version" : 1
|
"version": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,31 +6,13 @@ nonisolated enum AppAppearance: String, CaseIterable, Identifiable {
|
|||||||
var id: String { rawValue }
|
var id: String { rawValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
nonisolated enum AccentChoice: String, CaseIterable, Identifiable {
|
|
||||||
case system, blue, purple, teal, green, orange, pink, custom
|
|
||||||
var id: String { rawValue }
|
|
||||||
}
|
|
||||||
|
|
||||||
@MainActor @Observable
|
@MainActor @Observable
|
||||||
final class AppearancePreferences {
|
final class AppearancePreferences {
|
||||||
@ObservationIgnored private let defaults: UserDefaults
|
@ObservationIgnored private let defaults: UserDefaults
|
||||||
var appearance: AppAppearance { didSet { defaults.set(appearance.rawValue, forKey: "appearance") } }
|
var appearance: AppAppearance { didSet { defaults.set(appearance.rawValue, forKey: "appearance") } }
|
||||||
var accent: AccentChoice { didSet { defaults.set(accent.rawValue, forKey: "accent") } }
|
|
||||||
var red: Double { didSet { defaults.set(red, forKey: "accent.red") } }
|
|
||||||
var green: Double { didSet { defaults.set(green, forKey: "accent.green") } }
|
|
||||||
var blue: Double { didSet { defaults.set(blue, forKey: "accent.blue") } }
|
|
||||||
|
|
||||||
init(defaults: UserDefaults = .standard) {
|
init(defaults: UserDefaults = .standard) {
|
||||||
self.defaults = defaults
|
self.defaults = defaults
|
||||||
appearance = AppAppearance(rawValue: defaults.string(forKey: "appearance") ?? "") ?? .system
|
appearance = AppAppearance(rawValue: defaults.string(forKey: "appearance") ?? "") ?? .system
|
||||||
accent = AccentChoice(rawValue: defaults.string(forKey: "accent") ?? "") ?? .system
|
|
||||||
red = Self.component(defaults.object(forKey: "accent.red"), fallback: 0.2)
|
|
||||||
green = Self.component(defaults.object(forKey: "accent.green"), fallback: 0.5)
|
|
||||||
blue = Self.component(defaults.object(forKey: "accent.blue"), fallback: 0.9)
|
|
||||||
}
|
|
||||||
|
|
||||||
private static func component(_ value: Any?, fallback: Double) -> Double {
|
|
||||||
guard let value = value as? Double, value.isFinite else { return fallback }
|
|
||||||
return min(1, max(0, value))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ struct MenuPanelView: View {
|
|||||||
Button { presentation.isPinned.toggle() } label: {
|
Button { presentation.isPinned.toggle() } label: {
|
||||||
Image(systemName: presentation.isPinned ? "pin.fill" : "pin")
|
Image(systemName: presentation.isPinned ? "pin.fill" : "pin")
|
||||||
.frame(width: 20, height: 20)
|
.frame(width: 20, height: 20)
|
||||||
.foregroundStyle(presentation.isPinned ? preferences.tintColor : Color.primary)
|
.foregroundStyle(presentation.isPinned ? Color.blue : Color.primary)
|
||||||
}
|
}
|
||||||
.help(Text(presentation.isPinned ? "panel.unpin" : "panel.pin"))
|
.help(Text(presentation.isPinned ? "panel.unpin" : "panel.pin"))
|
||||||
.accessibilityLabel(Text(presentation.isPinned ? "panel.unpin" : "panel.pin"))
|
.accessibilityLabel(Text(presentation.isPinned ? "panel.unpin" : "panel.pin"))
|
||||||
@@ -151,7 +151,7 @@ struct MenuPanelView: View {
|
|||||||
Button { keepAwake.toggle() } label: {
|
Button { keepAwake.toggle() } label: {
|
||||||
Image(systemName: keepAwake.isEnabled ? "cup.and.saucer.fill" : "cup.and.saucer")
|
Image(systemName: keepAwake.isEnabled ? "cup.and.saucer.fill" : "cup.and.saucer")
|
||||||
.frame(width: 20, height: 20)
|
.frame(width: 20, height: 20)
|
||||||
.foregroundStyle(keepAwake.isEnabled ? preferences.tintColor : Color.primary)
|
.foregroundStyle(keepAwake.isEnabled ? Color.blue : Color.primary)
|
||||||
}
|
}
|
||||||
.help(keepAwake.didFail ? Text("awake.failed") : (keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable")))
|
.help(keepAwake.didFail ? Text("awake.failed") : (keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable")))
|
||||||
.accessibilityLabel(keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable"))
|
.accessibilityLabel(keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable"))
|
||||||
|
|||||||
@@ -8,96 +8,30 @@ struct AppearanceSettingsView: View {
|
|||||||
@Bindable var sampling: SamplingPreferences
|
@Bindable var sampling: SamplingPreferences
|
||||||
let presentation: SettingsPresentation
|
let presentation: SettingsPresentation
|
||||||
@Environment(\.locale) private var locale
|
@Environment(\.locale) private var locale
|
||||||
@State private var colorPicker = CustomColorPicker()
|
@State private var selection = SettingsPage.general
|
||||||
@State private var selection: SettingsPage? = .appearance
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationSplitView {
|
TabView(selection: $selection) {
|
||||||
List(selection: $selection) {
|
generalPage
|
||||||
ForEach(SettingsPage.allCases) { page in
|
.tabItem { Label("settings.general", systemImage: "gearshape") }
|
||||||
Label(page.title, systemImage: page.symbol).tag(page)
|
.tag(SettingsPage.general)
|
||||||
}
|
aboutPage
|
||||||
}
|
.tabItem { Label("settings.about", systemImage: "info.circle") }
|
||||||
.listStyle(.sidebar)
|
.tag(SettingsPage.about)
|
||||||
.navigationSplitViewColumnWidth(min: 180, ideal: 205, max: 240)
|
|
||||||
} detail: {
|
|
||||||
Group {
|
|
||||||
switch selectedPage {
|
|
||||||
case .appearance: appearancePage
|
|
||||||
case .language: languagePage
|
|
||||||
case .monitoring: monitoringPage
|
|
||||||
case .about: aboutPage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.navigationTitle(selectedPage.title)
|
|
||||||
}
|
}
|
||||||
.navigationSplitViewStyle(.balanced)
|
.padding(12)
|
||||||
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale),
|
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale),
|
||||||
requestID: presentation.requestID,
|
requestID: presentation.requestID))
|
||||||
onClose: { colorPicker.close() }))
|
.frame(minWidth: 600, idealWidth: 640, minHeight: 420, idealHeight: 460)
|
||||||
.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: 720, idealWidth: 780, minHeight: 460, idealHeight: 540)
|
|
||||||
.modifier(AppearanceStyle(preferences: preferences, refreshContentOnChange: true))
|
.modifier(AppearanceStyle(preferences: preferences, refreshContentOnChange: true))
|
||||||
}
|
}
|
||||||
|
|
||||||
private var selectedPage: SettingsPage { selection ?? .appearance }
|
private var generalPage: some View {
|
||||||
|
|
||||||
private var appearancePage: some View {
|
|
||||||
Form {
|
Form {
|
||||||
Section {
|
Section {
|
||||||
LabeledContent("appearance.title") {
|
LabeledContent("appearance.title") {
|
||||||
LiquidAppearancePicker(selection: $preferences.appearance)
|
LiquidAppearancePicker(selection: $preferences.appearance)
|
||||||
}
|
}
|
||||||
LabeledContent("accent.title") {
|
|
||||||
Picker("accent.title", selection: $preferences.accent) {
|
|
||||||
Text("accent.system").tag(AccentChoice.system)
|
|
||||||
Text("accent.blue").tag(AccentChoice.blue)
|
|
||||||
Text("accent.purple").tag(AccentChoice.purple)
|
|
||||||
Text("accent.teal").tag(AccentChoice.teal)
|
|
||||||
Text("accent.green").tag(AccentChoice.green)
|
|
||||||
Text("accent.orange").tag(AccentChoice.orange)
|
|
||||||
Text("accent.pink").tag(AccentChoice.pink)
|
|
||||||
Text("accent.custom").tag(AccentChoice.custom)
|
|
||||||
}
|
|
||||||
.labelsHidden()
|
|
||||||
.fixedSize()
|
|
||||||
}
|
|
||||||
if preferences.accent == .custom {
|
|
||||||
LabeledContent("accent.custom") {
|
|
||||||
CustomColorWell(preferences: preferences, picker: colorPicker)
|
|
||||||
.frame(width: 44, height: 26)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.formStyle(.grouped)
|
|
||||||
.padding(.horizontal, 12)
|
|
||||||
.padding(.top, 6)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var monitoringPage: some View {
|
|
||||||
Form {
|
|
||||||
Section {
|
|
||||||
LabeledContent("sampling.background") {
|
|
||||||
IntervalControl(milliseconds: $sampling.backgroundMilliseconds)
|
|
||||||
}
|
|
||||||
Text("sampling.backgroundHelp").font(.callout).foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
}.formStyle(.grouped).padding(.horizontal, 12).padding(.top, 6)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var languagePage: some View {
|
|
||||||
Form {
|
|
||||||
Section {
|
|
||||||
LabeledContent("language.title") {
|
LabeledContent("language.title") {
|
||||||
Picker("language.title", selection: $language.language) {
|
Picker("language.title", selection: $language.language) {
|
||||||
Text("language.system").tag(AppLanguage.system)
|
Text("language.system").tag(AppLanguage.system)
|
||||||
@@ -108,14 +42,15 @@ struct AppearanceSettingsView: View {
|
|||||||
.labelsHidden()
|
.labelsHidden()
|
||||||
.fixedSize()
|
.fixedSize()
|
||||||
}
|
}
|
||||||
Text("language.immediate")
|
}
|
||||||
.font(.callout)
|
Section {
|
||||||
.foregroundStyle(.secondary)
|
LabeledContent("sampling.background") {
|
||||||
|
IntervalControl(milliseconds: $sampling.backgroundMilliseconds)
|
||||||
|
}
|
||||||
|
Text("sampling.backgroundHelp").font(.callout).foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.formStyle(.grouped)
|
.formStyle(.grouped)
|
||||||
.padding(.horizontal, 12)
|
|
||||||
.padding(.top, 6)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var aboutPage: some View {
|
private var aboutPage: some View {
|
||||||
@@ -164,7 +99,7 @@ private struct LiquidAppearancePicker: View {
|
|||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
ForEach(AppAppearance.allCases) { appearance in
|
ForEach(AppAppearance.allCases) { appearance in
|
||||||
Button {
|
Button {
|
||||||
// Theme changes must not animate the native split view / Form hierarchy.
|
// Theme changes must not animate the native tab view / Form hierarchy.
|
||||||
selection = appearance
|
selection = appearance
|
||||||
} label: {
|
} label: {
|
||||||
Label(appearance.title, systemImage: appearance.symbol)
|
Label(appearance.title, systemImage: appearance.symbol)
|
||||||
@@ -215,23 +150,6 @@ private extension AppAppearance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum SettingsPage: String, CaseIterable, Identifiable {
|
private enum SettingsPage: Hashable {
|
||||||
case appearance, language, monitoring, about
|
case general, about
|
||||||
var id: String { rawValue }
|
|
||||||
var title: LocalizedStringKey {
|
|
||||||
switch self {
|
|
||||||
case .appearance: "settings.appearance"
|
|
||||||
case .language: "settings.language"
|
|
||||||
case .monitoring: "settings.monitoring"
|
|
||||||
case .about: "settings.about"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var symbol: String {
|
|
||||||
switch self {
|
|
||||||
case .appearance: "paintpalette"
|
|
||||||
case .language: "globe"
|
|
||||||
case .monitoring: "timer"
|
|
||||||
case .about: "info.circle"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
import AppKit
|
|
||||||
import OSLog
|
|
||||||
|
|
||||||
@MainActor final class CustomColorPicker: NSObject {
|
|
||||||
private let logger = Logger(subsystem: "cn.airnan.kymo", category: "color-picker")
|
|
||||||
private static weak var owner: CustomColorPicker?
|
|
||||||
private var preferences: AppearancePreferences?
|
|
||||||
|
|
||||||
func show(for preferences: AppearancePreferences) {
|
|
||||||
logger.info("Custom color panel requested")
|
|
||||||
Self.owner = self
|
|
||||||
self.preferences = preferences
|
|
||||||
let panel = NSColorPanel.shared
|
|
||||||
panel.appearance = preferences.appearance.windowAppearance
|
|
||||||
panel.showsAlpha = false
|
|
||||||
panel.isContinuous = true
|
|
||||||
panel.color = NSColor(srgbRed: preferences.red, green: preferences.green,
|
|
||||||
blue: preferences.blue, alpha: 1)
|
|
||||||
panel.setTarget(self)
|
|
||||||
panel.setAction(#selector(colorChanged(_:)))
|
|
||||||
NSApp.activate()
|
|
||||||
panel.level = .floating
|
|
||||||
panel.makeKeyAndOrderFront(nil)
|
|
||||||
panel.orderFrontRegardless()
|
|
||||||
logger.info("Custom color panel visible: \(panel.isVisible, privacy: .public)")
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func colorChanged(_ sender: NSColorPanel) {
|
|
||||||
guard let preferences, let rgb = sender.color.usingColorSpace(.sRGB) else { return }
|
|
||||||
preferences.red = rgb.redComponent
|
|
||||||
preferences.green = rgb.greenComponent
|
|
||||||
preferences.blue = rgb.blueComponent
|
|
||||||
}
|
|
||||||
|
|
||||||
func close() {
|
|
||||||
guard Self.owner === self else { return }
|
|
||||||
NSColorPanel.shared.setTarget(nil)
|
|
||||||
NSColorPanel.shared.setAction(nil)
|
|
||||||
NSColorPanel.shared.close()
|
|
||||||
preferences = nil
|
|
||||||
Self.owner = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import AppKit
|
|
||||||
|
|
||||||
/// A native hit target avoids Form/plain-Button hit-testing ambiguity on the swatch.
|
|
||||||
struct CustomColorWell: NSViewRepresentable {
|
|
||||||
let preferences: AppearancePreferences
|
|
||||||
let picker: CustomColorPicker
|
|
||||||
@Environment(\.locale) private var locale
|
|
||||||
|
|
||||||
func makeNSView(context: Context) -> SwatchButton {
|
|
||||||
let button = SwatchButton()
|
|
||||||
return button
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateNSView(_ button: SwatchButton, context: Context) {
|
|
||||||
button.setAccessibilityLabel(AppLocalization.string("accent.custom", locale: locale))
|
|
||||||
button.open = { picker.show(for: preferences) }
|
|
||||||
button.swatchColor = NSColor(srgbRed: preferences.red, green: preferences.green, blue: preferences.blue, alpha: 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sizeThatFits(_ proposal: ProposedViewSize, nsView: SwatchButton, context: Context) -> CGSize? {
|
|
||||||
CGSize(width: 44, height: 26)
|
|
||||||
}
|
|
||||||
|
|
||||||
final class SwatchButton: NSButton {
|
|
||||||
var swatchColor = NSColor.systemBlue { didSet { needsDisplay = true } }
|
|
||||||
override var intrinsicContentSize: NSSize { NSSize(width: 44, height: 26) }
|
|
||||||
|
|
||||||
override func draw(_ dirtyRect: NSRect) {
|
|
||||||
// Draw the actual RGB color inside bounds; no scalable SF Symbol/cell image.
|
|
||||||
let shape = NSBezierPath(roundedRect: bounds.insetBy(dx: 4, dy: 4), xRadius: 4, yRadius: 4)
|
|
||||||
(isHighlighted ? swatchColor.withAlphaComponent(0.7) : swatchColor).setFill()
|
|
||||||
shape.fill()
|
|
||||||
NSColor.separatorColor.setStroke()
|
|
||||||
shape.lineWidth = 1
|
|
||||||
shape.stroke()
|
|
||||||
}
|
|
||||||
|
|
||||||
var open: () -> Void = {}
|
|
||||||
override init(frame frameRect: NSRect) {
|
|
||||||
super.init(frame: frameRect)
|
|
||||||
bezelStyle = .rounded
|
|
||||||
isBordered = false
|
|
||||||
wantsLayer = true
|
|
||||||
layer?.masksToBounds = true
|
|
||||||
title = ""
|
|
||||||
target = self
|
|
||||||
action = #selector(openPicker)
|
|
||||||
}
|
|
||||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
||||||
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
|
|
||||||
@objc func openPicker() { open() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -133,213 +133,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"accent.blue" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Blue"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "蓝色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "藍色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.custom" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Custom color"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "自选颜色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "自選顏色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.green" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Green"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "绿色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "綠色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.orange" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Orange"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "橙色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "橘色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.pink" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Pink"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "粉色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "粉紅色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.purple" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Purple"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "紫色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "紫色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.system" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "System accent"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "系统强调色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "系統強調色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.teal" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Teal"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "青色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "青色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accent.title" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Accent color"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "强调色"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "強調色"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"action.closeWindow" : {
|
"action.closeWindow" : {
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@@ -4295,6 +4088,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"settings.general" : {
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "General"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "常规"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hant" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "一般"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version" : "1.0"
|
"version" : "1.0"
|
||||||
|
|||||||
@@ -16,21 +16,6 @@ extension AppAppearance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AppearancePreferences {
|
|
||||||
var tintColor: Color {
|
|
||||||
switch accent {
|
|
||||||
case .system: .accentColor
|
|
||||||
case .blue: .blue
|
|
||||||
case .purple: .purple
|
|
||||||
case .teal: .teal
|
|
||||||
case .green: .green
|
|
||||||
case .orange: .orange
|
|
||||||
case .pink: .pink
|
|
||||||
case .custom: Color(red: red, green: green, blue: blue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct AppearanceStyle: ViewModifier {
|
struct AppearanceStyle: ViewModifier {
|
||||||
let preferences: AppearancePreferences
|
let preferences: AppearancePreferences
|
||||||
var refreshContentOnChange = false
|
var refreshContentOnChange = false
|
||||||
@@ -39,13 +24,13 @@ struct AppearanceStyle: ViewModifier {
|
|||||||
private var scheme: ColorScheme { resolved == .dark ? .dark : .light }
|
private var scheme: ColorScheme { resolved == .dark ? .dark : .light }
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
content
|
content
|
||||||
// Settings split-view hosts can retain their previous native appearance.
|
// Settings native hosts can retain their previous native appearance.
|
||||||
// Keep state in the owning view, but replace the hosted subtree on a resolved theme change.
|
// Keep state in the owning view, but replace the hosted subtree on a resolved theme change.
|
||||||
.id(refreshContentOnChange ? resolved : nil)
|
.id(refreshContentOnChange ? resolved : nil)
|
||||||
.background(WindowAppearanceBridge(choice: resolved))
|
.background(WindowAppearanceBridge(choice: resolved))
|
||||||
.preferredColorScheme(scheme)
|
.preferredColorScheme(scheme)
|
||||||
.environment(\.colorScheme, scheme)
|
.environment(\.colorScheme, scheme)
|
||||||
.tint(preferences.tintColor)
|
.tint(.blue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ struct IntervalControl: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(spacing: 3) {
|
HStack(spacing: 3) {
|
||||||
TextField("sampling.seconds", text: $text)
|
TextField("sampling.seconds", text: $text)
|
||||||
|
.labelsHidden()
|
||||||
.textFieldStyle(.roundedBorder).multilineTextAlignment(.trailing)
|
.textFieldStyle(.roundedBorder).multilineTextAlignment(.trailing)
|
||||||
.frame(width: 64).focused($focused)
|
.frame(width: 64).focused($focused)
|
||||||
.onChange(of: text) { _, value in
|
.onChange(of: text) { _, value in
|
||||||
@@ -21,7 +22,10 @@ struct IntervalControl: View {
|
|||||||
}
|
}
|
||||||
.onSubmit { commit() }
|
.onSubmit { commit() }
|
||||||
Text("sampling.unit").foregroundStyle(.secondary).fixedSize()
|
Text("sampling.unit").foregroundStyle(.secondary).fixedSize()
|
||||||
Stepper("sampling.interval", value: $milliseconds, in: range, step: step).labelsHidden().fixedSize()
|
Stepper("sampling.interval", value: Binding(get: { milliseconds }, set: {
|
||||||
|
milliseconds = $0
|
||||||
|
synchronize()
|
||||||
|
}), in: range, step: step).labelsHidden().fixedSize()
|
||||||
}
|
}
|
||||||
.font(.system(size: 11)).monospacedDigit().controlSize(.small)
|
.font(.system(size: 11)).monospacedDigit().controlSize(.small)
|
||||||
.fixedSize(horizontal: true, vertical: false)
|
.fixedSize(horizontal: true, vertical: false)
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ import Foundation
|
|||||||
defaults.set("unsupported", forKey: "language")
|
defaults.set("unsupported", forKey: "language")
|
||||||
precondition(LanguagePreferences(defaults: defaults).language == .system)
|
precondition(LanguagePreferences(defaults: defaults).language == .system)
|
||||||
let bundle = Bundle(path: CommandLine.arguments[1])!
|
let bundle = Bundle(path: CommandLine.arguments[1])!
|
||||||
for (language, title, custom) in [("en", "Kymo Settings", "Custom color"),
|
for (language, title, general) in [("en", "Kymo Settings", "General"),
|
||||||
("zh-Hans", "Kymo 设置", "自选颜色"),
|
("zh-Hans", "Kymo 设置", "常规"),
|
||||||
("zh-Hant", "Kymo 設定", "自選顏色")] {
|
("zh-Hant", "Kymo 設定", "一般")] {
|
||||||
let locale = Locale(identifier: language)
|
let locale = Locale(identifier: language)
|
||||||
precondition(AppLocalization.string("settings.title", locale: locale, bundle: bundle) == title)
|
precondition(AppLocalization.string("settings.title", locale: locale, bundle: bundle) == title)
|
||||||
precondition(AppLocalization.string("accent.custom", locale: locale, bundle: bundle) == custom)
|
precondition(AppLocalization.string("settings.general", locale: locale, bundle: bundle) == general)
|
||||||
for (table, key) in [("StatusItem", "status.open"), ("Process", "copyPID"), ("CPUDetails", "cpu.kind.efficiency")] {
|
for (table, key) in [("StatusItem", "status.open"), ("Process", "copyPID"), ("CPUDetails", "cpu.kind.efficiency")] {
|
||||||
let value = AppLocalization.string(key, locale: locale, bundle: bundle, table: table)
|
let value = AppLocalization.string(key, locale: locale, bundle: bundle, table: table)
|
||||||
precondition(!value.isEmpty && value != key, "Missing built translation: \(language)/\(table)/\(key)")
|
precondition(!value.isEmpty && value != key, "Missing built translation: \(language)/\(table)/\(key)")
|
||||||
|
|||||||
@@ -28,27 +28,6 @@ import CoreGraphics
|
|||||||
precondition(SystemAppearanceObserver.isDark(globalDomain: ["AppleInterfaceStyle": "Dark"]))
|
precondition(SystemAppearanceObserver.isDark(globalDomain: ["AppleInterfaceStyle": "Dark"]))
|
||||||
precondition(!SystemAppearanceObserver.isDark(globalDomain: [:]))
|
precondition(!SystemAppearanceObserver.isDark(globalDomain: [:]))
|
||||||
_ = NSApplication.shared
|
_ = NSApplication.shared
|
||||||
let swatch = CustomColorWell.SwatchButton(frame: CGRect(x: 0, y: 0, width: 44, height: 26))
|
|
||||||
var clicked = false
|
|
||||||
swatch.open = { clicked = true }
|
|
||||||
precondition(swatch.acceptsFirstMouse(for: nil))
|
|
||||||
swatch.performClick(nil)
|
|
||||||
precondition(clicked)
|
|
||||||
swatch.swatchColor = NSColor(srgbRed: 0.2, green: 0.5, blue: 0.9, alpha: 1)
|
|
||||||
let bitmap = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: 44, pixelsHigh: 26,
|
|
||||||
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true,
|
|
||||||
isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!
|
|
||||||
NSGraphicsContext.saveGraphicsState()
|
|
||||||
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: bitmap)
|
|
||||||
NSColor.clear.setFill()
|
|
||||||
swatch.bounds.fill(using: .copy)
|
|
||||||
swatch.draw(swatch.bounds)
|
|
||||||
NSGraphicsContext.restoreGraphicsState()
|
|
||||||
let center = bitmap.colorAt(x: 22, y: 13)!.usingColorSpace(.sRGB)!
|
|
||||||
precondition(abs(center.redComponent - 0.2) < 0.02)
|
|
||||||
precondition(abs(center.greenComponent - 0.5) < 0.02)
|
|
||||||
precondition(abs(center.blueComponent - 0.9) < 0.02)
|
|
||||||
precondition(bitmap.colorAt(x: 0, y: 0)!.alphaComponent == 0)
|
|
||||||
let global = NSApp.appearance
|
let global = NSApp.appearance
|
||||||
let window = NSWindow(contentRect: .zero, styleMask: .borderless, backing: .buffered, defer: true)
|
let window = NSWindow(contentRect: .zero, styleMask: .borderless, backing: .buffered, defer: true)
|
||||||
window.isReleasedWhenClosed = false
|
window.isReleasedWhenClosed = false
|
||||||
@@ -63,6 +42,6 @@ import CoreGraphics
|
|||||||
precondition(NSApp.appearance === global)
|
precondition(NSApp.appearance === global)
|
||||||
}
|
}
|
||||||
window.close()
|
window.close()
|
||||||
print("PASS: outward placement, edge fallback, negative screen origins, vertical limits, explicit/system window appearance reset, independent system resolution, native swatch target/action")
|
print("PASS: outward placement, edge fallback, negative screen origins, vertical limits, explicit/system window appearance reset, independent system resolution")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ swiftc -module-cache-path /private/tmp/kymo-check-cache \
|
|||||||
kymo/Core/Services/AppearancePreferences.swift kymo/Core/Services/LanguagePreferences.swift \
|
kymo/Core/Services/AppearancePreferences.swift kymo/Core/Services/LanguagePreferences.swift \
|
||||||
kymo/UI/Components/AppearanceStyle.swift kymo/UI/Components/DetailPlacement.swift \
|
kymo/UI/Components/AppearanceStyle.swift kymo/UI/Components/DetailPlacement.swift \
|
||||||
kymo/UI/Components/AppLocalization.swift \
|
kymo/UI/Components/AppLocalization.swift \
|
||||||
kymo/Features/Settings/CustomColorPicker.swift kymo/Features/Settings/CustomColorWell.swift \
|
|
||||||
kymoTests/PresentationChecks.swift -o /private/tmp/kymo-presentation-checks
|
kymoTests/PresentationChecks.swift -o /private/tmp/kymo-presentation-checks
|
||||||
/private/tmp/kymo-presentation-checks
|
/private/tmp/kymo-presentation-checks
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -69,16 +69,16 @@ import Foundation
|
|||||||
let defaults = UserDefaults(suiteName: suite)!
|
let defaults = UserDefaults(suiteName: suite)!
|
||||||
defer { defaults.removePersistentDomain(forName: suite) }
|
defer { defaults.removePersistentDomain(forName: suite) }
|
||||||
let preferences = AppearancePreferences(defaults: defaults)
|
let preferences = AppearancePreferences(defaults: defaults)
|
||||||
precondition(preferences.appearance == .system && preferences.accent == .system)
|
precondition(preferences.appearance == .system)
|
||||||
preferences.appearance = .dark
|
preferences.appearance = .dark
|
||||||
preferences.accent = .custom
|
defaults.set("custom", forKey: "accent")
|
||||||
preferences.red = 0.75
|
defaults.set(0.75, forKey: "accent.red")
|
||||||
let restored = AppearancePreferences(defaults: defaults)
|
let restored = AppearancePreferences(defaults: defaults)
|
||||||
precondition(restored.appearance == .dark && restored.accent == .custom && restored.red == 0.75)
|
precondition(restored.appearance == .dark)
|
||||||
defaults.set("invalid", forKey: "appearance")
|
defaults.set("invalid", forKey: "appearance")
|
||||||
defaults.set(2.0, forKey: "accent.red")
|
defaults.set(2.0, forKey: "accent.red")
|
||||||
let recovered = AppearancePreferences(defaults: defaults)
|
let recovered = AppearancePreferences(defaults: defaults)
|
||||||
precondition(recovered.appearance == .system && recovered.red == 1)
|
precondition(recovered.appearance == .system)
|
||||||
print("PASS: bounded history, missing samples, format boundaries, appearance persistence and invalid defaults")
|
print("PASS: bounded history, missing samples, format boundaries, appearance persistence and invalid defaults")
|
||||||
let sampler = SystemSampler()
|
let sampler = SystemSampler()
|
||||||
let initial = await sampler.sample()
|
let initial = await sampler.sample()
|
||||||
|
|||||||
Reference in New Issue
Block a user