mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Use popup title user driver when holding down command at launch
This commit is contained in:
1 parent
f514861871
commit
6fb7b4a18b
2 files changed
+38
-13
No files matched your search
@@ -8,31 +8,58 @@
|
||||
|
||||
#import "SUUpdateSettingsWindowController.h"
|
||||
#import <Sparkle/Sparkle.h>
|
||||
#import "SUPopUpTitlebarUserDriver.h"
|
||||
|
||||
@interface SUUpdateSettingsWindowController ()
|
||||
|
||||
@property (nonatomic) IBOutlet SPUStandardUpdaterController *updaterController;
|
||||
@property (nonatomic) SPUUpdater *updater;
|
||||
@property (nonatomic) id<SPUStandardUserDriverProtocol> userDriver;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUUpdateSettingsWindowController
|
||||
|
||||
@synthesize updaterController = _updaterController;
|
||||
@synthesize updater = _updater;
|
||||
@synthesize userDriver = _userDriver;
|
||||
|
||||
- (NSString *)windowNibName
|
||||
{
|
||||
return NSStringFromClass([self class]);
|
||||
}
|
||||
|
||||
- (IBAction)checkForUpdates:(id __unused)sender
|
||||
- (void)windowDidLoad
|
||||
{
|
||||
[self.updaterController checkForUpdates:self];
|
||||
NSBundle *mainBundle = [NSBundle mainBundle];
|
||||
|
||||
// If the user is holding down command, we use the popup title user driver instead
|
||||
id<SPUUserDriver, SPUStandardUserDriverProtocol> userDriver;
|
||||
if (([NSEvent modifierFlags] & NSCommandKeyMask) != 0) {
|
||||
userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:self.window delegate:nil];
|
||||
} else {
|
||||
userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:mainBundle delegate:nil];
|
||||
}
|
||||
|
||||
self.userDriver = userDriver;
|
||||
self.updater = [[SPUUpdater alloc] initWithHostBundle:mainBundle userDriver:userDriver delegate:nil];
|
||||
|
||||
NSError *updaterError = nil;
|
||||
if (![self.updater startUpdater:&updaterError]) {
|
||||
NSLog(@"Failed to start updater with error: %@", updaterError);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)checkForUpdates:(id __unused)sender
|
||||
{
|
||||
[self.updater checkForUpdates];
|
||||
}
|
||||
|
||||
// This would not be necessary if the updater controller was instantiated in the main menu nib
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
|
||||
{
|
||||
return [self.updaterController validateMenuItem:menuItem];
|
||||
if (menuItem.action == @selector(checkForUpdates:)) {
|
||||
return self.userDriver.canCheckForUpdates;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user