Use popup title user driver when holding down command at launch

This commit is contained in:
Zorg committed 2016-08-13 08:39:55 -04:00
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
@@ -7,14 +7,13 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SUUpdateSettingsWindowController">
<connections>
<outlet property="updaterController" destination="Krg-xk-XXS" id="6b6-LB-0qA"/>
<outlet property="window" destination="Sg3-gX-Lin" id="wMT-bp-cDf"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<userDefaultsController representsSharedInstance="YES" id="ppb-Rb-fc7" userLabel="Shared User Defaults Controller"/>
<window title="Options" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="Sg3-gX-Lin" userLabel="Options Window">
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="Sg3-gX-Lin" userLabel="Options Window">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES"/>
<rect key="contentRect" x="543" y="572" width="314" height="149"/>
@@ -31,7 +30,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="Krg-xk-XXS" name="value" keyPath="updater.automaticallyChecksForUpdates" id="tr7-kI-Ucb"/>
<binding destination="-2" name="value" keyPath="self.updater.automaticallyChecksForUpdates" id="23i-l2-Iol"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="z6k-h3-dCv">
@@ -41,7 +40,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="Krg-xk-XXS" name="value" keyPath="updater.automaticallyDownloadsUpdates" id="BHg-1e-ggS"/>
<binding destination="-2" name="value" keyPath="self.updater.automaticallyDownloadsUpdates" id="JjR-6W-VVm"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wFV-vU-Dle">
@@ -51,7 +50,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="Krg-xk-XXS" name="value" keyPath="updater.sendsSystemProfile" id="oTa-ha-dC7"/>
<binding destination="-2" name="value" keyPath="self.updater.sendsSystemProfile" id="neZ-PW-Ps7"/>
</connections>
</button>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mU2-vs-cVn">
@@ -86,13 +85,12 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="Krg-xk-XXS" name="value" keyPath="updater.updateCheckInterval" id="XFG-PN-mB8"/>
<binding destination="-2" name="value" keyPath="self.updater.updateCheckInterval" id="U5m-Up-VEZ"/>
</connections>
</textField>
</subviews>
</view>
<point key="canvasLocation" x="233" y="312.5"/>
</window>
<customObject id="Krg-xk-XXS" userLabel="Updater Controller" customClass="SPUStandardUpdaterController"/>
</objects>
</document>