From d44a122a21abc86128de626bd97d754a70b8d984 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Sun, 8 Jan 2017 15:17:47 +0800 Subject: [PATCH 01/15] Add Touch Bar support --- Sparkle.xcodeproj/project.pbxproj | 10 ++++ Sparkle/SUAutomaticUpdateAlert.m | 27 +++++++++ Sparkle/SUStatusController.m | 16 +++++ Sparkle/SUTouchBar.h | 19 ++++++ Sparkle/SUTouchBar.m | 94 ++++++++++++++++++++++++++++++ Sparkle/SUUpdateAlert.m | 13 +++++ Sparkle/SUUpdatePermissionPrompt.m | 22 +++++++ 7 files changed, 201 insertions(+) create mode 100644 Sparkle/SUTouchBar.h create mode 100644 Sparkle/SUTouchBar.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index e83078b9..5f32fe12 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -262,6 +262,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 /* SUTouchBar.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUTouchBar.h */; }; + E1545EC61E1D7E0200FAECE8 /* SUTouchBar.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBar.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1EC2A301E21667000245715 /* SUTouchBar.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBar.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 */; }; @@ -794,6 +797,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 /* SUTouchBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBar.h; sourceTree = ""; }; + E1545EC41E1D7E0200FAECE8 /* SUTouchBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBar.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 = ""; }; @@ -1174,6 +1179,8 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 7205C42F1E1215AD00E370AE /* SUUpdatePermissionResponse.h */, 7205C4301E1215AD00E370AE /* SUUpdatePermissionResponse.m */, + E1545EC31E1D7E0200FAECE8 /* SUTouchBar.h */, + E1545EC41E1D7E0200FAECE8 /* SUTouchBar.m */, ); name = "User Interface"; sourceTree = ""; @@ -1377,6 +1384,7 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, + E1545EC51E1D7E0200FAECE8 /* SUTouchBar.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, 722954C41D04E66F00ECF9CA /* SUFileOperationConstants.h in Headers */, @@ -1861,6 +1869,7 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, + E1EC2A301E21667000245715 /* SUTouchBar.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2007,6 +2016,7 @@ 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */, + E1545EC61E1D7E0200FAECE8 /* SUTouchBar.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 f49dae6e..3fc21d71 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -11,6 +11,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUHost.h" +#import "SUTouchBar.h" @interface SUAutomaticUpdateAlert () @property (strong) void(^completionBlock)(SUAutomaticInstallationChoice); @@ -88,4 +89,30 @@ } } +- (NSTouchBar *)makeTouchBar +{ + NSButton *installButton, *laterButton, *cancelButton; + for (NSView *control in self.window.contentView.subviews) { + if ([control isKindOfClass:[NSButton class]]) { + NSButton *button = (NSButton *)control; + if (button.action == @selector(installNow:)) { + installButton = button; + } else if (button.action == @selector(installLater:)) { + laterButton = button; + } else if (button.action == @selector(doNotInstall:)) { + cancelButton = button; + } + } + } + + SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; + [touchBar addButtonWithButton:cancelButton]; + [touchBar addSpace]; + [touchBar addButtonWithButton:laterButton]; + [touchBar addButtonWithButton:installButton]; + [touchBar addSpace]; + [touchBar addSpace]; + return touchBar; +} + @end diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index cdca9ff8..bca5114a 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -11,10 +11,12 @@ #import "SUHost.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" +#import "SUTouchBar.h" @interface SUStatusController () @property (copy) NSString *title, *buttonTitle; @property (strong) SUHost *host; +@property NSButton *touchBarButton; @end @implementation SUStatusController @@ -27,6 +29,7 @@ @synthesize actionButton; @synthesize progressBar; @synthesize statusTextField; +@synthesize touchBarButton; - (instancetype)initWithHost:(SUHost *)aHost { @@ -93,6 +96,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 +130,13 @@ [self.progressBar setUsesThreadedAnimation:YES]; } +- (NSTouchBar *)makeTouchBar +{ + SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; + self.touchBarButton = [touchBar addButtonWithButton:self.actionButton]; + [self.touchBarButton bind:@"title" toObject:self.actionButton withKeyPath:@"title" options:nil]; + [self.touchBarButton bind:@"enabled" toObject:self.actionButton withKeyPath:@"enabled" options:nil]; + return touchBar; +} + @end diff --git a/Sparkle/SUTouchBar.h b/Sparkle/SUTouchBar.h new file mode 100644 index 00000000..1d1169c5 --- /dev/null +++ b/Sparkle/SUTouchBar.h @@ -0,0 +1,19 @@ +// +// SUTouchBar.h +// Sparkle +// +// Created by Yuxin Wang on 05/01/2017. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import + +@class NSTouchBar; + +@interface SUTouchBar : NSTouchBar + +-(instancetype)initWithIdentifier:(NSString *)identifier; +-(NSButton *)addButtonWithButton:(NSButton *)button; +-(void)addSpace; + +@end diff --git a/Sparkle/SUTouchBar.m b/Sparkle/SUTouchBar.m new file mode 100644 index 00000000..a1b801f9 --- /dev/null +++ b/Sparkle/SUTouchBar.m @@ -0,0 +1,94 @@ +// +// SUTouchBar.m +// Sparkle +// +// Created by Yuxin Wang on 05/01/2017. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import "SUTouchBar.h" + +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 + +@interface SUTouchBar() + +@property (copy) NSString* indentifier; +@property NSMutableArray *touchBarItems; + +@end + +@implementation SUTouchBar + +@synthesize indentifier; +@synthesize touchBarItems; + +-(instancetype)initWithIdentifier:(NSString *)anIdentifier +{ + if (!(self = [super init])) + return self; + + self.indentifier = [NSString stringWithFormat:@"%@.%@", [NSBundle mainBundle].bundleIdentifier, anIdentifier]; + self.touchBarItems = [NSMutableArray arrayWithCapacity:6]; + + self.defaultItemIdentifiers = @[self.indentifier,]; + self.principalItemIdentifier = self.indentifier; + + return self; +} + +- (NSTouchBarItem *)itemForIdentifier:(NSTouchBarItemIdentifier)identifier +{ + if ([identifier isEqualToString:self.indentifier]) + return [NSGroupTouchBarItem groupItemWithIdentifier:self.indentifier items:self.touchBarItems]; + return [super itemForIdentifier:identifier]; +} + +-(NSButton *)addButtonWithButton:(NSButton *)button +{ + NSString *itemId = [self.indentifier stringByAppendingFormat:@".button-%lu", self.touchBarItems.count]; + NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:itemId]; + + NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; + buttonCopy.keyEquivalent = button.keyEquivalent; + buttonCopy.tag = button.tag; + + item.view = buttonCopy; + [self.touchBarItems addObject:item]; + return buttonCopy; +} + +-(void)addSpace +{ + NSTouchBarItem *item = [super itemForIdentifier:NSTouchBarItemIdentifierFixedSpaceLarge]; + [self.touchBarItems addObject:item]; +} + +@end + +#else + +@interface NSTouchBar : NSObject + +@end + +@implementation NSTouchBar + +@end + +@implementation SUTouchBar + +-(instancetype)initWithIdentifier:(NSString *)identifier { + return nil; +} + +-(NSButton *)addButtonWithButton:(NSButton *)button { + return nil; +} + +-(void)addSpace { + return nil; +} + +@end + +#endif diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index efda7f45..b6c6069f 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,6 +21,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUSystemUpdateInfo.h" +#import "SUTouchBar.h" // WebKit protocols are not explicitly declared until 10.11 SDK, so // declare dummy protocols to keep the build working on earlier SDKs. @@ -316,4 +317,16 @@ return webViewMenuItems; } +- (NSTouchBar *)makeTouchBar +{ + SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; + [touchBar addButtonWithButton:self.skipButton]; + [touchBar addSpace]; + [touchBar addButtonWithButton:self.laterButton]; + [touchBar addButtonWithButton:self.installButton]; + [touchBar addSpace]; + [touchBar addSpace]; + return touchBar; +} + @end diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 23ee647e..30cb68f2 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -13,6 +13,7 @@ #import "SUConstants.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" +#import "SUTouchBar.h" @interface SUUpdatePermissionPrompt () @@ -160,4 +161,25 @@ [NSApp stopModal]; } +- (NSTouchBar *)makeTouchBar +{ + NSButton *checkButton, *cancelButton; + for (NSView *control in self.window.contentView.subviews) { + if ([control isKindOfClass:[NSButton class]]) { + NSButton *button = (NSButton *)control; + if (button.action == @selector(finishPrompt:)) { + if (button.tag == 1) { + checkButton = button; + } else if (button.tag == 0) { + cancelButton = button; + } + } + } + } + SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; + [touchBar addButtonWithButton:cancelButton]; + [touchBar addButtonWithButton:checkButton]; + return touchBar; +} + @end From 6902b80ab68dab3c07e40a48816dc42fc6c17ce1 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Sun, 8 Jan 2017 15:23:26 +0800 Subject: [PATCH 02/15] Fix UITests multiple matches issue introduced in touch bar --- Sparkle/SUStatus.xib | 2 +- UITests/SUTestApplicationTest.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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) From f795802d605057798533afba89d1402940dd643e Mon Sep 17 00:00:00 2001 From: Bi11 Date: Tue, 10 Jan 2017 07:22:44 +0800 Subject: [PATCH 03/15] Use NSTouchBarDelegate to avoid subclassing NSTouchBar --- Sparkle.xcodeproj/project.pbxproj | 20 +++++------ Sparkle/SUAutomaticUpdateAlert.m | 20 ++++++----- Sparkle/SUStatusController.m | 10 +++--- .../{SUTouchBar.h => SUTouchBarProvider.h} | 6 ++-- .../{SUTouchBar.m => SUTouchBarProvider.m} | 35 +++++++++---------- Sparkle/SUUpdateAlert.m | 21 ++++++----- Sparkle/SUUpdatePermissionPrompt.m | 12 ++++--- 7 files changed, 66 insertions(+), 58 deletions(-) rename Sparkle/{SUTouchBar.h => SUTouchBarProvider.h} (71%) rename Sparkle/{SUTouchBar.m => SUTouchBarProvider.m} (64%) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 5f32fe12..65f1fafa 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -262,9 +262,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 /* SUTouchBar.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUTouchBar.h */; }; - E1545EC61E1D7E0200FAECE8 /* SUTouchBar.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBar.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; - E1EC2A301E21667000245715 /* SUTouchBar.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBar.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1545EC51E1D7E0200FAECE8 /* SUTouchBarProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUTouchBarProvider.h */; }; + E1545EC61E1D7E0200FAECE8 /* SUTouchBarProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1EC2A301E21667000245715 /* SUTouchBarProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.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 */; }; @@ -797,8 +797,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 /* SUTouchBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBar.h; sourceTree = ""; }; - E1545EC41E1D7E0200FAECE8 /* SUTouchBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBar.m; sourceTree = ""; }; + E1545EC31E1D7E0200FAECE8 /* SUTouchBarProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarProvider.h; sourceTree = ""; }; + E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarProvider.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 = ""; }; @@ -1179,8 +1179,8 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 7205C42F1E1215AD00E370AE /* SUUpdatePermissionResponse.h */, 7205C4301E1215AD00E370AE /* SUUpdatePermissionResponse.m */, - E1545EC31E1D7E0200FAECE8 /* SUTouchBar.h */, - E1545EC41E1D7E0200FAECE8 /* SUTouchBar.m */, + E1545EC31E1D7E0200FAECE8 /* SUTouchBarProvider.h */, + E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.m */, ); name = "User Interface"; sourceTree = ""; @@ -1384,7 +1384,7 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, - E1545EC51E1D7E0200FAECE8 /* SUTouchBar.h in Headers */, + E1545EC51E1D7E0200FAECE8 /* SUTouchBarProvider.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, 722954C41D04E66F00ECF9CA /* SUFileOperationConstants.h in Headers */, @@ -1869,7 +1869,7 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, - E1EC2A301E21667000245715 /* SUTouchBar.m in Sources */, + E1EC2A301E21667000245715 /* SUTouchBarProvider.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2016,7 +2016,7 @@ 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */, - E1545EC61E1D7E0200FAECE8 /* SUTouchBar.m in Sources */, + E1545EC61E1D7E0200FAECE8 /* SUTouchBarProvider.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 3fc21d71..71c1fd67 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -11,18 +11,20 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUHost.h" -#import "SUTouchBar.h" +#import "SUTouchBarProvider.h" @interface SUAutomaticUpdateAlert () @property (strong) void(^completionBlock)(SUAutomaticInstallationChoice); @property (strong) SUAppcastItem *updateItem; @property (strong) SUHost *host; +@property (strong) SUTouchBarProvider *touchBarProvider; @end @implementation SUAutomaticUpdateAlert @synthesize host; @synthesize updateItem; @synthesize completionBlock; +@synthesize touchBarProvider; - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block { @@ -105,14 +107,14 @@ } } - SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; - [touchBar addButtonWithButton:cancelButton]; - [touchBar addSpace]; - [touchBar addButtonWithButton:laterButton]; - [touchBar addButtonWithButton:installButton]; - [touchBar addSpace]; - [touchBar addSpace]; - return touchBar; + self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; + [self.touchBarProvider addButtonWithButton:cancelButton]; + [self.touchBarProvider addSpace]; + [self.touchBarProvider addButtonWithButton:laterButton]; + [self.touchBarProvider addButtonWithButton:installButton]; + [self.touchBarProvider addSpace]; + [self.touchBarProvider addSpace]; + return self.touchBarProvider.touchBar; } @end diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index bca5114a..40af4f5e 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -11,12 +11,13 @@ #import "SUHost.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUTouchBar.h" +#import "SUTouchBarProvider.h" @interface SUStatusController () @property (copy) NSString *title, *buttonTitle; @property (strong) SUHost *host; @property NSButton *touchBarButton; +@property (strong) SUTouchBarProvider *touchBarProvider; @end @implementation SUStatusController @@ -30,6 +31,7 @@ @synthesize progressBar; @synthesize statusTextField; @synthesize touchBarButton; +@synthesize touchBarProvider; - (instancetype)initWithHost:(SUHost *)aHost { @@ -132,11 +134,11 @@ - (NSTouchBar *)makeTouchBar { - SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; - self.touchBarButton = [touchBar addButtonWithButton:self.actionButton]; + self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; + self.touchBarButton = [self.touchBarProvider addButtonWithButton:self.actionButton]; [self.touchBarButton bind:@"title" toObject:self.actionButton withKeyPath:@"title" options:nil]; [self.touchBarButton bind:@"enabled" toObject:self.actionButton withKeyPath:@"enabled" options:nil]; - return touchBar; + return self.touchBarProvider.touchBar; } @end diff --git a/Sparkle/SUTouchBar.h b/Sparkle/SUTouchBarProvider.h similarity index 71% rename from Sparkle/SUTouchBar.h rename to Sparkle/SUTouchBarProvider.h index 1d1169c5..ffb2f9a8 100644 --- a/Sparkle/SUTouchBar.h +++ b/Sparkle/SUTouchBarProvider.h @@ -1,5 +1,5 @@ // -// SUTouchBar.h +// SUTouchBarProvider.h // Sparkle // // Created by Yuxin Wang on 05/01/2017. @@ -10,7 +10,9 @@ @class NSTouchBar; -@interface SUTouchBar : NSTouchBar +@interface SUTouchBarProvider : NSObject + +@property (strong, readonly) NSTouchBar *touchBar; -(instancetype)initWithIdentifier:(NSString *)identifier; -(NSButton *)addButtonWithButton:(NSButton *)button; diff --git a/Sparkle/SUTouchBar.m b/Sparkle/SUTouchBarProvider.m similarity index 64% rename from Sparkle/SUTouchBar.m rename to Sparkle/SUTouchBarProvider.m index a1b801f9..044f6506 100644 --- a/Sparkle/SUTouchBar.m +++ b/Sparkle/SUTouchBarProvider.m @@ -1,46 +1,49 @@ // -// SUTouchBar.m +// SUTouchBarProvider.m // Sparkle // // Created by Yuxin Wang on 05/01/2017. // Copyright © 2017 Sparkle Project. All rights reserved. // -#import "SUTouchBar.h" +#import "SUTouchBarProvider.h" #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 -@interface SUTouchBar() +@interface SUTouchBarProvider() @property (copy) NSString* indentifier; @property NSMutableArray *touchBarItems; @end -@implementation SUTouchBar +@implementation SUTouchBarProvider @synthesize indentifier; @synthesize touchBarItems; +@synthesize touchBar; -(instancetype)initWithIdentifier:(NSString *)anIdentifier { if (!(self = [super init])) return self; - self.indentifier = [NSString stringWithFormat:@"%@.%@", [NSBundle mainBundle].bundleIdentifier, anIdentifier]; - self.touchBarItems = [NSMutableArray arrayWithCapacity:6]; + indentifier = [NSString stringWithFormat:@"%@.%@", [NSBundle mainBundle].bundleIdentifier, anIdentifier]; + touchBarItems = [NSMutableArray arrayWithCapacity:6]; - self.defaultItemIdentifiers = @[self.indentifier,]; - self.principalItemIdentifier = self.indentifier; + touchBar = [[NSTouchBar alloc] init]; + touchBar.defaultItemIdentifiers = @[indentifier,]; + touchBar.principalItemIdentifier = indentifier; + touchBar.delegate = self; return self; } -- (NSTouchBarItem *)itemForIdentifier:(NSTouchBarItemIdentifier)identifier +- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { if ([identifier isEqualToString:self.indentifier]) return [NSGroupTouchBarItem groupItemWithIdentifier:self.indentifier items:self.touchBarItems]; - return [super itemForIdentifier:identifier]; + return nil; } -(NSButton *)addButtonWithButton:(NSButton *)button @@ -59,7 +62,7 @@ -(void)addSpace { - NSTouchBarItem *item = [super itemForIdentifier:NSTouchBarItemIdentifierFixedSpaceLarge]; + NSTouchBarItem *item = [[NSTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierFixedSpaceLarge]; [self.touchBarItems addObject:item]; } @@ -67,15 +70,9 @@ #else -@interface NSTouchBar : NSObject +@implementation SUTouchBarProvider -@end - -@implementation NSTouchBar - -@end - -@implementation SUTouchBar +@synthesize touchBar; -(instancetype)initWithIdentifier:(NSString *)identifier { return nil; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index b6c6069f..ae615a6f 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,7 +21,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUSystemUpdateInfo.h" -#import "SUTouchBar.h" +#import "SUTouchBarProvider.h" // WebKit protocols are not explicitly declared until 10.11 SDK, so // declare dummy protocols to keep the build working on earlier SDKs. @@ -48,6 +48,7 @@ @property (weak) IBOutlet NSButton *installButton; @property (weak) IBOutlet NSButton *skipButton; @property (weak) IBOutlet NSButton *laterButton; +@property (strong) SUTouchBarProvider *touchBarProvider; @end @@ -70,6 +71,8 @@ @synthesize skipButton; @synthesize laterButton; +@synthesize touchBarProvider; + - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block { self = [super initWithWindowNibName:@"SUUpdateAlert"]; @@ -319,14 +322,14 @@ - (NSTouchBar *)makeTouchBar { - SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; - [touchBar addButtonWithButton:self.skipButton]; - [touchBar addSpace]; - [touchBar addButtonWithButton:self.laterButton]; - [touchBar addButtonWithButton:self.installButton]; - [touchBar addSpace]; - [touchBar addSpace]; - return touchBar; + self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; + [self.touchBarProvider addButtonWithButton:self.skipButton]; + [self.touchBarProvider addSpace]; + [self.touchBarProvider addButtonWithButton:self.laterButton]; + [self.touchBarProvider addButtonWithButton:self.installButton]; + [self.touchBarProvider addSpace]; + [self.touchBarProvider addSpace]; + return self.touchBarProvider.touchBar; } @end diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 30cb68f2..e7e4bedd 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -13,7 +13,7 @@ #import "SUConstants.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUTouchBar.h" +#import "SUTouchBarProvider.h" @interface SUUpdatePermissionPrompt () @@ -26,6 +26,7 @@ @property (weak) IBOutlet NSView *moreInfoView; @property (weak) IBOutlet NSButton *moreInfoButton; @property (weak) IBOutlet NSTableView *profileTableView; +@property (strong) SUTouchBarProvider *touchBarProvider; @property (nonatomic, readonly) void (^reply)(SUUpdatePermissionResponse *); @@ -42,6 +43,7 @@ @synthesize moreInfoView; @synthesize moreInfoButton; @synthesize profileTableView; +@synthesize touchBarProvider; - (BOOL)shouldAskAboutProfile { @@ -176,10 +178,10 @@ } } } - SUTouchBar *touchBar = [[SUTouchBar alloc] initWithIdentifier:self.className]; - [touchBar addButtonWithButton:cancelButton]; - [touchBar addButtonWithButton:checkButton]; - return touchBar; + self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; + [self.touchBarProvider addButtonWithButton:cancelButton]; + [self.touchBarProvider addButtonWithButton:checkButton]; + return self.touchBarProvider.touchBar; } @end From 07599c2ffdaf51ac5dcec3cea605f252a6af4496 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Tue, 10 Jan 2017 07:34:52 +0800 Subject: [PATCH 04/15] Bind `enabled` and `title` for touch bar buttons by default --- Sparkle/SUStatusController.m | 2 -- Sparkle/SUTouchBarProvider.m | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index 40af4f5e..38ca0d7c 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -136,8 +136,6 @@ { self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; self.touchBarButton = [self.touchBarProvider addButtonWithButton:self.actionButton]; - [self.touchBarButton bind:@"title" toObject:self.actionButton withKeyPath:@"title" options:nil]; - [self.touchBarButton bind:@"enabled" toObject:self.actionButton withKeyPath:@"enabled" options:nil]; return self.touchBarProvider.touchBar; } diff --git a/Sparkle/SUTouchBarProvider.m b/Sparkle/SUTouchBarProvider.m index 044f6506..241e781d 100644 --- a/Sparkle/SUTouchBarProvider.m +++ b/Sparkle/SUTouchBarProvider.m @@ -54,6 +54,9 @@ NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; buttonCopy.keyEquivalent = button.keyEquivalent; buttonCopy.tag = button.tag; + + [buttonCopy bind:@"title" toObject:button withKeyPath:@"title" options:nil]; + [buttonCopy bind:@"enabled" toObject:button withKeyPath:@"enabled" options:nil]; item.view = buttonCopy; [self.touchBarItems addObject:item]; From 6e01dd272f7f4e619367917a899de7e58f86a061 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Tue, 10 Jan 2017 08:34:25 +0800 Subject: [PATCH 05/15] Use outlets instead of iterating through subviews --- Sparkle/SUAutomaticUpdateAlert.m | 24 ++++++------------- Sparkle/SUUpdatePermissionPrompt.m | 21 +++++----------- Sparkle/en.lproj/SUAutomaticUpdateAlert.xib | 2 ++ Sparkle/en.lproj/SUUpdatePermissionPrompt.xib | 2 ++ 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index 6bcd1ff3..aae589c4 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -19,6 +19,8 @@ @property (strong) SUHost *host; @property (weak) IBOutlet NSButton *skipButton; +@property (weak) IBOutlet NSButton *laterButton; +@property (weak) IBOutlet NSButton *installButton; @property (strong) SUTouchBarProvider *touchBarProvider; @end @@ -27,6 +29,8 @@ @synthesize updateItem; @synthesize completionBlock; @synthesize skipButton; +@synthesize laterButton; +@synthesize installButton; @synthesize touchBarProvider; - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block @@ -105,25 +109,11 @@ - (NSTouchBar *)makeTouchBar { - NSButton *installButton, *laterButton, *cancelButton; - for (NSView *control in self.window.contentView.subviews) { - if ([control isKindOfClass:[NSButton class]]) { - NSButton *button = (NSButton *)control; - if (button.action == @selector(installNow:)) { - installButton = button; - } else if (button.action == @selector(installLater:)) { - laterButton = button; - } else if (button.action == @selector(doNotInstall:)) { - cancelButton = button; - } - } - } - self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:cancelButton]; + [self.touchBarProvider addButtonWithButton:self.skipButton]; [self.touchBarProvider addSpace]; - [self.touchBarProvider addButtonWithButton:laterButton]; - [self.touchBarProvider addButtonWithButton:installButton]; + [self.touchBarProvider addButtonWithButton:self.laterButton]; + [self.touchBarProvider addButtonWithButton:self.installButton]; [self.touchBarProvider addSpace]; [self.touchBarProvider addSpace]; return self.touchBarProvider.touchBar; diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 62a221e7..7e3ab730 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -26,6 +26,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 (strong) SUTouchBarProvider *touchBarProvider; @property (nonatomic, readonly) void (^reply)(SUUpdatePermissionResponse *); @@ -43,6 +45,8 @@ @synthesize moreInfoView; @synthesize moreInfoButton; @synthesize profileTableView; +@synthesize cancelButton; +@synthesize checkButton; @synthesize touchBarProvider; - (BOOL)shouldAskAboutProfile @@ -165,22 +169,9 @@ - (NSTouchBar *)makeTouchBar { - NSButton *checkButton, *cancelButton; - for (NSView *control in self.window.contentView.subviews) { - if ([control isKindOfClass:[NSButton class]]) { - NSButton *button = (NSButton *)control; - if (button.action == @selector(finishPrompt:)) { - if (button.tag == 1) { - checkButton = button; - } else if (button.tag == 0) { - cancelButton = button; - } - } - } - } self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:cancelButton]; - [self.touchBarProvider addButtonWithButton:checkButton]; + [self.touchBarProvider addButtonWithButton:self.cancelButton]; + [self.touchBarProvider addButtonWithButton:self.checkButton]; return self.touchBarProvider.touchBar; } 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 @@ + + From b16d881808b925cde8c2f11cfce7ade17bb14896 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Tue, 10 Jan 2017 18:44:48 +0800 Subject: [PATCH 06/15] Fix default button on touch bar --- Sparkle/SUAutomaticUpdateAlert.m | 2 +- Sparkle/SUUpdateAlert.m | 2 +- Sparkle/SUUpdatePermissionPrompt.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index aae589c4..571b9dfb 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -113,7 +113,7 @@ [self.touchBarProvider addButtonWithButton:self.skipButton]; [self.touchBarProvider addSpace]; [self.touchBarProvider addButtonWithButton:self.laterButton]; - [self.touchBarProvider addButtonWithButton:self.installButton]; + [self.touchBarProvider addButtonWithButton:self.installButton].keyEquivalent = @"\r"; [self.touchBarProvider addSpace]; [self.touchBarProvider addSpace]; return self.touchBarProvider.touchBar; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 188f7c4e..acc2bb40 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -330,7 +330,7 @@ [self.touchBarProvider addButtonWithButton:self.skipButton]; [self.touchBarProvider addSpace]; [self.touchBarProvider addButtonWithButton:self.laterButton]; - [self.touchBarProvider addButtonWithButton:self.installButton]; + [self.touchBarProvider addButtonWithButton:self.installButton].keyEquivalent = @"\r"; [self.touchBarProvider addSpace]; [self.touchBarProvider addSpace]; return self.touchBarProvider.touchBar; diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 7e3ab730..5e7822aa 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -171,7 +171,7 @@ { self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; [self.touchBarProvider addButtonWithButton:self.cancelButton]; - [self.touchBarProvider addButtonWithButton:self.checkButton]; + [self.touchBarProvider addButtonWithButton:self.checkButton].keyEquivalent = @"\r"; return self.touchBarProvider.touchBar; } From 7ae0e71b02e2e054ad5e9fcdd86766b6ddba1f4d Mon Sep 17 00:00:00 2001 From: Bi11 Date: Wed, 11 Jan 2017 00:42:03 +0800 Subject: [PATCH 07/15] Fix compile issue with older SDK < 10.12.2 --- Sparkle/SUTouchBarProvider.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Sparkle/SUTouchBarProvider.m b/Sparkle/SUTouchBarProvider.m index 241e781d..7f7886e2 100644 --- a/Sparkle/SUTouchBarProvider.m +++ b/Sparkle/SUTouchBarProvider.m @@ -86,7 +86,6 @@ } -(void)addSpace { - return nil; } @end From d95f420360aba9c43c6f9b356da9cefd5ee28bb3 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Wed, 11 Jan 2017 00:44:15 +0800 Subject: [PATCH 08/15] Set touch bar default button directly instead of changing its keyEquivalent --- Sparkle/SUAutomaticUpdateAlert.m | 6 +++--- Sparkle/SUStatusController.m | 2 +- Sparkle/SUTouchBarProvider.h | 2 +- Sparkle/SUTouchBarProvider.m | 6 ++++-- Sparkle/SUUpdateAlert.m | 6 +++--- Sparkle/SUUpdatePermissionPrompt.m | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index 571b9dfb..2c11a6e9 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -110,10 +110,10 @@ - (NSTouchBar *)makeTouchBar { self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:self.skipButton]; + [self.touchBarProvider addButtonWithButton:self.skipButton isDefault:NO]; [self.touchBarProvider addSpace]; - [self.touchBarProvider addButtonWithButton:self.laterButton]; - [self.touchBarProvider addButtonWithButton:self.installButton].keyEquivalent = @"\r"; + [self.touchBarProvider addButtonWithButton:self.laterButton isDefault:NO]; + [self.touchBarProvider addButtonWithButton:self.installButton isDefault:YES]; [self.touchBarProvider addSpace]; [self.touchBarProvider addSpace]; return self.touchBarProvider.touchBar; diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index 7697fcdc..aeb22499 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -135,7 +135,7 @@ - (NSTouchBar *)makeTouchBar { self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - self.touchBarButton = [self.touchBarProvider addButtonWithButton:self.actionButton]; + self.touchBarButton = [self.touchBarProvider addButtonWithButton:self.actionButton isDefault:[self.actionButton.keyEquivalent isEqualToString:@"\r"]]; return self.touchBarProvider.touchBar; } diff --git a/Sparkle/SUTouchBarProvider.h b/Sparkle/SUTouchBarProvider.h index ffb2f9a8..11d4cba8 100644 --- a/Sparkle/SUTouchBarProvider.h +++ b/Sparkle/SUTouchBarProvider.h @@ -15,7 +15,7 @@ @property (strong, readonly) NSTouchBar *touchBar; -(instancetype)initWithIdentifier:(NSString *)identifier; --(NSButton *)addButtonWithButton:(NSButton *)button; +-(NSButton *)addButtonWithButton:(NSButton *)button isDefault:(BOOL)isDefault; -(void)addSpace; @end diff --git a/Sparkle/SUTouchBarProvider.m b/Sparkle/SUTouchBarProvider.m index 7f7886e2..015f46df 100644 --- a/Sparkle/SUTouchBarProvider.m +++ b/Sparkle/SUTouchBarProvider.m @@ -46,14 +46,16 @@ return nil; } --(NSButton *)addButtonWithButton:(NSButton *)button +-(NSButton *)addButtonWithButton:(NSButton *)button isDefault:(BOOL)isDefault { NSString *itemId = [self.indentifier stringByAppendingFormat:@".button-%lu", self.touchBarItems.count]; NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:itemId]; NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; - buttonCopy.keyEquivalent = button.keyEquivalent; buttonCopy.tag = button.tag; + if (isDefault) { + buttonCopy.keyEquivalent = @"\r"; + } [buttonCopy bind:@"title" toObject:button withKeyPath:@"title" options:nil]; [buttonCopy bind:@"enabled" toObject:button withKeyPath:@"enabled" options:nil]; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index acc2bb40..60e0e9b2 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -327,10 +327,10 @@ - (NSTouchBar *)makeTouchBar { self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:self.skipButton]; + [self.touchBarProvider addButtonWithButton:self.skipButton isDefault:NO]; [self.touchBarProvider addSpace]; - [self.touchBarProvider addButtonWithButton:self.laterButton]; - [self.touchBarProvider addButtonWithButton:self.installButton].keyEquivalent = @"\r"; + [self.touchBarProvider addButtonWithButton:self.laterButton isDefault:NO]; + [self.touchBarProvider addButtonWithButton:self.installButton isDefault:YES]; [self.touchBarProvider addSpace]; [self.touchBarProvider addSpace]; return self.touchBarProvider.touchBar; diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 5e7822aa..e236bf6d 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -170,8 +170,8 @@ - (NSTouchBar *)makeTouchBar { self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:self.cancelButton]; - [self.touchBarProvider addButtonWithButton:self.checkButton].keyEquivalent = @"\r"; + [self.touchBarProvider addButtonWithButton:self.cancelButton isDefault:NO]; + [self.touchBarProvider addButtonWithButton:self.checkButton isDefault:YES]; return self.touchBarProvider.touchBar; } From 6ca4b05cad6709b3df6f439fa3431b1036da6cf9 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Wed, 11 Jan 2017 01:57:16 +0800 Subject: [PATCH 09/15] Change touch bar identifier prefix to sparkle bundle identifier --- Sparkle/SUTouchBarProvider.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUTouchBarProvider.m b/Sparkle/SUTouchBarProvider.m index 015f46df..fe092d26 100644 --- a/Sparkle/SUTouchBarProvider.m +++ b/Sparkle/SUTouchBarProvider.m @@ -7,6 +7,7 @@ // #import "SUTouchBarProvider.h" +#import "SUConstants.h" #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 @@ -28,7 +29,7 @@ if (!(self = [super init])) return self; - indentifier = [NSString stringWithFormat:@"%@.%@", [NSBundle mainBundle].bundleIdentifier, anIdentifier]; + indentifier = [NSString stringWithFormat:@"%@.%@", SUBundleIdentifier, anIdentifier]; touchBarItems = [NSMutableArray arrayWithCapacity:6]; touchBar = [[NSTouchBar alloc] init]; From c059dc8ae8c7904fddce5de96dfacb0604ea75c0 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Wed, 11 Jan 2017 02:07:48 +0800 Subject: [PATCH 10/15] remove hardcoded array capacity --- Sparkle/SUTouchBarProvider.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUTouchBarProvider.m b/Sparkle/SUTouchBarProvider.m index fe092d26..04689465 100644 --- a/Sparkle/SUTouchBarProvider.m +++ b/Sparkle/SUTouchBarProvider.m @@ -30,7 +30,7 @@ return self; indentifier = [NSString stringWithFormat:@"%@.%@", SUBundleIdentifier, anIdentifier]; - touchBarItems = [NSMutableArray arrayWithCapacity:6]; + touchBarItems = [NSMutableArray array]; touchBar = [[NSTouchBar alloc] init]; touchBar.defaultItemIdentifiers = @[indentifier,]; From d5f4c312eee174e89210532119ec2ad4e06a8286 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Wed, 11 Jan 2017 23:11:02 +0800 Subject: [PATCH 11/15] Keep consistent coding style --- Sparkle.xcodeproj/project.pbxproj | 20 ++++----- Sparkle/SUAutomaticUpdateAlert.m | 20 ++++----- Sparkle/SUStatusController.m | 12 +++--- Sparkle/SUTouchBarBuilder.h | 25 +++++++++++ ...TouchBarProvider.m => SUTouchBarBuilder.m} | 43 ++++++++++--------- Sparkle/SUTouchBarProvider.h | 21 --------- Sparkle/SUUpdateAlert.m | 20 ++++----- Sparkle/SUUpdatePermissionPrompt.m | 14 +++--- 8 files changed, 89 insertions(+), 86 deletions(-) create mode 100644 Sparkle/SUTouchBarBuilder.h rename Sparkle/{SUTouchBarProvider.m => SUTouchBarBuilder.m} (58%) delete mode 100644 Sparkle/SUTouchBarProvider.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 5f1a7986..8a708f70 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -263,9 +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 /* SUTouchBarProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUTouchBarProvider.h */; }; - E1545EC61E1D7E0200FAECE8 /* SUTouchBarProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; - E1EC2A301E21667000245715 /* SUTouchBarProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1545EC51E1D7E0200FAECE8 /* SUTouchBarBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUTouchBarBuilder.h */; }; + E1545EC61E1D7E0200FAECE8 /* SUTouchBarBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1EC2A301E21667000245715 /* SUTouchBarBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.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 */; }; @@ -798,8 +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 /* SUTouchBarProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarProvider.h; sourceTree = ""; }; - E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarProvider.m; sourceTree = ""; }; + E1545EC31E1D7E0200FAECE8 /* SUTouchBarBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarBuilder.h; sourceTree = ""; }; + E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarBuilder.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 = ""; }; @@ -1180,8 +1180,8 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 7205C42F1E1215AD00E370AE /* SUUpdatePermissionResponse.h */, 7205C4301E1215AD00E370AE /* SUUpdatePermissionResponse.m */, - E1545EC31E1D7E0200FAECE8 /* SUTouchBarProvider.h */, - E1545EC41E1D7E0200FAECE8 /* SUTouchBarProvider.m */, + E1545EC31E1D7E0200FAECE8 /* SUTouchBarBuilder.h */, + E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.m */, ); name = "User Interface"; sourceTree = ""; @@ -1385,7 +1385,7 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, - E1545EC51E1D7E0200FAECE8 /* SUTouchBarProvider.h in Headers */, + E1545EC51E1D7E0200FAECE8 /* SUTouchBarBuilder.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, 722954C41D04E66F00ECF9CA /* SUFileOperationConstants.h in Headers */, @@ -1870,7 +1870,7 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, - E1EC2A301E21667000245715 /* SUTouchBarProvider.m in Sources */, + E1EC2A301E21667000245715 /* SUTouchBarBuilder.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2018,7 +2018,7 @@ 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */, - E1545EC61E1D7E0200FAECE8 /* SUTouchBarProvider.m in Sources */, + E1545EC61E1D7E0200FAECE8 /* SUTouchBarBuilder.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 2c11a6e9..d96d6a2f 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -11,7 +11,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUHost.h" -#import "SUTouchBarProvider.h" +#import "SUTouchBarBuilder.h" @interface SUAutomaticUpdateAlert () @property (strong) void(^completionBlock)(SUAutomaticInstallationChoice); @@ -21,7 +21,7 @@ @property (weak) IBOutlet NSButton *skipButton; @property (weak) IBOutlet NSButton *laterButton; @property (weak) IBOutlet NSButton *installButton; -@property (strong) SUTouchBarProvider *touchBarProvider; +@property (strong) SUTouchBarBuilder *touchBarBuilder; @end @implementation SUAutomaticUpdateAlert @@ -31,7 +31,7 @@ @synthesize skipButton; @synthesize laterButton; @synthesize installButton; -@synthesize touchBarProvider; +@synthesize touchBarBuilder; - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block { @@ -109,14 +109,12 @@ - (NSTouchBar *)makeTouchBar { - self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:self.skipButton isDefault:NO]; - [self.touchBarProvider addSpace]; - [self.touchBarProvider addButtonWithButton:self.laterButton isDefault:NO]; - [self.touchBarProvider addButtonWithButton:self.installButton isDefault:YES]; - [self.touchBarProvider addSpace]; - [self.touchBarProvider addSpace]; - return self.touchBarProvider.touchBar; + self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; + [self.touchBarBuilder addButtonUsingButton:self.skipButton isDefault:NO]; + [self.touchBarBuilder addSpace]; + [self.touchBarBuilder addButtonUsingButton:self.laterButton isDefault:NO]; + [self.touchBarBuilder addButtonUsingButton:self.installButton isDefault:YES]; + return self.touchBarBuilder.touchBar; } @end diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index aeb22499..74684598 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -11,13 +11,13 @@ #import "SUHost.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUTouchBarProvider.h" +#import "SUTouchBarBuilder.h" @interface SUStatusController () @property (copy) NSString *title, *buttonTitle; @property (strong) SUHost *host; @property NSButton *touchBarButton; -@property (strong) SUTouchBarProvider *touchBarProvider; +@property (strong) SUTouchBarBuilder *touchBarBuilder; @end @implementation SUStatusController @@ -31,7 +31,7 @@ @synthesize progressBar; @synthesize statusTextField; @synthesize touchBarButton; -@synthesize touchBarProvider; +@synthesize touchBarBuilder; - (instancetype)initWithHost:(SUHost *)aHost { @@ -134,9 +134,9 @@ - (NSTouchBar *)makeTouchBar { - self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - self.touchBarButton = [self.touchBarProvider addButtonWithButton:self.actionButton isDefault:[self.actionButton.keyEquivalent isEqualToString:@"\r"]]; - return self.touchBarProvider.touchBar; + self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; + self.touchBarButton = [self.touchBarBuilder addButtonUsingButton:self.actionButton isDefault:[self.actionButton.keyEquivalent isEqualToString:@"\r"]]; + return self.touchBarBuilder.touchBar; } @end diff --git a/Sparkle/SUTouchBarBuilder.h b/Sparkle/SUTouchBarBuilder.h new file mode 100644 index 00000000..12b17215 --- /dev/null +++ b/Sparkle/SUTouchBarBuilder.h @@ -0,0 +1,25 @@ +// +// SUTouchBarBuilder.h +// Sparkle +// +// Created by Yuxin Wang on 05/01/2017. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import + +@class NSTouchBar; + +NS_ASSUME_NONNULL_BEGIN + +@interface SUTouchBarBuilder : NSObject + +@property (strong, readonly) NSTouchBar *touchBar; + +- (instancetype)initWithIdentifier:(NSString *)identifier; +- (NSButton *)addButtonUsingButton:(NSButton *)button isDefault:(BOOL)isDefault; +- (void)addSpace; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUTouchBarProvider.m b/Sparkle/SUTouchBarBuilder.m similarity index 58% rename from Sparkle/SUTouchBarProvider.m rename to Sparkle/SUTouchBarBuilder.m index 04689465..b852a75f 100644 --- a/Sparkle/SUTouchBarProvider.m +++ b/Sparkle/SUTouchBarBuilder.m @@ -1,41 +1,41 @@ // -// SUTouchBarProvider.m +// SUTouchBarBuilder.m // Sparkle // // Created by Yuxin Wang on 05/01/2017. // Copyright © 2017 Sparkle Project. All rights reserved. // -#import "SUTouchBarProvider.h" +#import "SUTouchBarBuilder.h" #import "SUConstants.h" #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 -@interface SUTouchBarProvider() +@interface SUTouchBarBuilder() -@property (copy) NSString* indentifier; -@property NSMutableArray *touchBarItems; +@property (nonatomic, copy) NSString* indentifier; +@property (nonatomic) NSMutableArray *touchBarItems; @end -@implementation SUTouchBarProvider +@implementation SUTouchBarBuilder -@synthesize indentifier; -@synthesize touchBarItems; -@synthesize touchBar; +@synthesize indentifier = _indentifier; +@synthesize touchBarItems = _touchBarItems; +@synthesize touchBar = _touchBar; --(instancetype)initWithIdentifier:(NSString *)anIdentifier +- (instancetype)initWithIdentifier:(NSString *)anIdentifier { if (!(self = [super init])) return self; - indentifier = [NSString stringWithFormat:@"%@.%@", SUBundleIdentifier, anIdentifier]; - touchBarItems = [NSMutableArray array]; + _indentifier = [NSString stringWithFormat:@"%@.%@", SUBundleIdentifier, anIdentifier]; + _touchBarItems = [NSMutableArray array]; - touchBar = [[NSTouchBar alloc] init]; - touchBar.defaultItemIdentifiers = @[indentifier,]; - touchBar.principalItemIdentifier = indentifier; - touchBar.delegate = self; + _touchBar = [[NSTouchBar alloc] init]; + _touchBar.defaultItemIdentifiers = @[_indentifier,]; + _touchBar.principalItemIdentifier = _indentifier; + _touchBar.delegate = self; return self; } @@ -47,13 +47,16 @@ return nil; } --(NSButton *)addButtonWithButton:(NSButton *)button isDefault:(BOOL)isDefault +- (NSButton *)addButtonUsingButton:(NSButton *)button isDefault:(BOOL)isDefault { NSString *itemId = [self.indentifier stringByAppendingFormat:@".button-%lu", self.touchBarItems.count]; NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:itemId]; NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; buttonCopy.tag = button.tag; + + // A modal NSWindow may empty its default button's keyEquivalent when it shows. + // We have to set the default button explicitly. if (isDefault) { buttonCopy.keyEquivalent = @"\r"; } @@ -66,7 +69,7 @@ return buttonCopy; } --(void)addSpace +- (void)addSpace { NSTouchBarItem *item = [[NSTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierFixedSpaceLarge]; [self.touchBarItems addObject:item]; @@ -76,7 +79,7 @@ #else -@implementation SUTouchBarProvider +@implementation SUTouchBarBuilder @synthesize touchBar; @@ -84,7 +87,7 @@ return nil; } --(NSButton *)addButtonWithButton:(NSButton *)button { +-(NSButton *)addButtonUsingButton:(NSButton *)button isDefault:(BOOL)isDefault{ return nil; } diff --git a/Sparkle/SUTouchBarProvider.h b/Sparkle/SUTouchBarProvider.h deleted file mode 100644 index 11d4cba8..00000000 --- a/Sparkle/SUTouchBarProvider.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// SUTouchBarProvider.h -// Sparkle -// -// Created by Yuxin Wang on 05/01/2017. -// Copyright © 2017 Sparkle Project. All rights reserved. -// - -#import - -@class NSTouchBar; - -@interface SUTouchBarProvider : NSObject - -@property (strong, readonly) NSTouchBar *touchBar; - --(instancetype)initWithIdentifier:(NSString *)identifier; --(NSButton *)addButtonWithButton:(NSButton *)button isDefault:(BOOL)isDefault; --(void)addSpace; - -@end diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 60e0e9b2..a5cac196 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,7 +21,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUSystemUpdateInfo.h" -#import "SUTouchBarProvider.h" +#import "SUTouchBarBuilder.h" // WebKit protocols are not explicitly declared until 10.11 SDK, so // declare dummy protocols to keep the build working on earlier SDKs. @@ -48,7 +48,7 @@ @property (weak) IBOutlet NSButton *installButton; @property (weak) IBOutlet NSButton *skipButton; @property (weak) IBOutlet NSButton *laterButton; -@property (strong) SUTouchBarProvider *touchBarProvider; +@property (strong) SUTouchBarBuilder *touchBarBuilder; @end @@ -71,7 +71,7 @@ @synthesize skipButton; @synthesize laterButton; -@synthesize touchBarProvider; +@synthesize touchBarBuilder; - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block { @@ -326,14 +326,12 @@ - (NSTouchBar *)makeTouchBar { - self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:self.skipButton isDefault:NO]; - [self.touchBarProvider addSpace]; - [self.touchBarProvider addButtonWithButton:self.laterButton isDefault:NO]; - [self.touchBarProvider addButtonWithButton:self.installButton isDefault:YES]; - [self.touchBarProvider addSpace]; - [self.touchBarProvider addSpace]; - return self.touchBarProvider.touchBar; + self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; + [self.touchBarBuilder addButtonUsingButton:self.skipButton isDefault:NO]; + [self.touchBarBuilder addSpace]; + [self.touchBarBuilder addButtonUsingButton:self.laterButton isDefault:NO]; + [self.touchBarBuilder addButtonUsingButton:self.installButton isDefault:YES]; + return self.touchBarBuilder.touchBar; } @end diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index e236bf6d..437cea18 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -13,7 +13,7 @@ #import "SUConstants.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUTouchBarProvider.h" +#import "SUTouchBarBuilder.h" @interface SUUpdatePermissionPrompt () @@ -28,7 +28,7 @@ @property (weak) IBOutlet NSTableView *profileTableView; @property (weak) IBOutlet NSButton *cancelButton; @property (weak) IBOutlet NSButton *checkButton; -@property (strong) SUTouchBarProvider *touchBarProvider; +@property (strong) SUTouchBarBuilder *touchBarBuilder; @property (nonatomic, readonly) void (^reply)(SUUpdatePermissionResponse *); @@ -47,7 +47,7 @@ @synthesize profileTableView; @synthesize cancelButton; @synthesize checkButton; -@synthesize touchBarProvider; +@synthesize touchBarBuilder; - (BOOL)shouldAskAboutProfile { @@ -169,10 +169,10 @@ - (NSTouchBar *)makeTouchBar { - self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:self.cancelButton isDefault:NO]; - [self.touchBarProvider addButtonWithButton:self.checkButton isDefault:YES]; - return self.touchBarProvider.touchBar; + self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; + [self.touchBarBuilder addButtonUsingButton:self.cancelButton isDefault:NO]; + [self.touchBarBuilder addButtonUsingButton:self.checkButton isDefault:YES]; + return self.touchBarBuilder.touchBar; } @end From 6f11c1ce02bc34f3802b305c95f7d2571c7678b1 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Thu, 12 Jan 2017 03:44:01 +0800 Subject: [PATCH 12/15] Set up touch bar in each window controller --- Sparkle.xcodeproj/project.pbxproj | 20 +++--- Sparkle/SUAutomaticUpdateAlert.m | 26 +++++--- Sparkle/SUButtonGroupTouchBarItem.h | 22 +++++++ Sparkle/SUButtonGroupTouchBarItem.m | 44 +++++++++++++ Sparkle/SUStatusController.m | 24 +++++-- Sparkle/SUTouchBarBuilder.h | 25 -------- Sparkle/SUTouchBarBuilder.m | 99 ----------------------------- Sparkle/SUUpdateAlert.m | 27 ++++---- Sparkle/SUUpdatePermissionPrompt.m | 24 ++++--- 9 files changed, 141 insertions(+), 170 deletions(-) create mode 100644 Sparkle/SUButtonGroupTouchBarItem.h create mode 100644 Sparkle/SUButtonGroupTouchBarItem.m delete mode 100644 Sparkle/SUTouchBarBuilder.h delete mode 100644 Sparkle/SUTouchBarBuilder.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 8a708f70..e1259eb3 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -263,9 +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 /* SUTouchBarBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUTouchBarBuilder.h */; }; - E1545EC61E1D7E0200FAECE8 /* SUTouchBarBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; - E1EC2A301E21667000245715 /* SUTouchBarBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1545EC51E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h */; }; + E1545EC61E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + E1EC2A301E21667000245715 /* SUButtonGroupTouchBarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.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 */; }; @@ -798,8 +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 /* SUTouchBarBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarBuilder.h; sourceTree = ""; }; - E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarBuilder.m; sourceTree = ""; }; + E1545EC31E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUButtonGroupTouchBarItem.h; sourceTree = ""; }; + E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUButtonGroupTouchBarItem.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 = ""; }; @@ -1180,8 +1180,8 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 7205C42F1E1215AD00E370AE /* SUUpdatePermissionResponse.h */, 7205C4301E1215AD00E370AE /* SUUpdatePermissionResponse.m */, - E1545EC31E1D7E0200FAECE8 /* SUTouchBarBuilder.h */, - E1545EC41E1D7E0200FAECE8 /* SUTouchBarBuilder.m */, + E1545EC31E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h */, + E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m */, ); name = "User Interface"; sourceTree = ""; @@ -1385,7 +1385,7 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, - E1545EC51E1D7E0200FAECE8 /* SUTouchBarBuilder.h in Headers */, + E1545EC51E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, 722954C41D04E66F00ECF9CA /* SUFileOperationConstants.h in Headers */, @@ -1870,7 +1870,7 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, - E1EC2A301E21667000245715 /* SUTouchBarBuilder.m in Sources */, + E1EC2A301E21667000245715 /* SUButtonGroupTouchBarItem.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2018,7 +2018,7 @@ 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */, - E1545EC61E1D7E0200FAECE8 /* SUTouchBarBuilder.m in Sources */, + E1545EC61E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.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 d96d6a2f..e176131b 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -11,9 +11,11 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUHost.h" -#import "SUTouchBarBuilder.h" +#import "SUButtonGroupTouchBarItem.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; @@ -21,7 +23,6 @@ @property (weak) IBOutlet NSButton *skipButton; @property (weak) IBOutlet NSButton *laterButton; @property (weak) IBOutlet NSButton *installButton; -@property (strong) SUTouchBarBuilder *touchBarBuilder; @end @implementation SUAutomaticUpdateAlert @@ -31,7 +32,6 @@ @synthesize skipButton; @synthesize laterButton; @synthesize installButton; -@synthesize touchBarBuilder; - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block { @@ -109,12 +109,18 @@ - (NSTouchBar *)makeTouchBar { - self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; - [self.touchBarBuilder addButtonUsingButton:self.skipButton isDefault:NO]; - [self.touchBarBuilder addSpace]; - [self.touchBarBuilder addButtonUsingButton:self.laterButton isDefault:NO]; - [self.touchBarBuilder addButtonUsingButton:self.installButton isDefault:YES]; - return self.touchBarBuilder.touchBar; + 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]) + return [SUButtonGroupTouchBarItem itemWithIndentifier:SUAutomaticUpdateAlertTouchBarIndentifier usingButtons:@[self.installButton, self.laterButton, self.skipButton]]; + return nil; } @end diff --git a/Sparkle/SUButtonGroupTouchBarItem.h b/Sparkle/SUButtonGroupTouchBarItem.h new file mode 100644 index 00000000..34b15246 --- /dev/null +++ b/Sparkle/SUButtonGroupTouchBarItem.h @@ -0,0 +1,22 @@ +// +// SUButtonGroupTouchBarItem.h +// Sparkle +// +// Created by Yuxin Wang on 05/01/2017. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import + +@class NSTouchBar; +@class NSTouchBarItem; + +NS_ASSUME_NONNULL_BEGIN + +@interface SUButtonGroupTouchBarItem : NSTouchBarItem + ++ (NSTouchBarItem *)itemWithIndentifier:(NSString *)indentifier usingButtons:(NSArray *)buttons; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUButtonGroupTouchBarItem.m b/Sparkle/SUButtonGroupTouchBarItem.m new file mode 100644 index 00000000..6799c917 --- /dev/null +++ b/Sparkle/SUButtonGroupTouchBarItem.m @@ -0,0 +1,44 @@ +// +// SUButtonGroupTouchBarItem.m +// Sparkle +// +// Created by Yuxin Wang on 05/01/2017. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import "SUButtonGroupTouchBarItem.h" +#import "SUConstants.h" + +@implementation SUButtonGroupTouchBarItem + ++ (NSTouchBarItem *)itemWithIndentifier:(NSString *)indentifier usingButtons:(NSArray *)buttons +{ + NSMutableArray *touchBarItems = [NSMutableArray arrayWithCapacity:buttons.count + 1]; + + for (NSUInteger i = 0; i < buttons.count; i++) { + if (i == 2) { + NSTouchBarItem *item = [[NSTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierFixedSpaceLarge]; + [touchBarItems insertObject:item atIndex:0]; + } + NSButton *button = buttons[i]; + NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; + buttonCopy.tag = button.tag; + + if (i == 0) { + buttonCopy.keyEquivalent = @"\r"; + } + + [buttonCopy bind:@"title" toObject:button withKeyPath:@"title" options:nil]; + [buttonCopy bind:@"enabled" toObject:button withKeyPath:@"enabled" options:nil]; + + NSString *itemId = [indentifier stringByAppendingFormat:@".button-%lu", i]; + NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:itemId]; + item.view = buttonCopy; + [touchBarItems insertObject:item atIndex:0]; + } + + return [NSGroupTouchBarItem groupItemWithIdentifier:indentifier items:touchBarItems]; +} + +@end + diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index 74684598..05b2469b 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -11,13 +11,14 @@ #import "SUHost.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUTouchBarBuilder.h" +#import "SUButtonGroupTouchBarItem.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; -@property (strong) SUTouchBarBuilder *touchBarBuilder; @end @implementation SUStatusController @@ -31,7 +32,6 @@ @synthesize progressBar; @synthesize statusTextField; @synthesize touchBarButton; -@synthesize touchBarBuilder; - (instancetype)initWithHost:(SUHost *)aHost { @@ -132,11 +132,21 @@ [self.progressBar setUsesThreadedAnimation:YES]; } + - (NSTouchBar *)makeTouchBar { - self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; - self.touchBarButton = [self.touchBarBuilder addButtonUsingButton:self.actionButton isDefault:[self.actionButton.keyEquivalent isEqualToString:@"\r"]]; - return self.touchBarBuilder.touchBar; + 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]) + return [SUButtonGroupTouchBarItem itemWithIndentifier:SUStatusControllerTouchBarIndentifier usingButtons:@[self.actionButton,]]; + return nil; } @end diff --git a/Sparkle/SUTouchBarBuilder.h b/Sparkle/SUTouchBarBuilder.h deleted file mode 100644 index 12b17215..00000000 --- a/Sparkle/SUTouchBarBuilder.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// SUTouchBarBuilder.h -// Sparkle -// -// Created by Yuxin Wang on 05/01/2017. -// Copyright © 2017 Sparkle Project. All rights reserved. -// - -#import - -@class NSTouchBar; - -NS_ASSUME_NONNULL_BEGIN - -@interface SUTouchBarBuilder : NSObject - -@property (strong, readonly) NSTouchBar *touchBar; - -- (instancetype)initWithIdentifier:(NSString *)identifier; -- (NSButton *)addButtonUsingButton:(NSButton *)button isDefault:(BOOL)isDefault; -- (void)addSpace; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUTouchBarBuilder.m b/Sparkle/SUTouchBarBuilder.m deleted file mode 100644 index b852a75f..00000000 --- a/Sparkle/SUTouchBarBuilder.m +++ /dev/null @@ -1,99 +0,0 @@ -// -// SUTouchBarBuilder.m -// Sparkle -// -// Created by Yuxin Wang on 05/01/2017. -// Copyright © 2017 Sparkle Project. All rights reserved. -// - -#import "SUTouchBarBuilder.h" -#import "SUConstants.h" - -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 - -@interface SUTouchBarBuilder() - -@property (nonatomic, copy) NSString* indentifier; -@property (nonatomic) NSMutableArray *touchBarItems; - -@end - -@implementation SUTouchBarBuilder - -@synthesize indentifier = _indentifier; -@synthesize touchBarItems = _touchBarItems; -@synthesize touchBar = _touchBar; - -- (instancetype)initWithIdentifier:(NSString *)anIdentifier -{ - if (!(self = [super init])) - return self; - - _indentifier = [NSString stringWithFormat:@"%@.%@", SUBundleIdentifier, anIdentifier]; - _touchBarItems = [NSMutableArray array]; - - _touchBar = [[NSTouchBar alloc] init]; - _touchBar.defaultItemIdentifiers = @[_indentifier,]; - _touchBar.principalItemIdentifier = _indentifier; - _touchBar.delegate = self; - - return self; -} - -- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier -{ - if ([identifier isEqualToString:self.indentifier]) - return [NSGroupTouchBarItem groupItemWithIdentifier:self.indentifier items:self.touchBarItems]; - return nil; -} - -- (NSButton *)addButtonUsingButton:(NSButton *)button isDefault:(BOOL)isDefault -{ - NSString *itemId = [self.indentifier stringByAppendingFormat:@".button-%lu", self.touchBarItems.count]; - NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:itemId]; - - NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; - buttonCopy.tag = button.tag; - - // A modal NSWindow may empty its default button's keyEquivalent when it shows. - // We have to set the default button explicitly. - if (isDefault) { - buttonCopy.keyEquivalent = @"\r"; - } - - [buttonCopy bind:@"title" toObject:button withKeyPath:@"title" options:nil]; - [buttonCopy bind:@"enabled" toObject:button withKeyPath:@"enabled" options:nil]; - - item.view = buttonCopy; - [self.touchBarItems addObject:item]; - return buttonCopy; -} - -- (void)addSpace -{ - NSTouchBarItem *item = [[NSTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierFixedSpaceLarge]; - [self.touchBarItems addObject:item]; -} - -@end - -#else - -@implementation SUTouchBarBuilder - -@synthesize touchBar; - --(instancetype)initWithIdentifier:(NSString *)identifier { - return nil; -} - --(NSButton *)addButtonUsingButton:(NSButton *)button isDefault:(BOOL)isDefault{ - return nil; -} - --(void)addSpace { -} - -@end - -#endif diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index a5cac196..82586daf 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,7 +21,9 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUSystemUpdateInfo.h" -#import "SUTouchBarBuilder.h" +#import "SUButtonGroupTouchBarItem.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 +34,7 @@ @end #endif -@interface SUUpdateAlert () +@interface SUUpdateAlert () @property (strong) SUAppcastItem *updateItem; @property (strong) SUHost *host; @@ -48,7 +50,6 @@ @property (weak) IBOutlet NSButton *installButton; @property (weak) IBOutlet NSButton *skipButton; @property (weak) IBOutlet NSButton *laterButton; -@property (strong) SUTouchBarBuilder *touchBarBuilder; @end @@ -71,8 +72,6 @@ @synthesize skipButton; @synthesize laterButton; -@synthesize touchBarBuilder; - - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block { self = [super initWithWindowNibName:@"SUUpdateAlert"]; @@ -326,12 +325,18 @@ - (NSTouchBar *)makeTouchBar { - self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; - [self.touchBarBuilder addButtonUsingButton:self.skipButton isDefault:NO]; - [self.touchBarBuilder addSpace]; - [self.touchBarBuilder addButtonUsingButton:self.laterButton isDefault:NO]; - [self.touchBarBuilder addButtonUsingButton:self.installButton isDefault:YES]; - return self.touchBarBuilder.touchBar; + 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]) + return [SUButtonGroupTouchBarItem itemWithIndentifier:SUUpdateAlertTouchBarIndentifier usingButtons:@[self.installButton, self.laterButton, self.skipButton]]; + return nil; } @end diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 437cea18..7552a2c8 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -13,9 +13,11 @@ #import "SUConstants.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUTouchBarBuilder.h" +#import "SUButtonGroupTouchBarItem.h" -@interface SUUpdatePermissionPrompt () +static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdatePermissionPrompt"; + +@interface SUUpdatePermissionPrompt () @property (assign) BOOL isShowingMoreInfo; @property (assign) BOOL shouldSendProfile; @@ -28,7 +30,6 @@ @property (weak) IBOutlet NSTableView *profileTableView; @property (weak) IBOutlet NSButton *cancelButton; @property (weak) IBOutlet NSButton *checkButton; -@property (strong) SUTouchBarBuilder *touchBarBuilder; @property (nonatomic, readonly) void (^reply)(SUUpdatePermissionResponse *); @@ -47,7 +48,6 @@ @synthesize profileTableView; @synthesize cancelButton; @synthesize checkButton; -@synthesize touchBarBuilder; - (BOOL)shouldAskAboutProfile { @@ -169,10 +169,18 @@ - (NSTouchBar *)makeTouchBar { - self.touchBarBuilder = [[SUTouchBarBuilder alloc] initWithIdentifier:self.className]; - [self.touchBarBuilder addButtonUsingButton:self.cancelButton isDefault:NO]; - [self.touchBarBuilder addButtonUsingButton:self.checkButton isDefault:YES]; - return self.touchBarBuilder.touchBar; + 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]) + return [SUButtonGroupTouchBarItem itemWithIndentifier:SUUpdatePermissionPromptTouchBarIndentifier usingButtons:@[self.checkButton, self.cancelButton]]; + return nil; } @end From 118c72e61cb26234dd480ffe40187fd58b8c41e6 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Fri, 13 Jan 2017 01:22:33 +0800 Subject: [PATCH 13/15] Add touch bar button group view to replace NSGroupTouchBarItem --- Sparkle.xcodeproj/project.pbxproj | 20 +++++----- Sparkle/SUAutomaticUpdateAlert.m | 9 +++-- Sparkle/SUButtonGroupTouchBarItem.h | 22 ----------- Sparkle/SUButtonGroupTouchBarItem.m | 44 ---------------------- Sparkle/SUStatusController.m | 13 +++++-- Sparkle/SUTouchBarButtonGroup.h | 25 +++++++++++++ Sparkle/SUTouchBarButtonGroup.m | 58 +++++++++++++++++++++++++++++ Sparkle/SUUpdateAlert.m | 9 +++-- Sparkle/SUUpdatePermissionPrompt.m | 9 +++-- 9 files changed, 121 insertions(+), 88 deletions(-) delete mode 100644 Sparkle/SUButtonGroupTouchBarItem.h delete mode 100644 Sparkle/SUButtonGroupTouchBarItem.m create mode 100644 Sparkle/SUTouchBarButtonGroup.h create mode 100644 Sparkle/SUTouchBarButtonGroup.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index e1259eb3..28ff1914 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -263,9 +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 /* SUButtonGroupTouchBarItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E1545EC31E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h */; }; - E1545EC61E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; - E1EC2A301E21667000245715 /* SUButtonGroupTouchBarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m */; settings = {COMPILER_FLAGS = "-Wno-partial-availability"; }; }; + 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 */; }; @@ -798,8 +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 /* SUButtonGroupTouchBarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUButtonGroupTouchBarItem.h; sourceTree = ""; }; - E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUButtonGroupTouchBarItem.m; 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 = ""; }; @@ -1180,8 +1180,8 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 7205C42F1E1215AD00E370AE /* SUUpdatePermissionResponse.h */, 7205C4301E1215AD00E370AE /* SUUpdatePermissionResponse.m */, - E1545EC31E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h */, - E1545EC41E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.m */, + E1545EC31E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h */, + E1545EC41E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m */, ); name = "User Interface"; sourceTree = ""; @@ -1385,7 +1385,7 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, - E1545EC51E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.h in Headers */, + E1545EC51E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, 722954C41D04E66F00ECF9CA /* SUFileOperationConstants.h in Headers */, @@ -1870,7 +1870,7 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, - E1EC2A301E21667000245715 /* SUButtonGroupTouchBarItem.m in Sources */, + E1EC2A301E21667000245715 /* SUTouchBarButtonGroup.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2018,7 +2018,7 @@ 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */, - E1545EC61E1D7E0200FAECE8 /* SUButtonGroupTouchBarItem.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 e176131b..c5fc0ed9 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -11,7 +11,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUHost.h" -#import "SUButtonGroupTouchBarItem.h" +#import "SUTouchBarButtonGroup.h" static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUAutomaticUpdateAlert"; @@ -118,8 +118,11 @@ static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_B - (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { - if ([identifier isEqualToString:SUAutomaticUpdateAlertTouchBarIndentifier]) - return [SUButtonGroupTouchBarItem itemWithIndentifier:SUAutomaticUpdateAlertTouchBarIndentifier usingButtons:@[self.installButton, self.laterButton, self.skipButton]]; + 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; } diff --git a/Sparkle/SUButtonGroupTouchBarItem.h b/Sparkle/SUButtonGroupTouchBarItem.h deleted file mode 100644 index 34b15246..00000000 --- a/Sparkle/SUButtonGroupTouchBarItem.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// SUButtonGroupTouchBarItem.h -// Sparkle -// -// Created by Yuxin Wang on 05/01/2017. -// Copyright © 2017 Sparkle Project. All rights reserved. -// - -#import - -@class NSTouchBar; -@class NSTouchBarItem; - -NS_ASSUME_NONNULL_BEGIN - -@interface SUButtonGroupTouchBarItem : NSTouchBarItem - -+ (NSTouchBarItem *)itemWithIndentifier:(NSString *)indentifier usingButtons:(NSArray *)buttons; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUButtonGroupTouchBarItem.m b/Sparkle/SUButtonGroupTouchBarItem.m deleted file mode 100644 index 6799c917..00000000 --- a/Sparkle/SUButtonGroupTouchBarItem.m +++ /dev/null @@ -1,44 +0,0 @@ -// -// SUButtonGroupTouchBarItem.m -// Sparkle -// -// Created by Yuxin Wang on 05/01/2017. -// Copyright © 2017 Sparkle Project. All rights reserved. -// - -#import "SUButtonGroupTouchBarItem.h" -#import "SUConstants.h" - -@implementation SUButtonGroupTouchBarItem - -+ (NSTouchBarItem *)itemWithIndentifier:(NSString *)indentifier usingButtons:(NSArray *)buttons -{ - NSMutableArray *touchBarItems = [NSMutableArray arrayWithCapacity:buttons.count + 1]; - - for (NSUInteger i = 0; i < buttons.count; i++) { - if (i == 2) { - NSTouchBarItem *item = [[NSTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierFixedSpaceLarge]; - [touchBarItems insertObject:item atIndex:0]; - } - NSButton *button = buttons[i]; - NSButton *buttonCopy = [NSButton buttonWithTitle:button.title target:button.target action:button.action]; - buttonCopy.tag = button.tag; - - if (i == 0) { - buttonCopy.keyEquivalent = @"\r"; - } - - [buttonCopy bind:@"title" toObject:button withKeyPath:@"title" options:nil]; - [buttonCopy bind:@"enabled" toObject:button withKeyPath:@"enabled" options:nil]; - - NSString *itemId = [indentifier stringByAppendingFormat:@".button-%lu", i]; - NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:itemId]; - item.view = buttonCopy; - [touchBarItems insertObject:item atIndex:0]; - } - - return [NSGroupTouchBarItem groupItemWithIdentifier:indentifier items:touchBarItems]; -} - -@end - diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index 05b2469b..f4f8bc04 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -11,7 +11,7 @@ #import "SUHost.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUButtonGroupTouchBarItem.h" +#import "SUTouchBarButtonGroup.h" static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUStatusController"; @@ -144,8 +144,15 @@ static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDL - (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { - if ([identifier isEqualToString:SUStatusControllerTouchBarIndentifier]) - return [SUButtonGroupTouchBarItem itemWithIndentifier:SUStatusControllerTouchBarIndentifier usingButtons:@[self.actionButton,]]; + 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; } 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..88b72cf2 --- /dev/null +++ b/Sparkle/SUTouchBarButtonGroup.m @@ -0,0 +1,58 @@ +// +// 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 new]; + 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]]; + } + 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 82586daf..78a01647 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,7 +21,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUSystemUpdateInfo.h" -#import "SUButtonGroupTouchBarItem.h" +#import "SUTouchBarButtonGroup.h" static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdateAlert"; @@ -334,8 +334,11 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { - if ([identifier isEqualToString:SUUpdateAlertTouchBarIndentifier]) - return [SUButtonGroupTouchBarItem itemWithIndentifier:SUUpdateAlertTouchBarIndentifier usingButtons:@[self.installButton, self.laterButton, self.skipButton]]; + 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; } diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 7552a2c8..9f2802a6 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -13,7 +13,7 @@ #import "SUConstants.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" -#import "SUButtonGroupTouchBarItem.h" +#import "SUTouchBarButtonGroup.h" static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdatePermissionPrompt"; @@ -178,8 +178,11 @@ static NSString *const SUUpdatePermissionPromptTouchBarIndentifier = @"" SPARKLE - (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { - if ([identifier isEqualToString:SUUpdatePermissionPromptTouchBarIndentifier]) - return [SUButtonGroupTouchBarItem itemWithIndentifier:SUUpdatePermissionPromptTouchBarIndentifier usingButtons:@[self.checkButton, self.cancelButton]]; + if ([identifier isEqualToString:SUUpdatePermissionPromptTouchBarIndentifier]) { + NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + item.viewController = [[SUTouchBarButtonGroup alloc] initByReferencingButtons:@[self.checkButton, self.cancelButton]]; + return item; + } return nil; } From e2426784ac2611be8e089b368a7c4b4da4092b29 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Fri, 13 Jan 2017 01:35:09 +0800 Subject: [PATCH 14/15] Add constrains to set touch bar buttons width equally --- Sparkle/SUTouchBarButtonGroup.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUTouchBarButtonGroup.m b/Sparkle/SUTouchBarButtonGroup.m index 88b72cf2..ab02bbd2 100644 --- a/Sparkle/SUTouchBarButtonGroup.m +++ b/Sparkle/SUTouchBarButtonGroup.m @@ -19,8 +19,8 @@ NSView *buttonGroup = [NSView new]; self.view = buttonGroup; - NSMutableArray *constraints = [NSMutableArray array]; - NSMutableArray *buttonCopies = [NSMutableArray arrayWithCapacity:buttons.count]; + NSMutableArray *constraints = [NSMutableArray array]; + NSMutableArray *buttonCopies = [NSMutableArray arrayWithCapacity:buttons.count]; for (NSUInteger i = 0; i < buttons.count; i++) { NSButton *button = buttons[i]; @@ -43,6 +43,8 @@ [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]]; From 65bd11df8a61aae627cfdaff76cb751a9e1111ea Mon Sep 17 00:00:00 2001 From: Bi11 Date: Fri, 13 Jan 2017 20:33:41 +0800 Subject: [PATCH 15/15] =?UTF-8?q?Use=20NSView=E2=80=99s=20designated=20ini?= =?UTF-8?q?tializer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sparkle/SUTouchBarButtonGroup.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUTouchBarButtonGroup.m b/Sparkle/SUTouchBarButtonGroup.m index ab02bbd2..3a56046e 100644 --- a/Sparkle/SUTouchBarButtonGroup.m +++ b/Sparkle/SUTouchBarButtonGroup.m @@ -17,7 +17,7 @@ if (!(self = [super init])) return self; - NSView *buttonGroup = [NSView new]; + NSView *buttonGroup = [[NSView alloc] initWithFrame:NSZeroRect]; self.view = buttonGroup; NSMutableArray *constraints = [NSMutableArray array]; NSMutableArray *buttonCopies = [NSMutableArray arrayWithCapacity:buttons.count];