fix(menubar): 修复清理构建状态项并增加液态外观选择
This commit is contained in:
@@ -1,25 +1,5 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MenuBarLabel: View {
|
||||
let snapshot: MetricsSnapshot
|
||||
|
||||
var body: some View {
|
||||
// Use one native image/title label: the previous multi-view HStack showed
|
||||
// only its first image and percentage in the user-verified menu bar.
|
||||
Label {
|
||||
Text(verbatim: title)
|
||||
.monospacedDigit()
|
||||
} icon: {
|
||||
Image("BrandMark")
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 18, height: 18)
|
||||
}
|
||||
.labelStyle(.titleAndIcon)
|
||||
}
|
||||
|
||||
private var title: String {
|
||||
enum MenuBarLabel {
|
||||
static func title(for snapshot: MetricsSnapshot) -> String {
|
||||
var items = ["CPU \(MetricFormat.percent(snapshot.cpu?.usage))"]
|
||||
if let gpu = snapshot.gpuUsage {
|
||||
items.append("GPU \(MetricFormat.percent(gpu))")
|
||||
|
||||
@@ -53,14 +53,7 @@ struct AppearanceSettingsView: View {
|
||||
Form {
|
||||
Section {
|
||||
LabeledContent("appearance.title") {
|
||||
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)
|
||||
.fixedSize()
|
||||
LiquidAppearancePicker(selection: $preferences.appearance)
|
||||
}
|
||||
LabeledContent("accent.title") {
|
||||
Picker("accent.title", selection: $preferences.accent) {
|
||||
@@ -148,6 +141,71 @@ struct AppearanceSettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private struct LiquidAppearancePicker: View {
|
||||
@Binding var selection: AppAppearance
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@Namespace private var selectionNamespace
|
||||
|
||||
var body: some View {
|
||||
GlassEffectContainer(spacing: 10) {
|
||||
HStack(spacing: 4) {
|
||||
ForEach(AppAppearance.allCases) { appearance in
|
||||
Button {
|
||||
if reduceMotion {
|
||||
selection = appearance
|
||||
} else {
|
||||
withAnimation(.smooth(duration: 0.24)) {
|
||||
selection = appearance
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label(appearance.title, systemImage: appearance.symbol)
|
||||
.labelStyle(.titleAndIcon)
|
||||
.font(.system(size: 13, weight: .medium))
|
||||
.foregroundStyle(selection == appearance ? .primary : .secondary)
|
||||
.padding(.horizontal, 11)
|
||||
.frame(minWidth: 108, minHeight: 34)
|
||||
.contentShape(.capsule)
|
||||
.background {
|
||||
if selection == appearance {
|
||||
Capsule()
|
||||
.fill(.clear)
|
||||
.glassEffect(.regular.interactive(), in: .capsule)
|
||||
.glassEffectID("appearance-selection", in: selectionNamespace)
|
||||
.glassEffectTransition(.matchedGeometry)
|
||||
}
|
||||
}
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityAddTraits(selection == appearance ? .isSelected : [])
|
||||
}
|
||||
}
|
||||
.padding(4)
|
||||
.glassEffect(.regular, in: .capsule)
|
||||
}
|
||||
.accessibilityElement(children: .contain)
|
||||
.accessibilityLabel(Text("appearance.title"))
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppAppearance {
|
||||
var title: LocalizedStringKey {
|
||||
switch self {
|
||||
case .system: "appearance.system"
|
||||
case .light: "appearance.light"
|
||||
case .dark: "appearance.dark"
|
||||
}
|
||||
}
|
||||
|
||||
var symbol: String {
|
||||
switch self {
|
||||
case .system: "circle.lefthalf.filled"
|
||||
case .light: "sun.max.fill"
|
||||
case .dark: "moon.fill"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum SettingsPage: String, CaseIterable, Identifiable {
|
||||
case appearance, language, about
|
||||
var id: String { rawValue }
|
||||
|
||||
Reference in New Issue
Block a user