--- Ice/Updates/UpdatesManager.swift +++ Ice/Updates/UpdatesManager.swift @@ -3,7 +3,6 @@ // Ice // -import Sparkle import SwiftUI /// Manager for app updates. @@ -18,39 +17,11 @@ /// The shared app state. private(set) weak var appState: AppState? - /// The underlying updater controller. - private(set) lazy var updaterController = SPUStandardUpdaterController( - startingUpdater: true, - updaterDelegate: self, - userDriverDelegate: self - ) - - /// The underlying updater. - var updater: SPUUpdater { - updaterController.updater - } - /// A Boolean value that indicates whether to automatically check for updates. - var automaticallyChecksForUpdates: Bool { - get { - updater.automaticallyChecksForUpdates - } - set { - objectWillChange.send() - updater.automaticallyChecksForUpdates = newValue - } - } + var automaticallyChecksForUpdates: Bool = false /// A Boolean value that indicates whether to automatically download updates. - var automaticallyDownloadsUpdates: Bool { - get { - updater.automaticallyDownloadsUpdates - } - set { - objectWillChange.send() - updater.automaticallyDownloadsUpdates = newValue - } - } + var automaticallyDownloadsUpdates: Bool = false /// Creates an updates manager with the given app state. init(appState: AppState) { @@ -59,87 +30,11 @@ } /// Sets up the manager. - func performSetup() { - _ = updaterController - configureCancellables() - } + func performSetup() { } - /// Configures the internal observers for the manager. - private func configureCancellables() { - updater.publisher(for: \.canCheckForUpdates) - .assign(to: &$canCheckForUpdates) - updater.publisher(for: \.lastUpdateCheckDate) - .assign(to: &$lastUpdateCheckDate) - } - /// Checks for app updates. - @objc func checkForUpdates() { - #if DEBUG - // Checking for updates hangs in debug mode. - let alert = NSAlert() - alert.messageText = "Checking for updates is not supported in debug mode." - alert.runModal() - #else - guard let appState else { - return - } - // Activate the app in case an alert needs to be displayed. - appState.activate(withPolicy: .regular) - appState.openSettingsWindow() - updater.checkForUpdates() - #endif - } + @objc func checkForUpdates() { } } -// MARK: UpdatesManager: SPUUpdaterDelegate -extension UpdatesManager: @preconcurrency SPUUpdaterDelegate { - func updater(_ updater: SPUUpdater, willScheduleUpdateCheckAfterDelay delay: TimeInterval) { - guard let appState else { - return - } - appState.userNotificationManager.requestAuthorization() - } -} - -// MARK: UpdatesManager: SPUStandardUserDriverDelegate -extension UpdatesManager: @preconcurrency SPUStandardUserDriverDelegate { - var supportsGentleScheduledUpdateReminders: Bool { true } - - func standardUserDriverShouldHandleShowingScheduledUpdate( - _ update: SUAppcastItem, - andInImmediateFocus immediateFocus: Bool - ) -> Bool { - if NSApp.isActive { - return immediateFocus - } else { - return false - } - } - - func standardUserDriverWillHandleShowingUpdate( - _ handleShowingUpdate: Bool, - forUpdate update: SUAppcastItem, - state: SPUUserUpdateState - ) { - guard let appState else { - return - } - if !state.userInitiated { - appState.userNotificationManager.addRequest( - with: .updateCheck, - title: "A new update is available", - body: "Version \(update.displayVersionString) is now available" - ) - } - } - - func standardUserDriverDidReceiveUserAttention(forUpdate update: SUAppcastItem) { - guard let appState else { - return - } - appState.userNotificationManager.removeDeliveredNotifications(with: [.updateCheck]) - } -} - // MARK: UpdatesManager: BindingExposable extension UpdatesManager: BindingExposable { } --- Ice/Settings/SettingsPanes/UpdatesSettingsPane.swift +++ Ice/Settings/SettingsPanes/UpdatesSettingsPane.swift @@ -6,66 +6,8 @@ import SwiftUI struct UpdatesSettingsPane: View { - @EnvironmentObject var appState: AppState - - private var updatesManager: UpdatesManager { - appState.updatesManager - } - - private var lastUpdateCheckString: String { - if let date = updatesManager.lastUpdateCheckDate { - date.formatted(date: .abbreviated, time: .standard) - } else { - "Never" - } - } - var body: some View { - IceForm { - IceSection { - automaticallyCheckForUpdates - automaticallyDownloadUpdates - } - if updatesManager.canCheckForUpdates { - IceSection { - checkForUpdates - } - } - } + Text("Updates are managed by MacPorts.") + .frame(maxWidth: .infinity, maxHeight: .infinity) } - - @ViewBuilder - private var automaticallyCheckForUpdates: some View { - Toggle( - "Automatically check for updates", - isOn: updatesManager.bindings.automaticallyChecksForUpdates - ) - } - - @ViewBuilder - private var automaticallyDownloadUpdates: some View { - Toggle( - "Automatically download updates", - isOn: updatesManager.bindings.automaticallyDownloadsUpdates - ) - } - - @ViewBuilder - private var checkForUpdates: some View { - HStack { - Button("Check for Updates…") { - updatesManager.checkForUpdates() - } - .controlSize(.large) - - Spacer() - - HStack(spacing: 2) { - Text("Last checked:") - Text(lastUpdateCheckString) - } - .lineLimit(1) - .font(.caption) - } - } }