From a52604a264d95aa8a536bdb60fe7a0fa12e31b69 Mon Sep 17 00:00:00 2001 From: Kornel Date: Thu, 20 Jul 2017 13:20:20 +0100 Subject: [PATCH] Revert "Ensure UI code always runs on the main thread" This reverts commit 423ee5a9d690a835cd8a8827e4c4df07cecf9dab. --- Sparkle/SUAutomaticUpdateDriver.m | 37 +++++++-------- Sparkle/SUUIBasedUpdateDriver.m | 76 ++++++++++++++---------------- Sparkle/SUUpdatePermissionPrompt.m | 26 +++++----- 3 files changed, 65 insertions(+), 74 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 57ca62af..c88aaeaf 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -49,29 +49,26 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 self.interruptible = NO; [self invalidateShowUpdateAlertTimer]; - dispatch_async(dispatch_get_main_queue(), ^{ - if (self.alert) { - [self.alert close]; - } + if (self.alert) { + [self.alert close]; + } - self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { - [self automaticUpdateAlertFinishedWithChoice:choice]; - }]; + self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { + [self automaticUpdateAlertFinishedWithChoice:choice]; + }]; - // If the app is a menubar app or the like, we need to focus it first and alter the - // update prompt to behave like a normal window. Otherwise if the window were hidden - // there may be no way for the application to be activated to make it visible again. - if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { - [[self.alert window] setHidesOnDeactivate:NO]; - [NSApp activateIgnoringOtherApps:YES]; - } + // If the app is a menubar app or the like, we need to focus it first and alter the + // update prompt to behave like a normal window. Otherwise if the window were hidden + // there may be no way for the application to be activated to make it visible again. + if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { + [[self.alert window] setHidesOnDeactivate:NO]; + [NSApp activateIgnoringOtherApps:YES]; + } - if ([NSApp isActive]) { - [[self.alert window] makeKeyAndOrderFront:self]; - } else { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; - } - }); + if ([NSApp isActive]) + [[self.alert window] makeKeyAndOrderFront:self]; + else + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } - (void)unarchiverDidFinish:(id)__unused ua diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index e356a4c0..0400e5aa 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -68,35 +68,33 @@ return; } - dispatch_async(dispatch_get_main_queue(), ^{ - self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) { - [self updateAlertFinishedWithChoice:choice]; - }]; + self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) { + [self updateAlertFinishedWithChoice:choice]; + }]; - id versDisp = nil; - if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { - versDisp = [[updater delegate] versionDisplayerForUpdater:self.updater]; + id versDisp = nil; + if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { + versDisp = [[updater delegate] versionDisplayerForUpdater:self.updater]; + } + [self.updateAlert setVersionDisplayer:versDisp]; + + // If the app is a menubar app or the like, we need to focus it first and alter the + // update prompt to behave like a normal window. Otherwise if the window were hidden + // there may be no way for the application to be activated to make it visible again. + if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { + [[self.updateAlert window] setHidesOnDeactivate:NO]; + [NSApp activateIgnoringOtherApps:YES]; + } + + // Only show the update alert if the app is active; otherwise, we'll wait until it is. + if ([NSApp isActive]) { + NSWindow *window = [self.updateAlert window]; + if ([self shouldDisableKeyboardShortcutForInstallButton]) { + [self.updateAlert disableKeyboardShortcutForInstallButton]; } - [self.updateAlert setVersionDisplayer:versDisp]; - - // If the app is a menubar app or the like, we need to focus it first and alter the - // update prompt to behave like a normal window. Otherwise if the window were hidden - // there may be no way for the application to be activated to make it visible again. - if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { - [[self.updateAlert window] setHidesOnDeactivate:NO]; - [NSApp activateIgnoringOtherApps:YES]; - } - - // Only show the update alert if the app is active; otherwise, we'll wait until it is. - if ([NSApp isActive]) { - NSWindow *window = [self.updateAlert window]; - if ([self shouldDisableKeyboardShortcutForInstallButton]) { - [self.updateAlert disableKeyboardShortcutForInstallButton]; - } - [window makeKeyAndOrderFront:self]; - } else - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; - }); + [window makeKeyAndOrderFront:self]; + } else + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } - (BOOL)shouldDisableKeyboardShortcutForInstallButton { @@ -319,22 +317,20 @@ - (void)showAlert:(NSAlert *)alert { - dispatch_sync(dispatch_get_main_queue(), ^{ - id updater = self.updater; - if ([[updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) { - [[updater delegate] updaterWillShowModalAlert:self.updater]; - } + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) { + [[updater delegate] updaterWillShowModalAlert:self.updater]; + } - // When showing a modal alert we need to ensure that background applications - // are focused to inform the user since there is no dock icon to notify them. - if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { [NSApp activateIgnoringOtherApps:YES]; } + // When showing a modal alert we need to ensure that background applications + // are focused to inform the user since there is no dock icon to notify them. + if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { [NSApp activateIgnoringOtherApps:YES]; } - [alert setIcon:[SUApplicationInfo bestIconForHost:self.host]]; - [alert runModal]; + [alert setIcon:[SUApplicationInfo bestIconForHost:self.host]]; + [alert runModal]; - if ([[updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)]) - [[updater delegate] updaterDidShowModalAlert:self.updater]; - }); + if ([[updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)]) + [[updater delegate] updaterDidShowModalAlert:self.updater]; } @end diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index d3773a7c..7f1c0055 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -72,22 +72,20 @@ static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE + (void)promptWithHost:(SUHost *)host systemProfile:(NSArray *)profile reply:(void (^)(SUUpdatePermissionResponse *))reply { - dispatch_async(dispatch_get_main_queue(), ^{ - // If this is a background application we need to focus it in order to bring the prompt - // to the user's attention. Otherwise the prompt would be hidden behind other applications and - // the user would not know why the application was paused. - if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { - [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; - } + // If this is a background application we need to focus it in order to bring the prompt + // to the user's attention. Otherwise the prompt would be hidden behind other applications and + // the user would not know why the application was paused. + if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; + } - if (![NSApp modalWindow]) { // do not prompt if there is is another modal window on screen - SUUpdatePermissionPrompt *prompt = [[[self class] alloc] initWithHost:host systemProfile:profile reply:reply]; - NSWindow *window = [prompt window]; - if (window) { - [NSApp runModalForWindow:window]; - } + if (![NSApp modalWindow]) { // do not prompt if there is is another modal window on screen + SUUpdatePermissionPrompt *prompt = [[[self class] alloc] initWithHost:host systemProfile:profile reply:reply]; + NSWindow *window = [prompt window]; + if (window) { + [NSApp runModalForWindow:window]; } - }); + } } - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; }