forked from nikitabobko/AeroSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperimentalUISettings.swift
More file actions
73 lines (67 loc) · 2.22 KB
/
ExperimentalUISettings.swift
File metadata and controls
73 lines (67 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import SwiftUI
struct ExperimentalUISettings {
var displayStyle: MenuBarStyle {
get {
if let value = UserDefaults.standard.string(forKey: ExperimentalUISettingsItems.displayStyle.rawValue) {
return MenuBarStyle(rawValue: value) ?? .monospacedText
} else {
return .monospacedText
}
}
set {
UserDefaults.standard.setValue(newValue.rawValue, forKey: ExperimentalUISettingsItems.displayStyle.rawValue)
UserDefaults.standard.synchronize()
}
}
}
enum MenuBarStyle: String, CaseIterable, Identifiable, Equatable, Hashable {
case monospacedText
case systemText
case squares
case i3
case i3Ordered
case i3OrderedWithAppIcons
var id: String { rawValue }
var title: String {
switch self {
case .monospacedText: "Monospaced font"
case .systemText: "System font"
case .squares: "Square images"
case .i3: "i3 style grouped"
case .i3Ordered: "i3 style ordered"
case .i3OrderedWithAppIcons: "i3 style ordered + app icons"
}
}
}
enum ExperimentalUISettingsItems: String {
case displayStyle
}
@MainActor
func getExperimentalUISettingsMenu(viewModel: TrayMenuModel) -> some View {
let color = AppearanceTheme.current == .dark ? Color.white : Color.black
return Menu {
Text("Menu bar style (macOS 14 or later):")
ForEach(MenuBarStyle.allCases, id: \.id) { style in
MenuBarStyleButton(style: style, color: color).environmentObject(viewModel)
}
} label: {
Text("Experimental UI Settings (No stability guarantees)")
}
}
@MainActor
struct MenuBarStyleButton: View {
@EnvironmentObject var viewModel: TrayMenuModel
let style: MenuBarStyle
let color: Color
var body: some View {
Button {
viewModel.experimentalUISettings.displayStyle = style
} label: {
Toggle(isOn: .constant(viewModel.experimentalUISettings.displayStyle == style)) {
MenuBarLabel(style: style, color: color)
.environmentObject(viewModel)
Text(" - " + style.title)
}
}
}
}