Show update-available banner automatically on launch (#1651)
* Show update-available banner automatically on launch Probe for updates immediately on launch via Sparkle's checkForUpdateInformation() so the sidebar surfaces a passive update indicator without waiting for the 24h scheduler. When Sparkle detects an available update in the background, the pill now shows "Update Available: X.Y.Z" with accent styling while the updater is idle. Clicking it triggers the full interactive update flow. Also fixes thread safety in delegate callbacks by dispatching @Published mutations to the main queue. Closes #1643 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add periodic background update probe every 15 minutes The launch-only probe wouldn't catch updates published while the app is already running. Add a repeating 15-minute timer that calls checkForUpdateInformation() so the sidebar banner appears within a reasonable window after a new version is published. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Change background update probe interval to 30 minutes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Change update check interval to 1 hour and migrate existing users Reduce Sparkle's scheduled check interval from 24h to 1h so update banners appear sooner. Migrate users stuck on the old 24h default by bumping the migration key to v2. Align background probe interval with the Sparkle check interval instead of hardcoding 30 minutes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
63e65a7f5c
commit
e203c51c7a
7 changed files with 147 additions and 32 deletions
|
|
@ -8,8 +8,9 @@ enum UpdateSettings {
|
|||
static let automaticallyUpdateKey = "SUAutomaticallyUpdate"
|
||||
static let scheduledCheckIntervalKey = "SUScheduledCheckInterval"
|
||||
static let sendProfileInfoKey = "SUSendProfileInfo"
|
||||
static let migrationKey = "cmux.sparkle.automaticChecksMigration.v1"
|
||||
static let scheduledCheckInterval: TimeInterval = 60 * 60 * 24
|
||||
static let migrationKey = "cmux.sparkle.automaticChecksMigration.v2"
|
||||
static let previousDefaultScheduledCheckInterval: TimeInterval = 60 * 60 * 24
|
||||
static let scheduledCheckInterval: TimeInterval = 60 * 60
|
||||
|
||||
static func apply(to defaults: UserDefaults) {
|
||||
defaults.register(defaults: [
|
||||
|
|
@ -26,7 +27,9 @@ enum UpdateSettings {
|
|||
defaults.set(true, forKey: automaticChecksKey)
|
||||
|
||||
if let interval = defaults.object(forKey: scheduledCheckIntervalKey) as? NSNumber {
|
||||
if interval.doubleValue <= 0 {
|
||||
let currentInterval = interval.doubleValue
|
||||
if currentInterval <= 0 ||
|
||||
abs(currentInterval - previousDefaultScheduledCheckInterval) < 1 {
|
||||
defaults.set(scheduledCheckInterval, forKey: scheduledCheckIntervalKey)
|
||||
}
|
||||
} else {
|
||||
|
|
@ -54,9 +57,11 @@ class UpdateController {
|
|||
private var noUpdateDismissCancellable: AnyCancellable?
|
||||
private var noUpdateDismissWorkItem: DispatchWorkItem?
|
||||
private var readyCheckWorkItem: DispatchWorkItem?
|
||||
private var backgroundProbeTimer: Timer?
|
||||
private var didStartUpdater: Bool = false
|
||||
private let readyRetryDelay: TimeInterval = 0.25
|
||||
private let readyRetryCount: Int = 20
|
||||
private let backgroundProbeInterval: TimeInterval = UpdateSettings.scheduledCheckInterval
|
||||
|
||||
var viewModel: UpdateViewModel {
|
||||
userDriver.viewModel
|
||||
|
|
@ -88,6 +93,7 @@ class UpdateController {
|
|||
noUpdateDismissCancellable?.cancel()
|
||||
noUpdateDismissWorkItem?.cancel()
|
||||
readyCheckWorkItem?.cancel()
|
||||
backgroundProbeTimer?.invalidate()
|
||||
}
|
||||
|
||||
/// Start the updater. If startup fails, the error is shown via the custom UI.
|
||||
|
|
@ -115,6 +121,7 @@ class UpdateController {
|
|||
UpdateLogStore.shared.append(
|
||||
"updater started (autoChecks=\(updater.automaticallyChecksForUpdates), interval=\(interval)s, autoDownloads=\(updater.automaticallyDownloadsUpdates))"
|
||||
)
|
||||
startLaunchUpdateProbeIfNeeded()
|
||||
} catch {
|
||||
userDriver.viewModel.state = .error(.init(
|
||||
error: error,
|
||||
|
|
@ -130,6 +137,27 @@ class UpdateController {
|
|||
}
|
||||
}
|
||||
|
||||
private func startLaunchUpdateProbeIfNeeded() {
|
||||
guard updater.automaticallyChecksForUpdates else {
|
||||
UpdateLogStore.shared.append("launch update probe skipped (automatic checks disabled)")
|
||||
return
|
||||
}
|
||||
|
||||
// Probe immediately on launch so the sidebar can surface a passive update indicator
|
||||
// without waiting for Sparkle's scheduled check or opening interactive update UI.
|
||||
UpdateLogStore.shared.append("starting launch update probe")
|
||||
updater.checkForUpdateInformation()
|
||||
|
||||
// Re-probe every hour so the banner appears even if the app has been running
|
||||
// for a while when a new version is published.
|
||||
backgroundProbeTimer?.invalidate()
|
||||
backgroundProbeTimer = Timer.scheduledTimer(withTimeInterval: backgroundProbeInterval, repeats: true) { [weak self] _ in
|
||||
guard let self, self.updater.automaticallyChecksForUpdates else { return }
|
||||
UpdateLogStore.shared.append("periodic background update probe")
|
||||
self.updater.checkForUpdateInformation()
|
||||
}
|
||||
}
|
||||
|
||||
/// Force install the current update by auto-confirming all installable states.
|
||||
func installUpdate() {
|
||||
guard viewModel.state.isInstallable else { return }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue