diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 13ac27fe..28ff1914 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -263,6 +263,9 @@ 767B61AE1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */; }; A5BF4F1D1BC7668B007A052A /* SUTestWebServer.m in Sources */ = {isa = PBXBuildFile; fileRef = A5BF4F1C1BC7668B007A052A /* SUTestWebServer.m */; }; C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */ = {isa = PBXBuildFile; fileRef = C23E88591BE7AF890050BB73 /* SparkleTestCodeSignApp.enc.dmg */; }; + E1545EC51E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h */; }; + E1545EC61E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1EC2A301E21667000245715 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */; }; F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */ = {isa = PBXBuildFile; fileRef = F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */; }; F8761EB61ADC5E7A000C9034 /* SUCodeSigningVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B078CD15A5FB6100600039 /* SUCodeSigningVerifier.m */; }; @@ -795,6 +798,8 @@ A5BF4F1B1BC7668B007A052A /* SUTestWebServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTestWebServer.h; sourceTree = ""; }; A5BF4F1C1BC7668B007A052A /* SUTestWebServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTestWebServer.m; sourceTree = ""; }; C23E88591BE7AF890050BB73 /* SparkleTestCodeSignApp.enc.dmg */ = {isa = PBXFileReference; lastKnownFileType = file; path = SparkleTestCodeSignApp.enc.dmg; sourceTree = ""; }; + E1545EC31E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarButtonGroup.h; sourceTree = ""; }; + E1545EC41E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarButtonGroup.m; sourceTree = ""; }; F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUCodeSigningVerifierTest.m; sourceTree = ""; }; F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SparkleTestCodeSignApp.zip; sourceTree = ""; }; FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigFrameworkDebug.xcconfig; sourceTree = ""; }; @@ -1175,6 +1180,8 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 7205C42F1E1215AD00E370AE /* SUUpdatePermissionResponse.h */, 7205C4301E1215AD00E370AE /* SUUpdatePermissionResponse.m */, + E1545EC31E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h */, + E1545EC41E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m */, ); name = "User Interface"; sourceTree = ""; @@ -1378,6 +1385,7 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, + E1545EC51E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, 722954C41D04E66F00ECF9CA /* SUFileOperationConstants.h in Headers */, @@ -1862,6 +1870,7 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, + E1EC2A301E21667000245715 /* SUTouchBarButtonGroup.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2009,6 +2018,7 @@ 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */, + E1545EC61E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m in Sources */, 61B93A3D0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.m in Sources */, 61299A8E09CA790200B7442F /* SUUnarchiver.m in Sources */, 722589DB1E0B19F4005EA0B9 /* SUUnarchiverNotifier.m in Sources */, diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index 4f066d90..c5fc0ed9 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -11,13 +11,18 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUHost.h" +#import "SUTouchBarButtonGroup.h" -@interface SUAutomaticUpdateAlert () +static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUAutomaticUpdateAlert"; + +@interface SUAutomaticUpdateAlert () @property (strong) void(^completionBlock)(SUAutomaticInstallationChoice); @property (strong) SUAppcastItem *updateItem; @property (strong) SUHost *host; @property (weak) IBOutlet NSButton *skipButton; +@property (weak) IBOutlet NSButton *laterButton; +@property (weak) IBOutlet NSButton *installButton; @end @implementation SUAutomaticUpdateAlert @@ -25,6 +30,8 @@ @synthesize updateItem; @synthesize completionBlock; @synthesize skipButton; +@synthesize laterButton; +@synthesize installButton; - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block { @@ -100,4 +107,23 @@ } } +- (NSTouchBar *)makeTouchBar +{ + NSTouchBar *touchBar = [[NSTouchBar alloc] init]; + touchBar.defaultItemIdentifiers = @[SUAutomaticUpdateAlertTouchBarIndentifier,]; + touchBar.principalItemIdentifier = SUAutomaticUpdateAlertTouchBarIndentifier; + touchBar.delegate = self; + return touchBar; +} + +- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier +{ + if ([identifier isEqualToString:SUAutomaticUpdateAlertTouchBarIndentifier]) { + NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + item.viewController = [[SUTouchBarButtonGroup alloc] initByReferencingButtons:@[self.installButton, self.laterButton, self.skipButton]]; + return item; + } + return nil; +} + @end diff --git a/Sparkle/SUStatus.xib b/Sparkle/SUStatus.xib index d225d6c2..cb6a8084 100644 --- a/Sparkle/SUStatus.xib +++ b/Sparkle/SUStatus.xib @@ -16,7 +16,7 @@ - + diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index eb5ecbfc..f4f8bc04 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -11,10 +11,14 @@ #import "SUHost.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" +#import "SUTouchBarButtonGroup.h" -@interface SUStatusController () +static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUStatusController"; + +@interface SUStatusController () @property (copy) NSString *title, *buttonTitle; @property (strong) SUHost *host; +@property NSButton *touchBarButton; @end @implementation SUStatusController @@ -27,6 +31,7 @@ @synthesize actionButton; @synthesize progressBar; @synthesize statusTextField; +@synthesize touchBarButton; - (instancetype)initWithHost:(SUHost *)aHost { @@ -93,6 +98,10 @@ [self.actionButton setTarget:target]; [self.actionButton setAction:action]; [self.actionButton setKeyEquivalent:isDefault ? @"\r" : @""]; + + self.touchBarButton.target = self.actionButton.target; + self.touchBarButton.action = self.actionButton.action; + self.touchBarButton.keyEquivalent = self.actionButton.keyEquivalent; // 06/05/2008 Alex: Avoid a crash when cancelling during the extraction [self setButtonEnabled:(target != nil)]; @@ -123,4 +132,28 @@ [self.progressBar setUsesThreadedAnimation:YES]; } + +- (NSTouchBar *)makeTouchBar +{ + NSTouchBar *touchBar = [[NSTouchBar alloc] init]; + touchBar.defaultItemIdentifiers = @[ SUStatusControllerTouchBarIndentifier,]; + touchBar.principalItemIdentifier = SUStatusControllerTouchBarIndentifier; + touchBar.delegate = self; + return touchBar; +} + +- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier +{ + if ([identifier isEqualToString:SUStatusControllerTouchBarIndentifier]) { + NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + SUTouchBarButtonGroup *group = [[SUTouchBarButtonGroup alloc] initByReferencingButtons:@[self.actionButton,]]; + item.viewController = group; + self.touchBarButton = group.buttons.firstObject; + [self.touchBarButton bind:@"title" toObject:self.actionButton withKeyPath:@"title" options:nil]; + [self.touchBarButton bind:@"enabled" toObject:self.actionButton withKeyPath:@"enabled" options:nil]; + return item; + } + return nil; +} + @end diff --git a/Sparkle/SUTouchBarButtonGroup.h b/Sparkle/SUTouchBarButtonGroup.h new file mode 100644 index 00000000..55337b06 --- /dev/null +++ b/Sparkle/SUTouchBarButtonGroup.h @@ -0,0 +1,25 @@ +// +// SUTouchBarButtonGroup.h +// Sparkle +// +// Created by Yuxin Wang on 05/01/2017. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import + +@class NSTouchBar; +@class NSTouchBarItem; +@class NSCustomTouchBarItem; + +NS_ASSUME_NONNULL_BEGIN + +@interface SUTouchBarButtonGroup : NSViewController + +@property (nonatomic, readonly, copy) NSArray *buttons; + +- (instancetype)initByReferencingButtons:(NSArray *)buttons; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUTouchBarButtonGroup.m b/Sparkle/SUTouchBarButtonGroup.m new file mode 100644 index 00000000..3a56046e --- /dev/null +++ b/Sparkle/SUTouchBarButtonGroup.m @@ -0,0 +1,60 @@ +// +// SUTouchBarButtonGroup.m +// Sparkle +// +// Created by Yuxin Wang on 05/01/2017. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import "SUTouchBarButtonGroup.h" + +@implementation SUTouchBarButtonGroup + +@synthesize buttons = _buttons; + +- (instancetype)initByReferencingButtons:(NSArray *)buttons +{ + if (!(self = [super init])) + return self; + + NSView *buttonGroup = [[NSView alloc] initWithFrame:NSZeroRect]; + self.view = buttonGroup; + NSMutableArray *constraints = [NSMutableArray array]; + NSMutableArray *buttonCopies = [NSMutableArray arrayWithCapacity:buttons.count]; + + for (NSUInteger i = 0; i < buttons.count; i++) { + NSButton *button = buttons[i]; + NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; + buttonCopy.tag = button.tag; + buttonCopy.enabled = button.enabled; + + if (i == 0) { + buttonCopy.keyEquivalent = @"\r"; + } + + buttonCopy.translatesAutoresizingMaskIntoConstraints = NO; + + [buttonCopies addObject:buttonCopy]; + [buttonGroup addSubview:buttonCopy]; + + [constraints addObject:[NSLayoutConstraint constraintWithItem:buttonCopy attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:buttonGroup attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]]; + [constraints addObject:[NSLayoutConstraint constraintWithItem:buttonCopy attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:buttonGroup attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]]; + if (i == 0) { + [constraints addObject:[NSLayoutConstraint constraintWithItem:buttonCopy attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:buttonGroup attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0]]; + } else { + [constraints addObject:[NSLayoutConstraint constraintWithItem:buttonCopy attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:buttonCopies[i-1] attribute:NSLayoutAttributeLeading multiplier:1.0 constant:(i == 1) ? -8 : -32]]; + [constraints addObject:[NSLayoutConstraint constraintWithItem:buttonCopy attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:buttonCopies[i-1] attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0]]; + constraints.lastObject.priority = 250; + } + if (i == buttons.count - 1) { + [constraints addObject:[NSLayoutConstraint constraintWithItem:buttonCopy attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:buttonGroup attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]]; + } + } + [NSLayoutConstraint activateConstraints:constraints]; + + _buttons = buttonCopies; + return self; +} + +@end + diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index e7d79610..78a01647 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,6 +21,9 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUSystemUpdateInfo.h" +#import "SUTouchBarButtonGroup.h" + +static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdateAlert"; // WebKit protocols are not explicitly declared until 10.11 SDK, so // declare dummy protocols to keep the build working on earlier SDKs. @@ -31,7 +34,7 @@ @end #endif -@interface SUUpdateAlert () +@interface SUUpdateAlert () @property (strong) SUAppcastItem *updateItem; @property (strong) SUHost *host; @@ -320,4 +323,23 @@ return webViewMenuItems; } +- (NSTouchBar *)makeTouchBar +{ + NSTouchBar *touchBar = [[NSTouchBar alloc] init]; + touchBar.defaultItemIdentifiers = @[SUUpdateAlertTouchBarIndentifier,]; + touchBar.principalItemIdentifier = SUUpdateAlertTouchBarIndentifier; + touchBar.delegate = self; + return touchBar; +} + +- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier +{ + if ([identifier isEqualToString:SUUpdateAlertTouchBarIndentifier]) { + NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + item.viewController = [[SUTouchBarButtonGroup alloc] initByReferencingButtons:@[self.installButton, self.laterButton, self.skipButton]]; + return item; + } + return nil; +} + @end diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index a6b96378..9f2802a6 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -13,8 +13,11 @@ #import "SUConstants.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" +#import "SUTouchBarButtonGroup.h" -@interface SUUpdatePermissionPrompt () +static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdatePermissionPrompt"; + +@interface SUUpdatePermissionPrompt () @property (assign) BOOL isShowingMoreInfo; @property (assign) BOOL shouldSendProfile; @@ -25,6 +28,8 @@ @property (weak) IBOutlet NSView *moreInfoView; @property (weak) IBOutlet NSButton *moreInfoButton; @property (weak) IBOutlet NSTableView *profileTableView; +@property (weak) IBOutlet NSButton *cancelButton; +@property (weak) IBOutlet NSButton *checkButton; @property (nonatomic, readonly) void (^reply)(SUUpdatePermissionResponse *); @@ -41,6 +46,8 @@ @synthesize moreInfoView; @synthesize moreInfoButton; @synthesize profileTableView; +@synthesize cancelButton; +@synthesize checkButton; - (BOOL)shouldAskAboutProfile { @@ -160,4 +167,23 @@ [NSApp stopModal]; } +- (NSTouchBar *)makeTouchBar +{ + NSTouchBar *touchBar = [[NSTouchBar alloc] init]; + touchBar.defaultItemIdentifiers = @[SUUpdatePermissionPromptTouchBarIndentifier,]; + touchBar.principalItemIdentifier = SUUpdatePermissionPromptTouchBarIndentifier; + touchBar.delegate = self; + return touchBar; +} + +- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier +{ + if ([identifier isEqualToString:SUUpdatePermissionPromptTouchBarIndentifier]) { + NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + item.viewController = [[SUTouchBarButtonGroup alloc] initByReferencingButtons:@[self.checkButton, self.cancelButton]]; + return item; + } + return nil; +} + @end diff --git a/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib b/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib index 8c96fb03..213f7b57 100644 --- a/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib +++ b/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib @@ -6,6 +6,8 @@ + + diff --git a/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib b/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib index 3ad4bd24..4a007572 100644 --- a/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib +++ b/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib @@ -7,6 +7,8 @@ + + diff --git a/UITests/SUTestApplicationTest.swift b/UITests/SUTestApplicationTest.swift index 7074953b..7f360a20 100644 --- a/UITests/SUTestApplicationTest.swift +++ b/UITests/SUTestApplicationTest.swift @@ -89,7 +89,7 @@ class SUTestApplicationTest: XCTestCase app.dialogs["SUUpdateAlert"].staticTexts["Software Update"].click() app.dialogs["SUUpdateAlert"].buttons["Install Update"].click() - app.buttons["Install and Relaunch"].click() + app.windows["SUStatus"].buttons["Install and Relaunch"].click() // Wait for the new updated app to finish launching so we can test if it's the frontmost app sleep(3)