Skip to content

Commit

Permalink
Don't force Sparkle updates in background #738 (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasderraugh authored Nov 14, 2021
1 parent 90a5943 commit 96d8885
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
1 change: 0 additions & 1 deletion GitUp/Application/AboutWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
NS_ASSUME_NONNULL_BEGIN

@interface AboutWindowController : NSWindowController
@property(assign, nonatomic, readwrite) BOOL updatePending;
@end

NS_ASSUME_NONNULL_END
10 changes: 3 additions & 7 deletions GitUp/Application/AboutWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ - (instancetype)init {

- (void)windowDidLoad {
[super windowDidLoad];
[self populateWithDataWhenUpdateIsPending:self.updatePending];
[self configureUI];
}

- (void)populateWithDataWhenUpdateIsPending:(BOOL)updatePending {
- (void)configureUI {
NSString* version = nil;
#if DEBUG
version = @"DEBUG";
#else
if (updatePending) {
version = NSLocalizedString(@"Update Pending", nil);
} else {
version = [NSString stringWithFormat:NSLocalizedString(@"Version %@ (%@)", nil), [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
}
version = [NSString stringWithFormat:NSLocalizedString(@"Version %@ (%@)", nil), [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
#endif
self.versionTextField.stringValue = version;
self.copyrightTextField.stringValue = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSHumanReadableCopyright"];
Expand Down
27 changes: 4 additions & 23 deletions GitUp/Application/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ @interface AppDelegate () <NSUserNotificationCenterDelegate, SUUpdaterDelegate>

@implementation AppDelegate {
SUUpdater* _updater;
BOOL _updatePending;
BOOL _manualCheck;

CFMessagePortRef _messagePort;
Expand Down Expand Up @@ -212,9 +211,8 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
if (![[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsKey_DisableSparkle]) {
_updater = [SUUpdater sharedUpdater];
_updater.delegate = self;
_updater.automaticallyChecksForUpdates = NO;
_updater.automaticallyChecksForUpdates = YES;
_updater.sendsSystemProfile = NO;
_updater.automaticallyDownloadsUpdates = YES;

_manualCheck = NO;
[_updater checkForUpdatesInBackground];
Expand Down Expand Up @@ -382,9 +380,9 @@ - (NSDictionary*)_processToolCommand:(NSDictionary*)input {

#pragma mark - Actions

- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem {
if (anItem.action == @selector(checkForUpdates:)) {
return _updater && !_updatePending && ![_updater updateInProgress];
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
if (menuItem.action == @selector(checkForUpdates:)) {
return [_updater validateMenuItem:menuItem];
}
return YES;
}
Expand All @@ -406,7 +404,6 @@ - (IBAction)viewIssues:(id)sender {
}

- (IBAction)showAboutPanel:(id)sender {
self.aboutWindowController.updatePending = _updatePending;
[self.aboutWindowController showWindow:nil];
}

Expand Down Expand Up @@ -562,14 +559,6 @@ - (NSString*)feedURLStringForUpdater:(SUUpdater*)updater {
- (void)updater:(SUUpdater*)updater didFindValidUpdate:(SUAppcastItem*)item {
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
XLOG_INFO(@"Did find app update on channel '%@' for version %@", channel, item.versionString);
if (_manualCheck) {
NSAlert* alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"A GitUp update is available!", nil);
alert.informativeText = NSLocalizedString(@"The update will download automatically in the background and be installed when you quit GitUp.", nil);
[alert addButtonWithTitle:NSLocalizedString(@"OK", nil)];
alert.type = kGIAlertType_Note;
[alert runModal];
}
}

- (void)updaterDidNotFindUpdate:(SUUpdater*)updater {
Expand All @@ -595,12 +584,4 @@ - (void)updater:(SUUpdater*)updater willInstallUpdate:(SUAppcastItem*)item {
XLOG_INFO(@"Installing app update for version %@", item.versionString);
}

- (void)updater:(SUUpdater*)updater willInstallUpdateOnQuit:(SUAppcastItem*)item immediateInstallationInvocation:(NSInvocation*)invocation {
XLOG_INFO(@"Will install app update for version %@ on quit", item.versionString);
_updatePending = YES;
[self _showNotificationWithTitle:NSLocalizedString(@"Update Available", nil)
action:NULL
message:NSLocalizedString(@"Relaunch GitUp to update to version %@ (%@).", nil), item.displayVersionString, item.versionString];
}

@end

0 comments on commit 96d8885

Please sign in to comment.