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.
This commit is contained in:
Zorg committed 2021-03-28 17:35:32 -07:00
1 parent 923bb96eda
commit 3a201a45ac
3 files changed
+21 -27

No files matched your search

+17 -4
View File
@@ -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;
+1 -3
View File
@@ -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
+3 -20
View File
@@ -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