mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
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:
1 parent
923bb96eda
commit
3a201a45ac
3 files changed
+21
-27
No files matched your search
Vendored
+17
-4
@@ -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;
|
||||
|
||||
Vendored
+1
-3
@@ -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
|
||||
Vendored
+3
-20
@@ -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
|
||||
|
||||
Reference in new issue
Block a user