@@ -13,31 +13,31 @@ public enum ColorSchemePreference: String, CaseIterable, Identifiable {
13
13
case system
14
14
case light
15
15
case dark
16
-
16
+
17
17
public var id : Self { self }
18
18
}
19
19
20
20
/// Settings pane
21
21
struct SettingsView : View {
22
22
let updater : SPUUpdater
23
-
23
+
24
24
var body : some View {
25
25
TabView {
26
26
GeneralSettingsView ( )
27
27
. tabItem {
28
28
Label ( " General " , systemImage: " gearshape " )
29
29
}
30
-
30
+
31
31
BrewPathView ( )
32
32
. tabItem {
33
33
Label ( " Brew Path " , systemImage: " mug " )
34
34
}
35
-
35
+
36
36
UpdateSettingsView ( updater: updater)
37
37
. tabItem {
38
38
Label ( " Updates " , systemImage: " arrow.clockwise " )
39
39
}
40
-
40
+
41
41
UninstallView ( )
42
42
. tabItem {
43
43
Label ( " Uninstall " , systemImage: " trash " )
@@ -53,38 +53,36 @@ struct SettingsView: View {
53
53
NSApp . keyWindow? . makeFirstResponder ( nil )
54
54
}
55
55
}
56
- . frame ( width: 400 , height : 260 )
56
+ . frame ( width: 400 )
57
57
}
58
58
}
59
59
60
60
fileprivate struct GeneralSettingsView : View {
61
61
@AppStorage ( " colorSchemePreference " ) var colorSchemePreference : ColorSchemePreference = . system
62
62
@AppStorage ( " notificationSuccess " ) var notificationOnSuccess : Bool = false
63
63
@AppStorage ( " notificationFailure " ) var notificationOnFailure : Bool = true
64
-
64
+
65
65
var body : some View {
66
66
VStack ( alignment: . leading) {
67
67
Text ( " Appearance " )
68
68
. bold ( )
69
-
69
+
70
70
Picker ( " Color Scheme: " , selection: $colorSchemePreference) {
71
-
71
+
72
72
ForEach ( ColorSchemePreference . allCases) { color in
73
73
Text ( NSLocalizedString ( color. rawValue. capitalized, comment: " Colors schemes names " ) )
74
74
}
75
75
}
76
76
. pickerStyle ( . segmented)
77
-
77
+
78
78
Divider ( )
79
79
. padding ( . vertical)
80
-
80
+
81
81
Text ( " Notifications " )
82
82
. bold ( )
83
83
84
84
Toggle ( " Task completions " , isOn: $notificationOnSuccess)
85
85
Toggle ( " Task errors " , isOn: $notificationOnFailure)
86
-
87
- Spacer ( )
88
86
}
89
87
. padding ( )
90
88
}
@@ -93,84 +91,84 @@ fileprivate struct GeneralSettingsView: View {
93
91
fileprivate struct BrewPathView : View {
94
92
@AppStorage ( " customUserBrewPath " ) var customUserBrewPath : String = " /opt/homebrew/bin/brew "
95
93
@AppStorage ( " brewPathOption " ) var brewPathOption = BrewPaths . PathOption. appPath. rawValue
96
-
94
+
97
95
@State var isSelectedBrewPathValid = false
98
-
96
+
99
97
/// Brew installation option before making changes
100
98
@State var previousBrewOption : Int = 0
101
-
99
+
102
100
var body : some View {
103
101
VStack {
104
102
Text ( " Brew Executable Path " )
105
103
. bold ( )
106
-
104
+
107
105
BrewPathSelectorView ( isSelectedPathValid: $isSelectedBrewPathValid)
108
- . padding ( . bottom, 4 )
109
-
106
+
110
107
Text ( " Currently selected brew path is invalid " )
111
108
. foregroundColor ( . red)
112
109
. opacity ( isSelectedBrewPathValid ? 0 : 1 )
113
-
110
+
114
111
if previousBrewOption != brewPathOption && isSelectedBrewPathValid {
115
112
Text ( " Brew path has been modified. Restart app for changes to take effect. " )
116
113
. foregroundColor ( . red)
117
-
114
+
118
115
Button ( " Relaunch " , role: . destructive) {
119
116
Task {
120
117
await shell ( " /usr/bin/osascript -e 'tell application \" \( Bundle . main. appName) \" to quit' && sleep 2 && open \" /Applications/ \( Bundle . main. appName) .app \" " )
121
118
}
122
119
}
123
120
}
124
121
}
125
- . padding ( )
126
122
. onAppear {
127
123
previousBrewOption = BrewPaths . selectedBrewOption. rawValue
128
124
}
125
+ . padding ( )
129
126
}
130
127
}
131
128
132
129
fileprivate struct UpdateSettingsView : View {
133
130
private let updater : SPUUpdater
134
-
131
+
135
132
@State private var automaticallyChecksForUpdates : Bool
136
133
@State private var automaticallyDownloadsUpdates : Bool
137
-
134
+
138
135
init ( updater: SPUUpdater ) {
139
136
self . updater = updater
140
137
self . automaticallyChecksForUpdates = updater. automaticallyChecksForUpdates
141
138
self . automaticallyDownloadsUpdates = updater. automaticallyDownloadsUpdates
142
139
}
143
-
140
+
144
141
var body : some View {
145
142
VStack {
146
143
CheckForUpdatesView ( updater: updater) {
147
144
Label ( " Check for Updates... " , systemImage: " arrow.uturn.down " )
148
145
}
149
-
146
+
150
147
Text ( " Current app version: \( Bundle . main. version) ( \( Bundle . main. buildNumber) ) " )
151
148
. font ( . system( . body, weight: . light) )
152
149
. foregroundColor ( . secondary)
153
-
150
+
154
151
Spacer ( )
155
- . frame ( height: 30 )
156
-
152
+ . frame ( height: 20 )
153
+
157
154
Toggle ( " Automatically check for updates " , isOn: $automaticallyChecksForUpdates)
158
155
. onChange ( of: automaticallyChecksForUpdates) { newValue in
159
156
updater. automaticallyChecksForUpdates = newValue
160
157
}
161
-
158
+
162
159
Toggle ( " Automatically download updates " , isOn: $automaticallyDownloadsUpdates)
163
160
. disabled ( !automaticallyChecksForUpdates)
164
161
. onChange ( of: automaticallyDownloadsUpdates) { newValue in
165
162
updater. automaticallyDownloadsUpdates = newValue
166
163
}
167
- } . padding ( )
164
+ }
165
+ . padding ( )
168
166
}
169
167
}
170
168
171
169
fileprivate struct UninstallView : View {
172
170
@Environment ( \. openWindow) var openWindow
173
-
171
+
174
172
var body : some View {
175
173
VStack ( alignment: . center) {
176
174
Button ( role: . destructive) {
@@ -179,9 +177,9 @@ fileprivate struct UninstallView: View {
179
177
Label ( " Uninstall " , systemImage: " trash.fill " )
180
178
}
181
179
. bigButton ( foregroundColor: . white, backgroundColor: . red)
182
-
180
+
183
181
Text ( " Uninstall \( Bundle . main. appName) , related files and cache. " )
184
- }
182
+ } . padding ( )
185
183
}
186
184
}
187
185
0 commit comments