Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid assert/crash when app is moved before update alert shows #2658

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading