Skip to content

Commit 8dc576c

Browse files
authored
Merge pull request #25 from stonerl/settings
Slight adjustments to the settings window
2 parents d33d7cd + 3d0d25c commit 8dc576c

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

Applite/Components/BrewPathSelectorView.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,36 @@ import SwiftUI
1010
/// Provides a picker so the user can select the brew executable path they want to use
1111
struct BrewPathSelectorView: View {
1212
@Binding var isSelectedPathValid: Bool
13-
13+
1414
@StateObject var customBrewPathDebounced = DebounceObject()
15-
15+
1616
@AppStorage("customUserBrewPath") var customUserBrewPath: String = BrewPaths.getBrewExectuablePath(for: .defaultAppleSilicon, shellFriendly: false)
1717
@AppStorage("brewPathOption") var brewPathOption = BrewPaths.PathOption.defaultAppleSilicon.rawValue
18-
19-
private func getPathDesctiption(for option: BrewPaths.PathOption) -> String {
18+
19+
private func getPathDescription(for option: BrewPaths.PathOption) -> String {
2020
switch option {
2121
case .appPath:
2222
return "\(Bundle.main.appName)'s installation"
23-
23+
2424
case .defaultAppleSilicon:
25-
return "Apple Silicon mac"
26-
25+
return "Apple Silicon Mac"
26+
2727
case .defaultIntel:
28-
return "Intel mac"
29-
28+
return "Intel Mac"
29+
3030
case .custom:
3131
return ""
3232
}
3333
}
34-
34+
3535
var body: some View {
3636
VStack(alignment: .leading) {
3737
Picker("", selection: $brewPathOption) {
3838
ForEach(BrewPaths.PathOption.allCases) { option in
3939
if option != .custom {
4040
HStack {
41-
Text("\(BrewPaths.getBrewExectuablePath(for: option, shellFriendly: false)) (\(getPathDesctiption(for: option)))")
42-
.truncationMode(.middle)
43-
41+
Text("\(getPathDescription(for: option))")
42+
Text("(\(BrewPaths.getBrewExectuablePath(for: option, shellFriendly: false)))").truncationMode(.middle).lineLimit(1).foregroundColor(.gray)
4443
if option.rawValue == brewPathOption {
4544
if isSelectedPathValid {
4645
Image(systemName: "checkmark.circle")
@@ -58,7 +57,7 @@ struct BrewPathSelectorView: View {
5857
VStack(alignment: .leading, spacing: 5) {
5958
HStack {
6059
Text("Custom")
61-
60+
6261
if option.rawValue == brewPathOption {
6362
if isSelectedPathValid {
6463
Image(systemName: "checkmark.circle")
@@ -71,7 +70,7 @@ struct BrewPathSelectorView: View {
7170
}
7271
}
7372
}
74-
73+
7574
TextField("Custom brew path", text: $customBrewPathDebounced.text, prompt: Text("/path/to/brew"))
7675
.textFieldStyle(.roundedBorder)
7776
.frame(maxWidth: 300)
@@ -93,7 +92,7 @@ struct BrewPathSelectorView: View {
9392
}
9493
.onChange(of: customBrewPathDebounced.debouncedText) { newPath in
9594
customUserBrewPath = newPath
96-
95+
9796
if brewPathOption == BrewPaths.PathOption.custom.rawValue {
9897
isSelectedPathValid = isBrewPathValid(path: newPath)
9998
}

Applite/Views/SettingsView.swift

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ public enum ColorSchemePreference: String, CaseIterable, Identifiable {
1313
case system
1414
case light
1515
case dark
16-
16+
1717
public var id: Self { self }
1818
}
1919

2020
/// Settings pane
2121
struct SettingsView: View {
2222
let updater: SPUUpdater
23-
23+
2424
var body: some View {
2525
TabView {
2626
GeneralSettingsView()
2727
.tabItem {
2828
Label("General", systemImage: "gearshape")
2929
}
30-
30+
3131
BrewPathView()
3232
.tabItem {
3333
Label("Brew Path", systemImage: "mug")
3434
}
35-
35+
3636
UpdateSettingsView(updater: updater)
3737
.tabItem {
3838
Label("Updates", systemImage: "arrow.clockwise")
3939
}
40-
40+
4141
UninstallView()
4242
.tabItem {
4343
Label("Uninstall", systemImage: "trash")
@@ -53,38 +53,36 @@ struct SettingsView: View {
5353
NSApp.keyWindow?.makeFirstResponder(nil)
5454
}
5555
}
56-
.frame(width: 400, height: 260)
56+
.frame(width: 400)
5757
}
5858
}
5959

6060
fileprivate struct GeneralSettingsView: View {
6161
@AppStorage("colorSchemePreference") var colorSchemePreference: ColorSchemePreference = .system
6262
@AppStorage("notificationSuccess") var notificationOnSuccess: Bool = false
6363
@AppStorage("notificationFailure") var notificationOnFailure: Bool = true
64-
64+
6565
var body: some View {
6666
VStack(alignment: .leading) {
6767
Text("Appearance")
6868
.bold()
69-
69+
7070
Picker("Color Scheme:", selection: $colorSchemePreference) {
71-
71+
7272
ForEach(ColorSchemePreference.allCases) { color in
7373
Text(NSLocalizedString(color.rawValue.capitalized, comment: "Colors schemes names"))
7474
}
7575
}
7676
.pickerStyle(.segmented)
77-
77+
7878
Divider()
7979
.padding(.vertical)
80-
80+
8181
Text("Notifications")
8282
.bold()
8383

8484
Toggle("Task completions", isOn: $notificationOnSuccess)
8585
Toggle("Task errors", isOn: $notificationOnFailure)
86-
87-
Spacer()
8886
}
8987
.padding()
9088
}
@@ -93,84 +91,84 @@ fileprivate struct GeneralSettingsView: View {
9391
fileprivate struct BrewPathView: View {
9492
@AppStorage("customUserBrewPath") var customUserBrewPath: String = "/opt/homebrew/bin/brew"
9593
@AppStorage("brewPathOption") var brewPathOption = BrewPaths.PathOption.appPath.rawValue
96-
94+
9795
@State var isSelectedBrewPathValid = false
98-
96+
9997
/// Brew installation option before making changes
10098
@State var previousBrewOption: Int = 0
101-
99+
102100
var body: some View {
103101
VStack {
104102
Text("Brew Executable Path")
105103
.bold()
106-
104+
107105
BrewPathSelectorView(isSelectedPathValid: $isSelectedBrewPathValid)
108-
.padding(.bottom, 4)
109-
106+
110107
Text("Currently selected brew path is invalid")
111108
.foregroundColor(.red)
112109
.opacity(isSelectedBrewPathValid ? 0 : 1)
113-
110+
114111
if previousBrewOption != brewPathOption && isSelectedBrewPathValid {
115112
Text("Brew path has been modified. Restart app for changes to take effect.")
116113
.foregroundColor(.red)
117-
114+
118115
Button("Relaunch", role: .destructive) {
119116
Task {
120117
await shell("/usr/bin/osascript -e 'tell application \"\(Bundle.main.appName)\" to quit' && sleep 2 && open \"/Applications/\(Bundle.main.appName).app\"")
121118
}
122119
}
123120
}
124121
}
125-
.padding()
126122
.onAppear {
127123
previousBrewOption = BrewPaths.selectedBrewOption.rawValue
128124
}
125+
.padding()
129126
}
130127
}
131128

132129
fileprivate struct UpdateSettingsView: View {
133130
private let updater: SPUUpdater
134-
131+
135132
@State private var automaticallyChecksForUpdates: Bool
136133
@State private var automaticallyDownloadsUpdates: Bool
137-
134+
138135
init(updater: SPUUpdater) {
139136
self.updater = updater
140137
self.automaticallyChecksForUpdates = updater.automaticallyChecksForUpdates
141138
self.automaticallyDownloadsUpdates = updater.automaticallyDownloadsUpdates
142139
}
143-
140+
144141
var body: some View {
145142
VStack {
146143
CheckForUpdatesView(updater: updater) {
147144
Label("Check for Updates...", systemImage: "arrow.uturn.down")
148145
}
149-
146+
150147
Text("Current app version: \(Bundle.main.version) (\(Bundle.main.buildNumber))")
151148
.font(.system(.body, weight: .light))
152149
.foregroundColor(.secondary)
153-
150+
154151
Spacer()
155-
.frame(height: 30)
156-
152+
.frame(height: 20)
153+
157154
Toggle("Automatically check for updates", isOn: $automaticallyChecksForUpdates)
158155
.onChange(of: automaticallyChecksForUpdates) { newValue in
159156
updater.automaticallyChecksForUpdates = newValue
160157
}
161-
158+
162159
Toggle("Automatically download updates", isOn: $automaticallyDownloadsUpdates)
163160
.disabled(!automaticallyChecksForUpdates)
164161
.onChange(of: automaticallyDownloadsUpdates) { newValue in
165162
updater.automaticallyDownloadsUpdates = newValue
166163
}
167-
}.padding()
164+
}
165+
.padding()
168166
}
169167
}
170168

171169
fileprivate struct UninstallView: View {
172170
@Environment(\.openWindow) var openWindow
173-
171+
174172
var body: some View {
175173
VStack(alignment: .center) {
176174
Button(role: .destructive) {
@@ -179,9 +177,9 @@ fileprivate struct UninstallView: View {
179177
Label("Uninstall", systemImage: "trash.fill")
180178
}
181179
.bigButton(foregroundColor: .white, backgroundColor: .red)
182-
180+
183181
Text("Uninstall \(Bundle.main.appName), related files and cache.")
184-
}
182+
}.padding()
185183
}
186184
}
187185

0 commit comments

Comments
 (0)