From 8fcdac1e6c044470e2976dca48bbbdcad6cf46d4 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 10 Nov 2024 19:43:32 -0800 Subject: [PATCH] Avoid assert/crash when app is moved before update alert shows (#2658) Note this puts Sparkle and possibly the rest of the app running in an unsupported state even a crash doesn't occur when showing an update alert. --- Sparkle/SUUpdateAlert.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index e38f80677..6b1777093 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -58,6 +58,7 @@ @implementation SUUpdateAlert void(^_completionBlock)(SPUUserUpdateChoice, NSRect, BOOL); BOOL _allowsAutomaticUpdates; + BOOL _windowLoadedAndShowsReleaseNotes; } - (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id)versionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice, NSRect, BOOL))completionBlock didBecomeKeyBlock:(void (^)(void))didBecomeKeyBlock @@ -184,8 +185,13 @@ - (void)displayReleaseNotesSpinner SPU_OBJC_DIRECT - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { - if (![self showsReleaseNotes]) { - if ([_host.bundle isEqual:NSBundle.mainBundle]) { + if (!_windowLoadedAndShowsReleaseNotes) { + if (self.window == nil) { + // Window was not properly loaded. + // This can happen if the app moves and the update alert nib fails to load + // This puts Sparkle in an unsupported state but we will try to avoid crashing + SULog(SULogLevelError, @"Error: SUUpdateAlert window is nil and failed to load, which may mean the app was moved. Sparkle is running in an unsupported state."); + } else if ([_host.bundle isEqual:NSBundle.mainBundle]) { SULog(SULogLevelError, @"Warning: '%@' is configured to not show release notes but release notes for version %@ were downloaded. Consider either removing release notes from your appcast or implementing -[SPUUpdaterDelegate updater:shouldDownloadReleaseNotesForUpdate:]", _host.name, _updateItem.displayVersionString); } return; @@ -344,6 +350,7 @@ - (void)windowDidLoad // Update alert should not be resizable when no release notes are available window.styleMask &= ~NSWindowStyleMaskResizable; } + _windowLoadedAndShowsReleaseNotes = showReleaseNotes; if (_updateItem.informationOnlyUpdate) { [_installButton setTitle:SULocalizedStringFromTableInBundle(@"Learn Moreā€¦", SPARKLE_TABLE, SUSparkleBundle(), @"Alternate title for 'Install Update' button when there's no download in RSS feed.")];