From e038cad2c80cce0b00f735e51a3194f5860391d1 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 12 Jan 2024 12:18:16 -0500 Subject: [PATCH] Allow setting default location for Bottles --- Whisky/Localizable.xcstrings | 10 +++++ Whisky/Views/Bottle/BottleCreationView.swift | 2 +- Whisky/Views/Settings/SettingsView.swift | 44 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Whisky/Localizable.xcstrings b/Whisky/Localizable.xcstrings index a3cd00e1..7af11a19 100644 --- a/Whisky/Localizable.xcstrings +++ b/Whisky/Localizable.xcstrings @@ -11061,6 +11061,16 @@ } } }, + "settings.path" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Default bottle path:" + } + } + } + }, "settings.toggle.gptk.updates" : { "localizations" : { "da" : { diff --git a/Whisky/Views/Bottle/BottleCreationView.swift b/Whisky/Views/Bottle/BottleCreationView.swift index 75afc64c..67d270a0 100644 --- a/Whisky/Views/Bottle/BottleCreationView.swift +++ b/Whisky/Views/Bottle/BottleCreationView.swift @@ -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 @State private var bottlePath: String = "" @State private var nameValid: Bool = false diff --git a/Whisky/Views/Settings/SettingsView.swift b/Whisky/Views/Settings/SettingsView.swift index bba25430..d2b2d5d0 100644 --- a/Whisky/Views/Settings/SettingsView.swift +++ b/Whisky/Views/Settings/SettingsView.swift @@ -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) @@ -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() +}