~ Custom Homebrew paths → @Defaults

This commit is contained in:
David Bureš 2025-05-16 23:12:10 +02:00
parent 459e2c6a47
commit 0fbdc8fa72
No known key found for this signature in database
3 changed files with 21 additions and 11 deletions

View File

@ -24,7 +24,7 @@ struct ContentView: View, Sendable
@Default(.discoverabilityDaySpan) var discoverabilityDaySpan: DiscoverabilityDaySpans @Default(.discoverabilityDaySpan) var discoverabilityDaySpan: DiscoverabilityDaySpans
@Default(.sortTopPackagesBy) var sortTopPackagesBy @Default(.sortTopPackagesBy) var sortTopPackagesBy
@AppStorage("customHomebrewPath") var customHomebrewPath: String = "" @Default(.customHomebrewPath) var customHomebrewPath: URL?
@Environment(\.openWindow) var openWindow: OpenWindowAction @Environment(\.openWindow) var openWindow: OpenWindowAction
@ -236,7 +236,7 @@ private extension View
{ {
AppConstants.shared.logger.debug("Brew executable path: \(AppConstants.shared.brewExecutablePath, privacy: .public)") 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) view.appState.showAlert(errorToShow: .customBrewExcutableGotDeleted)
} }
@ -594,7 +594,7 @@ private extension View
case .customBrewExcutableGotDeleted: case .customBrewExcutableGotDeleted:
Button Button
{ {
view.customHomebrewPath = "" view.customHomebrewPath = nil
} label: { } label: {
Text("action.reset-custom-brew-executable") Text("action.reset-custom-brew-executable")
} }

View File

@ -7,10 +7,11 @@
import SwiftUI import SwiftUI
import CorkShared import CorkShared
import Defaults
struct CustomHomebrewExecutableView: View struct CustomHomebrewExecutableView: View
{ {
@AppStorage("customHomebrewPath") var customHomebrewPath: String = "" @Default(.customHomebrewPath) var customHomebrewPath: URL?
@AppStorage("allowAdvancedHomebrewSettings") var allowAdvancedHomebrewSettings: Bool = false @AppStorage("allowAdvancedHomebrewSettings") var allowAdvancedHomebrewSettings: Bool = false
@EnvironmentObject var settingsState: SettingsState @EnvironmentObject var settingsState: SettingsState
@ -45,11 +46,11 @@ struct CustomHomebrewExecutableView: View
Text("settings.brew.custom-homebrew-path.select") Text("settings.brew.custom-homebrew-path.select")
} }
if !customHomebrewPath.isEmpty if customHomebrewPath != nil
{ {
Button Button
{ {
customHomebrewPath = "" customHomebrewPath = nil
} label: { } label: {
Text("settings.brew.custom-homebrew-path.reset") Text("settings.brew.custom-homebrew-path.reset")
} }
@ -65,9 +66,9 @@ struct CustomHomebrewExecutableView: View
.onChange(of: allowAdvancedHomebrewSettings, perform: { newValue in .onChange(of: allowAdvancedHomebrewSettings, perform: { newValue in
if newValue == false if newValue == false
{ {
if !customHomebrewPath.isEmpty if customHomebrewPath != nil
{ {
customHomebrewPath = "" customHomebrewPath = nil
} }
} }
}) })
@ -82,9 +83,15 @@ struct CustomHomebrewExecutableView: View
case .success(let success): case .success(let success):
if success.first!.lastPathComponent == "brew" if success.first!.lastPathComponent == "brew"
{ {
AppConstants.shared.logger.info("Valid brew executable: \(success.first!.path)") guard let selectedCustomHomebrewPath = success.first else
{
AppConstants.shared.logger.error("Failed while getting selected custom Homebrew executable")
return
}
customHomebrewPath = success.first!.path AppConstants.shared.logger.info("Valid brew executable: \(selectedCustomHomebrewPath.path)")
customHomebrewPath = selectedCustomHomebrewPath
} }
else else
{ {

View File

@ -13,4 +13,7 @@ public extension Defaults.Keys
// MARK: - Analytics // MARK: - Analytics
/// Whether to allow anonymous Homebrew analytics /// Whether to allow anonymous Homebrew analytics
static let allowBrewAnalytics: Key<Bool> = .init("allowBrewAnalytics", default: true) static let allowBrewAnalytics: Key<Bool> = .init("allowBrewAnalytics", default: true)
// MARK: - Developer settings
static let customHomebrewPath: Key<URL?> = .init("customHomebrewPath", default: nil)
} }