macos: "Check for updates" cancels whatever the current update state is (#9203)

This mainly allows users who have a pending update but didn't install it
for some time to re-check to see if there is something newer in the mean
time.
pull/9208/head
Mitchell Hashimoto 2025-10-14 07:31:31 -07:00 committed by GitHub
parent 9f726492ac
commit 3d837cbbce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -93,7 +93,22 @@ class UpdateController {
///
/// This is typically connected to a menu item action.
@objc func checkForUpdates() {
updater.checkForUpdates()
// If we're already idle, then just check for updates immediately.
if viewModel.state == .idle {
updater.checkForUpdates()
return
}
// If we're not idle then we need to cancel any prior state.
installCancellable?.cancel()
viewModel.state.cancel()
// The above will take time to settle, so we delay the check for some time.
// The 100ms is arbitrary and I'd rather not, but we have to wait more than
// one loop tick it seems.
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) { [weak self] in
self?.updater.checkForUpdates()
}
}
/// Validate the check for updates menu item.