diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 0fdccf52..44e05fd9 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -159,6 +159,9 @@ 723B5DA71CF7AB0100365F95 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA01CF7AB0100365F95 /* main.m */; }; 723B5DA91CF7AB0100365F95 /* SPUDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA31CF7AB0100365F95 /* SPUDownloader.m */; }; 723B5DAA1CF7AB6A00365F95 /* SPUDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA31CF7AB0100365F95 /* SPUDownloader.m */; }; + 723C8A541E2D60DB00C14942 /* SUTouchBarButtonGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */; }; + 723C8A551E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */; }; + 723C8A561E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */; }; 72464F701E1F31E000FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; 72464F711E1F326A00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; 72464F721E1F327C00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; @@ -993,6 +996,8 @@ 723B5DA31CF7AB0100365F95 /* SPUDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUDownloader.m; path = Downloader/SPUDownloader.m; sourceTree = SOURCE_ROOT; }; 723B5DA41CF7AB0100365F95 /* SPUDownloaderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUDownloaderDelegate.h; path = Downloader/SPUDownloaderDelegate.h; sourceTree = SOURCE_ROOT; }; 723B5DA51CF7AB0100365F95 /* SPUDownloaderProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUDownloaderProtocol.h; path = Downloader/SPUDownloaderProtocol.h; sourceTree = SOURCE_ROOT; }; + 723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarButtonGroup.h; sourceTree = ""; }; + 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarButtonGroup.m; sourceTree = ""; }; 7246E0A11C83B685003B4E75 /* SPUStandardUpdaterController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUStandardUpdaterController.h; sourceTree = ""; }; 7246E0A21C83B685003B4E75 /* SPUStandardUpdaterController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUStandardUpdaterController.m; sourceTree = ""; }; 724BB36C1D31D0B7005D534A /* org.sparkle-project.InstallerConnection.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = "org.sparkle-project.InstallerConnection.xpc"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1640,6 +1645,8 @@ 61B5FCA109C5228F00B25A18 /* SUUpdateAlert.m */, 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */, 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, + 723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */, + 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */, 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */, ); name = "User Interface"; @@ -2085,6 +2092,7 @@ 721BC20E1D1CDE55002BC71E /* SPULocalCacheDirectory.h in Headers */, 7267E5B11D3D8AD500D1BF90 /* SPUMessageTypes.h in Headers */, 728337A61C9E6FF40085AA99 /* SPUProbeInstallStatus.h in Headers */, + 723C8A541E2D60DB00C14942 /* SUTouchBarButtonGroup.h in Headers */, 72B767D21C9C7B9300A07552 /* SPUProbingUpdateDriver.h in Headers */, 7229E1B91C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h in Headers */, 726E075C1CA3A6D6001A286B /* SPUSecureCoding.h in Headers */, @@ -3011,6 +3019,7 @@ 72D954831CBAD34F006F28BD /* main.m in Sources */, 72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */, 7267E5DC1D3D8F1E00D1BF90 /* SPUMessageTypes.m in Sources */, + 723C8A561E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */, 721652621D3C44A100FD13D8 /* SPUSystemAuthorization.m in Sources */, 7267E5FA1D3DAC3600D1BF90 /* StatusInfo.m in Sources */, 720595EF1D700568000572E8 /* SUApplicationInfo.m in Sources */, @@ -3226,6 +3235,7 @@ 7246E0A41C83B685003B4E75 /* SPUStandardUpdaterController.m in Sources */, 725CB95B1C7121830064365A /* SPUStandardUserDriver.m in Sources */, 724BB3B01D3482BA005D534A /* SPUSystemAuthorization.m in Sources */, + 723C8A551E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */, 72B767DB1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.m in Sources */, 72DBA37E1D60CC34002594A8 /* SPUUpdatePermissionRequest.m in Sources */, 61B5F8EE09C4CE3C00B25A18 /* SPUUpdater.m in Sources */, 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 1198427c..f6693cbf 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -11,10 +11,14 @@ #import "SUApplicationInfo.h" #import "SULocalizations.h" #import "SUOperatingSystem.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 1fb56e01..daa29a6a 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -22,6 +22,10 @@ #import "SPUDownloadData.h" #import "SUApplicationInfo.h" #import "SPUUpdaterSettings.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. @@ -32,7 +36,7 @@ @end #endif -@interface SUUpdateAlert () +@interface SUUpdateAlert () @property (strong) SUAppcastItem *updateItem; @property (nonatomic) BOOL alreadyDownloaded; @@ -442,4 +446,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 66e96ef2..b143bc54 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -14,8 +14,11 @@ #import "SUHost.h" #import "SUConstants.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; @@ -26,6 +29,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 *); @@ -42,6 +47,8 @@ @synthesize moreInfoView; @synthesize moreInfoButton; @synthesize profileTableView; +@synthesize cancelButton; +@synthesize checkButton; - (instancetype)initPromptWithHost:(SUHost *)theHost request:(SPUUpdatePermissionRequest *)request reply:(void (^)(SUUpdatePermissionResponse *))reply { @@ -161,4 +168,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/SUUpdatePermissionPrompt.xib b/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib index 53f05c82..61ba6bac 100644 --- a/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib +++ b/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib @@ -8,6 +8,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)