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
+5 -3
View File
@@ -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)
}
}
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" : [
{
"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
}
}
}
+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)
.monospacedDigit()
} icon: {
Image(systemName: "gauge")
Image("BrandMark")
.renderingMode(.template)
.resizable()
.scaledToFit()
.frame(width: 18, height: 18)
}
.labelStyle(.titleAndIcon)
}
+6 -1
View File
@@ -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"))
@@ -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<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.
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<Void, Never>?
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) } }
}
}
+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"