From 3a201a45aca8133215165e67be03cd767ae5a730 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 28 Mar 2021 17:35:32 -0700 Subject: [PATCH] Don't make permission prompt a modal window This can block the rest of the UI from being loaded on an app that is just starting. I saw this myself in a pref pane plugin. --- Sparkle/SPUStandardUserDriver.m | 21 +++++++++++++++++---- Sparkle/SUUpdatePermissionPrompt.h | 4 +--- Sparkle/SUUpdatePermissionPrompt.m | 23 +++-------------------- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 58c09401..b9c3ed0f 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -29,6 +29,7 @@ @property (nonatomic) SUStatusController *checkingController; @property (nonatomic) SUUpdateAlert *activeUpdateAlert; @property (nonatomic) SUStatusController *statusController; +@property (nonatomic) SUUpdatePermissionPrompt *permissionPrompt; @end @@ -40,6 +41,7 @@ @synthesize checkingController = _checkingController; @synthesize activeUpdateAlert = _activeUpdateAlert; @synthesize statusController = _statusController; +@synthesize permissionPrompt = _permissionPrompt; #pragma mark Birth @@ -67,11 +69,17 @@ { assert(NSThread.isMainThread); - // This shows a modal alert dialog which unlike other alerts cannot be closed until the user makes a decision - // This means that we can never programatically close the dialog if something goes horribly wrong - // But this dialog should only show up once in the application's lifetime so this may be an OK decision + if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; + } - [SUUpdatePermissionPrompt promptWithHost:self.host request:request reply:reply]; + __weak __typeof__(self) weakSelf = self; + self.permissionPrompt = [[SUUpdatePermissionPrompt alloc] initPromptWithHost:self.host request:request reply:^(SUUpdatePermissionResponse *response) { + reply(response); + weakSelf.permissionPrompt = nil; + }]; + + [self.permissionPrompt showWindow:nil]; } #pragma mark Update Alert Focus @@ -443,6 +451,11 @@ [self closeCheckingWindow]; + if (self.permissionPrompt) { + [self.permissionPrompt close]; + self.permissionPrompt = nil; + } + if (self.statusController) { [self.statusController close]; self.statusController = nil; diff --git a/Sparkle/SUUpdatePermissionPrompt.h b/Sparkle/SUUpdatePermissionPrompt.h index e4477594..a0a519d7 100644 --- a/Sparkle/SUUpdatePermissionPrompt.h +++ b/Sparkle/SUUpdatePermissionPrompt.h @@ -15,10 +15,8 @@ @interface SUUpdatePermissionPrompt : NSWindowController -+ (void)promptWithHost:(SUHost *)host request:(SPUUpdatePermissionRequest *)request reply:(void (^)(SUUpdatePermissionResponse *))reply; +- (instancetype)initPromptWithHost:(SUHost *)theHost request:(SPUUpdatePermissionRequest *)request reply:(void (^)(SUUpdatePermissionResponse *))reply; -- (IBAction)toggleMoreInfo:(id)sender; -- (IBAction)finishPrompt:(NSButton *)sender; @end #endif diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index a6cc540d..b6bf53a3 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -66,24 +66,6 @@ static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE return self; } -+ (void)promptWithHost:(SUHost *)host request:(SPUUpdatePermissionRequest *)request reply:(void (^)(SUUpdatePermissionResponse *))reply -{ - // 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 = [(SUUpdatePermissionPrompt *)[[self class] alloc] initPromptWithHost:host request:request reply:reply]; - NSWindow *window = [prompt window]; - if (window) { - [NSApp runModalForWindow:window]; - } - } -} - - (BOOL)shouldAskAboutProfile { return [(NSNumber *)[self.host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue]; @@ -93,6 +75,8 @@ static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE - (void)windowDidLoad { + [self.window center]; + if (![self shouldAskAboutProfile]) { NSRect frame = [[self window] frame]; @@ -165,8 +149,7 @@ static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE SUUpdatePermissionResponse *response = [[SUUpdatePermissionResponse alloc] initWithAutomaticUpdateChecks:([sender tag] == 1) sendSystemProfile:self.shouldSendProfile]; self.reply(response); - [[self window] close]; - [NSApp stopModal]; + [self close]; } - (NSTouchBar *)makeTouchBar