diff --git a/Cork/ContentView.swift b/Cork/ContentView.swift index eef89ea5..246cd770 100644 --- a/Cork/ContentView.swift +++ b/Cork/ContentView.swift @@ -24,7 +24,7 @@ struct ContentView: View, Sendable @Default(.discoverabilityDaySpan) var discoverabilityDaySpan: DiscoverabilityDaySpans @Default(.sortTopPackagesBy) var sortTopPackagesBy - @AppStorage("customHomebrewPath") var customHomebrewPath: String = "" + @Default(.customHomebrewPath) var customHomebrewPath: URL? @Environment(\.openWindow) var openWindow: OpenWindowAction @@ -236,7 +236,7 @@ private extension View { AppConstants.shared.logger.debug("Brew executable path: \(AppConstants.shared.brewExecutablePath, privacy: .public)") - if !view.customHomebrewPath.isEmpty && !FileManager.default.fileExists(atPath: AppConstants.shared.brewExecutablePath.path) + if view.customHomebrewPath != nil && !FileManager.default.fileExists(atPath: AppConstants.shared.brewExecutablePath.path) { view.appState.showAlert(errorToShow: .customBrewExcutableGotDeleted) } @@ -594,7 +594,7 @@ private extension View case .customBrewExcutableGotDeleted: Button { - view.customHomebrewPath = "" + view.customHomebrewPath = nil } label: { Text("action.reset-custom-brew-executable") } diff --git a/Cork/Views/Settings/Panes/Sub-Views/Brew Pane/Custom Homebrew Executable View.swift b/Cork/Views/Settings/Panes/Sub-Views/Brew Pane/Custom Homebrew Executable View.swift index 7625d366..7efd72f0 100644 --- a/Cork/Views/Settings/Panes/Sub-Views/Brew Pane/Custom Homebrew Executable View.swift +++ b/Cork/Views/Settings/Panes/Sub-Views/Brew Pane/Custom Homebrew Executable View.swift @@ -7,10 +7,11 @@ import SwiftUI import CorkShared +import Defaults struct CustomHomebrewExecutableView: View { - @AppStorage("customHomebrewPath") var customHomebrewPath: String = "" + @Default(.customHomebrewPath) var customHomebrewPath: URL? @AppStorage("allowAdvancedHomebrewSettings") var allowAdvancedHomebrewSettings: Bool = false @EnvironmentObject var settingsState: SettingsState @@ -45,11 +46,11 @@ struct CustomHomebrewExecutableView: View Text("settings.brew.custom-homebrew-path.select") } - if !customHomebrewPath.isEmpty + if customHomebrewPath != nil { Button { - customHomebrewPath = "" + customHomebrewPath = nil } label: { Text("settings.brew.custom-homebrew-path.reset") } @@ -65,9 +66,9 @@ struct CustomHomebrewExecutableView: View .onChange(of: allowAdvancedHomebrewSettings, perform: { newValue in if newValue == false { - if !customHomebrewPath.isEmpty + if customHomebrewPath != nil { - customHomebrewPath = "" + customHomebrewPath = nil } } }) @@ -82,9 +83,15 @@ struct CustomHomebrewExecutableView: View case .success(let success): if success.first!.lastPathComponent == "brew" { - AppConstants.shared.logger.info("Valid brew executable: \(success.first!.path)") - - customHomebrewPath = success.first!.path + guard let selectedCustomHomebrewPath = success.first else + { + AppConstants.shared.logger.error("Failed while getting selected custom Homebrew executable") + return + } + + AppConstants.shared.logger.info("Valid brew executable: \(selectedCustomHomebrewPath.path)") + + customHomebrewPath = selectedCustomHomebrewPath } else { diff --git a/Modules/Shared/Defaults/Settings/Homebrew Settings.swift b/Modules/Shared/Defaults/Settings/Homebrew Settings.swift index 9a36e3ba..71fa17df 100644 --- a/Modules/Shared/Defaults/Settings/Homebrew Settings.swift +++ b/Modules/Shared/Defaults/Settings/Homebrew Settings.swift @@ -13,4 +13,7 @@ public extension Defaults.Keys // MARK: - Analytics /// Whether to allow anonymous Homebrew analytics static let allowBrewAnalytics: Key = .init("allowBrewAnalytics", default: true) + + // MARK: - Developer settings + static let customHomebrewPath: Key = .init("customHomebrewPath", default: nil) }