Skip to content

Commit

Permalink
Avoid assert/crash when app is moved before update alert shows (#2658)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zorgiepoo authored Nov 11, 2024
1 parent d04faab commit 8fcdac1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sparkle/SUUpdateAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<SUVersionDisplay>)versionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice, NSRect, BOOL))completionBlock didBecomeKeyBlock:(void (^)(void))didBecomeKeyBlock
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.")];
Expand Down

0 comments on commit 8fcdac1

Please sign in to comment.