+ Observable defaults where appropriate

This commit is contained in:
David Bureš 2025-05-14 12:26:47 +02:00
parent b13ce91b52
commit 284cd52f53
No known key found for this signature in database
19 changed files with 168 additions and 85 deletions

View File

@ -11,14 +11,13 @@ import Foundation
import SwiftUI
import CorkShared
import Defaults
import DefaultsMacros
@Observable
class AppDelegate: NSObject, NSApplicationDelegate
{
@ObservableDefault(.showInMenuBar)
@ObservationIgnored
var showInMenuBar
@AppStorage("startWithoutWindow") var startWithoutWindow: Bool = false
@ObservableDefault(.showInMenuBar) @ObservationIgnored var showInMenuBar: Bool
@ObservableDefault(.startWithoutWindow) @ObservationIgnored var startWithoutWindow: Bool
@MainActor let appState: AppState = .init()

View File

@ -9,13 +9,12 @@ import Foundation
import SwiftUI
import CorkShared
import Defaults
import DefaultsMacros
@Observable @MainActor
class TopPackagesTracker
{
@ObservableDefault(.sortTopPackagesBy)
@ObservationIgnored
var sortTopPackagesBy
@ObservableDefault(.sortTopPackagesBy) @ObservationIgnored var sortTopPackagesBy: TopPackageSorting
var topFormulae: [BrewPackage] = .init()
var topCasks: [BrewPackage] = .init()

View File

@ -7,13 +7,15 @@
import Foundation
import SwiftUI
import Defaults
import DefaultsMacros
@Observable @MainActor
class OutdatedPackagesTracker
{
@ObservationIgnored @AppStorage("displayOnlyIntentionallyInstalledPackagesByDefault") var displayOnlyIntentionallyInstalledPackagesByDefault: Bool = true
@ObservableDefault(.displayOnlyIntentionallyInstalledPackagesByDefault) @ObservationIgnored var displayOnlyIntentionallyInstalledPackagesByDefault: Bool
@ObservationIgnored @AppStorage("includeGreedyOutdatedPackages") var includeGreedyOutdatedPackages: Bool = false
@ObservableDefault(.includeGreedyOutdatedPackages) @ObservationIgnored var includeGreedyOutdatedPackages: Bool
var outdatedPackages: Set<OutdatedPackage> = .init()
enum OutdatedPackageDisplayStage: Equatable

View File

@ -7,10 +7,11 @@
import CorkShared
import SwiftUI
import Defaults
struct MaintenanceFinishedView: View
{
@AppStorage("displayOnlyIntentionallyInstalledPackagesByDefault") var displayOnlyIntentionallyInstalledPackagesByDefault: Bool = true
@Default(.displayOnlyIntentionallyInstalledPackagesByDefault) var displayOnlyIntentionallyInstalledPackagesByDefault: Bool
@Environment(\.dismiss) var dismiss: DismissAction

View File

@ -38,7 +38,7 @@ struct OnboardingView: View
@AppStorage("enableRevealInFinder") var enableRevealInFinder: Bool = false
@AppStorage("displayOnlyIntentionallyInstalledPackagesByDefault") var displayOnlyIntentionallyInstalledPackagesByDefault: Bool = true
@Default(.displayOnlyIntentionallyInstalledPackagesByDefault) var displayOnlyIntentionallyInstalledPackagesByDefault: Bool
@AppStorage("outdatedPackageInfoDisplayAmount") var outdatedPackageInfoDisplayAmount: OutdatedPackageInfoAmount = .all
@AppStorage("showOldVersionsInOutdatedPackageList") var showOldVersionsInOutdatedPackageList: Bool = true

View File

@ -15,7 +15,7 @@ struct GeneralPane: View
@Default(.sortPackagesBy) var sortPackagesBy
@Default(.displayAdvancedDependencies) var displayAdvancedDependencies
@AppStorage("displayOnlyIntentionallyInstalledPackagesByDefault") var displayOnlyIntentionallyInstalledPackagesByDefault: Bool = true
@Default(.displayOnlyIntentionallyInstalledPackagesByDefault) var displayOnlyIntentionallyInstalledPackagesByDefault: Bool
@Default(.caveatDisplayOptions) var caveatDisplayOptions
@Default(.showDescriptionsInSearchResults) var showDescriptionsInSearchResults
@ -29,7 +29,7 @@ struct GeneralPane: View
@Default(.showSearchFieldForDependenciesInPackageDetails) var showSearchFieldForDependenciesInPackageDetails
@Default(.showInMenuBar) var showInMenuBar
@AppStorage("startWithoutWindow") var startWithoutWindow: Bool = false
@Default(.startWithoutWindow) var startWithoutWindow: Bool
@AppStorage("defaultBackupDateFormat") var defaultBackupDateFormat: Date.FormatStyle.DateStyle = .numeric

View File

@ -14,7 +14,7 @@ struct InstallationAndUninstallationPane: View
@AppStorage("shouldRequestPackageRemovalConfirmation") var shouldRequestPackageRemovalConfirmation: Bool = false
@Default(.showCompatibilityWarning) var showCompatibilityWarning
@AppStorage("includeGreedyOutdatedPackages") var includeGreedyOutdatedPackages: Bool = false
@Default(.includeGreedyOutdatedPackages) var includeGreedyOutdatedPackages: Bool
@AppStorage("showPackagesStillLeftToInstall") var showPackagesStillLeftToInstall: Bool = false

View File

@ -11,7 +11,7 @@ import Defaults
struct FormulaeSection: View
{
@AppStorage("displayOnlyIntentionallyInstalledPackagesByDefault") var displayOnlyIntentionallyInstalledPackagesByDefault: Bool = true
@Default(.displayOnlyIntentionallyInstalledPackagesByDefault) var displayOnlyIntentionallyInstalledPackagesByDefault: Bool
@Default(.sortPackagesBy) var sortPackagesBy
@Environment(AppState.self) var appState: AppState

View File

@ -6,6 +6,7 @@
//
import SwiftUI
import Defaults
struct OutdatedPackageListBox: View
{
@ -21,7 +22,7 @@ struct OutdatedPackageListBox: View
case unmanagedOnly
}
@AppStorage("displayOnlyIntentionallyInstalledPackagesByDefault") var displayOnlyIntentionallyInstalledPackagesByDefault: Bool = true
@Default(.displayOnlyIntentionallyInstalledPackagesByDefault) var displayOnlyIntentionallyInstalledPackagesByDefault: Bool
@AppStorage("outdatedPackageInfoDisplayAmount") var outdatedPackageInfoDisplayAmount: OutdatedPackageInfoAmount = .versionOnly
@Environment(AppState.self) var appState: AppState

View File

@ -7,10 +7,11 @@
import SwiftUI
import CorkShared
import Defaults
struct PackageAndTapOverviewBox: View
{
@AppStorage("displayOnlyIntentionallyInstalledPackagesByDefault") var displayOnlyIntentionallyInstalledPackagesByDefault: Bool = true
@Default(.displayOnlyIntentionallyInstalledPackagesByDefault) var displayOnlyIntentionallyInstalledPackagesByDefault: Bool
@Environment(BrewPackagesTracker.self) var brewPackagesTracker: BrewPackagesTracker
@Environment(TapTracker.self) var tapTracker: TapTracker

View File

@ -7,10 +7,11 @@
import SwiftUI
import CorkShared
import Defaults
struct UpdatingPackageTrackerStateView: View
{
@AppStorage("includeGreedyOutdatedPackages") var includeGreedyOutdatedPackages: Bool = false
@Default(.includeGreedyOutdatedPackages) var includeGreedyOutdatedPackages: Bool
@Environment(AppState.self) var appState: AppState
@Environment(OutdatedPackagesTracker.self) var outdatedPackagesTracker: OutdatedPackagesTracker

View File

@ -1,66 +0,0 @@
//
// Settings.swift
// CorkShared
//
// Created by David Bureš - P on 10.03.2025.
//
import Foundation
import Defaults
public extension Defaults.Keys
{
/// Sorting type of the installed packages in the sidebar
static let sortPackagesBy: Key<PackageSortingOptions> = .init("sortPackagesBy", default: .byInstallDate)
/// Whether to allow anonymous Homebrew analytics
static let allowBrewAnalytics: Key<Bool> = .init("allowBrewAnalytics", default: true)
/// Whether to allow purging
static let allowMoreCompleteUninstallations: Key<Bool> = .init("allowMoreCompleteUninstallations", default: false)
/// Whether to show live Terminal outputs of varous operations
static let showRealTimeTerminalOutputOfOperations: Key<Bool> = .init("showRealTimeTerminalOutputOfOperations", default: false)
/// Whether to show more info about a package's dependencies, including its version, and if it is a direct dependency
static let displayAdvancedDependencies: Key<Bool> = .init("displayAdvancedDependencies", default: false)
/// Whether to show a package's caveats as a pill, or as a full, separate section
static let caveatDisplayOptions: Key<PackageCaveatDisplay> = .init("caveatDisplayOptions", default: .full)
/// Whether descriptions of packages will be shown in the installer sheet
static let showDescriptionsInSearchResults: Key<Bool> = .init("showDescriptionsInSearchResults", default: false)
/// Whether the info setion about a package's dependencies shows a search field, which allows the searching for dependencies
static let showSearchFieldForDependenciesInPackageDetails: Key<Bool> = .init("showSearchFieldForDependenciesInPackageDetails", default: false)
/// Sorting type of top packages in the package installed
static let sortTopPackagesBy: Key<TopPackageSorting> = .init("sortTopPackagesBy", default: .mostDownloads)
/// Whether Cork's menu bar item is shown
static let showInMenuBar: Key<Bool> = .init("showInMenuBar", default: false)
// MARK: - Package Installation
/// Whether to warn about packages incompatible with the user's system
static let showCompatibilityWarning: Key<Bool> = .init("showCompatibilityWarning", default: true)
// MARK: - Notifications
/// Whether notifications are enabled
static let areNotificationsEnabled: Key<Bool> = .init("areNotificationsEnabled", default: true)
/// Type of notifications for outdated packages
/// Types:
/// - ``OutdatedPackageNotificationType.badge``: Only a badge in the app's icon
/// - ``OutdatedPackageNotificationType.both``: Badge, as well as a notification
static let outdatedPackageNotificationType: Key<OutdatedPackageNotificationType> = .init("outdatedPackageNotificationType", default: .badge)
/// Whether to send a notification about the results of a package updating action
static let notifyAboutPackageUpgradeResults: Key<Bool> = .init("notifyAboutPackageUpgradeResults", default: false)
/// Whether no send a notification about the results of a package installation action
static let notifyAboutPackageInstallationResults: Key<Bool> = .init("notifyAboutPackageInstallationResults", default: false)
// MARK: - Discoverability
/// Whether to enable top packages
static let enableDiscoverability: Key<Bool> = .init("enableDiscoverability", default: false)
}

View File

@ -0,0 +1,18 @@
//
// Discoverability Settings.swift
// Cork
//
// Created by David Bureš - P on 14.05.2025.
//
import Foundation
import Defaults
public extension Defaults.Keys
{
/// Whether to enable top packages
static let enableDiscoverability: Key<Bool> = .init("enableDiscoverability", default: false)
/// Sorting type of top packages in the package installed
static let sortTopPackagesBy: Key<TopPackageSorting> = .init("sortTopPackagesBy", default: .mostDownloads)
}

View File

@ -0,0 +1,45 @@
//
// General Settings.swift
// Cork
//
// Created by David Bureš - P on 14.05.2025.
//
import Foundation
import Defaults
public extension Defaults.Keys
{
// MARK: - Package Sorting
/// Sorting type of the installed packages in the sidebar
static let sortPackagesBy: Key<PackageSortingOptions> = .init("sortPackagesBy", default: .byInstallDate)
// MARK: - Package filtering
/// Whether to show only packages that the user installed manually
static let displayOnlyIntentionallyInstalledPackagesByDefault: Key<Bool> = .init("displayOnlyIntentionallyInstalledPackagesByDefault", default: true)
// MARK: - Dependencies
/// Whether to show more info about a package's dependencies, including its version, and if it is a direct dependency
static let displayAdvancedDependencies: Key<Bool> = .init("displayAdvancedDependencies", default: false)
// MARK: - Package caveats
/// Whether to show a package's caveats as a pill, or as a full, separate section
static let caveatDisplayOptions: Key<PackageCaveatDisplay> = .init("caveatDisplayOptions", default: .full)
// MARK: - Search results
/// Whether descriptions of packages will be shown in the installer sheet
static let showDescriptionsInSearchResults: Key<Bool> = .init("showDescriptionsInSearchResults", default: false)
// MARK: - Package details
/// Whether the info setion about a package's dependencies shows a search field, which allows the searching for dependencies
static let showSearchFieldForDependenciesInPackageDetails: Key<Bool> = .init("showSearchFieldForDependenciesInPackageDetails", default: false)
// MARK: - Menu bar
/// Whether Cork's menu bar item is shown
static let showInMenuBar: Key<Bool> = .init("showInMenuBar", default: false)
/// Whether the app should start without its window
/// Not implemented at the moment
static let startWithoutWindow: Key<Bool> = .init("startWithoutWindow", default: false)
}

View File

@ -0,0 +1,16 @@
//
// Homebrew Settings.swift
// Cork
//
// Created by David Bureš - P on 14.05.2025.
//
import Foundation
import Defaults
public extension Defaults.Keys
{
// MARK: - Analytics
/// Whether to allow anonymous Homebrew analytics
static let allowBrewAnalytics: Key<Bool> = .init("allowBrewAnalytics", default: true)
}

View File

@ -0,0 +1,8 @@
//
// Maintenance Settings.swift
// Cork
//
// Created by David Bureš - P on 14.05.2025.
//
import Foundation

View File

@ -0,0 +1,27 @@
//
// Notifications Settings.swift
// Cork
//
// Created by David Bureš - P on 14.05.2025.
//
import Foundation
import Defaults
public extension Defaults.Keys
{
/// Whether notifications are enabled
static let areNotificationsEnabled: Key<Bool> = .init("areNotificationsEnabled", default: true)
/// Type of notifications for outdated packages
/// Types:
/// - ``OutdatedPackageNotificationType.badge``: Only a badge in the app's icon
/// - ``OutdatedPackageNotificationType.both``: Badge, as well as a notification
static let outdatedPackageNotificationType: Key<OutdatedPackageNotificationType> = .init("outdatedPackageNotificationType", default: .badge)
/// Whether to send a notification about the results of a package updating action
static let notifyAboutPackageUpgradeResults: Key<Bool> = .init("notifyAboutPackageUpgradeResults", default: false)
/// Whether no send a notification about the results of a package installation action
static let notifyAboutPackageInstallationResults: Key<Bool> = .init("notifyAboutPackageInstallationResults", default: false)
}

View File

@ -0,0 +1,30 @@
//
// Packages Settings.swift
// Cork
//
// Created by David Bureš - P on 14.05.2025.
//
import Foundation
import Defaults
public extension Defaults.Keys
{
// MARK: - Package removal
// MARK: - Outdated packages
/// Whether to show `--greedy` packages
static let includeGreedyOutdatedPackages: Key<Bool> = .init("includeGreedyOutdatedPackages", default: false)
// MARK: - Compatibility
/// Whether to warn about packages incompatible with the user's system
static let showCompatibilityWarning: Key<Bool> = .init("showCompatibilityWarning", default: true)
// MARK: - Advanced
/// Whether to show live Terminal outputs of varous operations
static let showRealTimeTerminalOutputOfOperations: Key<Bool> = .init("showRealTimeTerminalOutputOfOperations", default: false)
// MARK: - Developer
/// Whether to allow purging
static let allowMoreCompleteUninstallations: Key<Bool> = .init("allowMoreCompleteUninstallations", default: false)
}

View File

@ -33,7 +33,8 @@ func corkTarget(configureWithSelfCompiled: Bool) -> ProjectDescription.Target {
.external(name: "DavidFoundation"),
.external(name: "ButtonKit"),
.package(product: "SwiftLintBuildToolPlugin", type: .plugin),
.external(name: "Defaults")
.external(name: "Defaults"),
.external(name: "DefaultsMacros")
], settings: .settings(configurations: [
.debug(
name: "Debug",