Skip to content

Commit

Permalink
Allow setting default location for Bottles
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jan 12, 2024
1 parent e3b607b commit e038cad
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Whisky/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -11061,6 +11061,16 @@
}
}
},
"settings.path" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Default bottle path:"
}
}
}
},
"settings.toggle.gptk.updates" : {
"localizations" : {
"da" : {
Expand Down
2 changes: 1 addition & 1 deletion Whisky/Views/Bottle/BottleCreationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct BottleCreationView: View {

@State private var newBottleName: String = ""
@State private var newBottleVersion: WinVersion = .win10
@State private var newBottleURL: URL = BottleData.defaultBottleDir
@State private var newBottleURL: URL = UserDefaults.standard.url(forKey: "defaultBottleLocation") ?? BottleData.defaultBottleDir

Check failure on line 27 in Whisky/Views/Bottle/BottleCreationView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 132 characters (line_length)
@State private var bottlePath: String = ""
@State private var nameValid: Bool = false

Expand Down
44 changes: 44 additions & 0 deletions Whisky/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,50 @@
//

import SwiftUI
import WhiskyKit

struct SettingsView: View {
@AppStorage("SUEnableAutomaticChecks") var whiskyUpdate = true
@AppStorage("killOnTerminate") var killOnTerminate = true
@AppStorage("checkGPTKUpdates") var checkGPTKUpdates = true
@AppStorage("defaultBottleLocation") var defaultBottleLocation = BottleData.defaultBottleDir

@State private var bottlePath: String = ""

var body: some View {
Form {
Section("settings.general") {
Toggle("settings.toggle.kill.on.terminate", isOn: $killOnTerminate)
HStack {
VStack(alignment: .leading) {
Text("settings.path")
.foregroundStyle(.primary)
Text(bottlePath)
.foregroundStyle(.secondary)
.truncationMode(.middle)
.lineLimit(2)
.help(bottlePath)
}

Spacer()
Button {
let panel = NSOpenPanel()
panel.canChooseFiles = false
panel.canChooseDirectories = true
panel.allowsMultipleSelection = false
panel.canCreateDirectories = true
panel.directoryURL = BottleData.containerDir
panel.begin { result in
if result == .OK {
if let url = panel.urls.first {
defaultBottleLocation = url
}
}
}
} label: {
Text("create.browse")
}
}
}
Section("settings.updates") {
Toggle("settings.toggle.whisky.updates", isOn: $whiskyUpdate)
Expand All @@ -35,5 +69,15 @@ struct SettingsView: View {
}
.formStyle(.grouped)
.frame(width: 500, height: 250)
.onChange(of: defaultBottleLocation) {
bottlePath = defaultBottleLocation.prettyPath()
}
.onAppear {
bottlePath = defaultBottleLocation.prettyPath()
}
}
}

#Preview {
SettingsView()
}

0 comments on commit e038cad

Please sign in to comment.