From ece2b2e642e13064998fc3069f19b91536b46263 Mon Sep 17 00:00:00 2001 From: Marcus Ososbase Date: Wed, 22 Feb 2017 18:55:41 -0500 Subject: [PATCH] Rebased fork on upstream --- Sparkle/SUAutomaticUpdateDriver.m | 13 +++++----- Sparkle/SUUIBasedUpdateDriver.m | 26 +------------------- Sparkle/SUUpdater.h | 37 ----------------------------- Sparkle/SUUpdater.m | 3 ++- Sparkle/SUUpdaterDelegate.h | 32 +++++++++++++++++++++++++ generate_appcast/DSASignature.swift | 20 ++++++++-------- 6 files changed, 52 insertions(+), 79 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 8b9e2810..56a2fbae 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -46,12 +46,13 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)showUpdateAlert { - id updaterDelegate = [self.updater delegate]; - if ([updaterDelegate suppressSparkleUI]) - { - [self automaticUpdateAlertFinishedWithChoice:SUInstallLaterChoice]; - return; - } + id updater = self.updater; + id updaterDelegate = [updater delegate]; + if ([updaterDelegate suppressSparkleUI]) + { + [self automaticUpdateAlertFinishedWithChoice:SUInstallLaterChoice]; + return; + } // NSLog(@"[Sparkle showUpdateAlert]"); self.interruptible = NO; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 6404421b..bfe74ff4 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -69,30 +69,6 @@ else if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { [[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem]; } - -// self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) { -// [self updateAlertFinishedWithChoice:choice]; -// }]; -// -// id versDisp = nil; -// if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { -// versDisp = [[updater delegate] versionDisplayerForUpdater:self.updater]; -// } -// [self.updateAlert setVersionDisplayer:versDisp]; -// -// // If the app is a menubar app or the like, we need to focus it first and alter the -// // update prompt to behave like a normal window. Otherwise if the window were hidden -// // there may be no way for the application to be activated to make it visible again. -// if ([self.host isBackgroundApplication]) { -// [[self.updateAlert window] setHidesOnDeactivate:NO]; -// [NSApp activateIgnoringOtherApps:YES]; -// } - - // Only show the update alert if the app is active; otherwise, we'll wait until it is. -// if ([NSApp isActive]) -// [[self.updateAlert window] makeKeyAndOrderFront:self]; -// else -// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } - (BOOL)shouldDisableKeyboardShortcutForInstallButton { @@ -151,7 +127,7 @@ - (void)downloadUpdate { id updater = self.updater; - if(![[updater delegate] suppressUI]) + if(![[updater delegate] suppressSparkleUI]) { BOOL createdStatusController = NO; if (self.statusController == nil) { diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index bee72acc..95647290 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -18,13 +18,6 @@ #import "SUVersionComparisonProtocol.h" #import "SUVersionDisplayProtocol.h" -typedef NS_ENUM(NSInteger, SUDUpdateAlertChoice) { - SUDInstallUpdateChoice, - SUDRemindMeLaterChoice, - SUDSkipThisVersionChoice, - SUDOpenInfoURLChoice -}; - @class SUAppcastItem, SUAppcast; @protocol SUUpdaterDelegate; @@ -66,14 +59,6 @@ SU_EXPORT @interface SUUpdater : NSObject */ -(BOOL)suppressSparkleUI; - -/*! - Suppress sparkle UI. This should prevent any Sparkle UI from popping up. - Updates should be handled by the host. - */ --(BOOL)suppressSparkleUI; - - /*! Explicitly checks for updates and displays a progress dialog while doing so. @@ -126,16 +111,6 @@ SU_EXPORT @interface SUUpdater : NSObject */ @property BOOL automaticallyDownloadsUpdates; -/*! - Called when a valid update is found by the update driver and provides delegate ability to respond. - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that is proposed to be installed. - \param responseBlock The block carrying the users response to update. -*/ -- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item respondWithChoice:(void (^)(SUDUpdateAlertChoice))responseBlock; - - /*! A property indicating the current automatic update check interval. @@ -260,18 +235,6 @@ SU_EXPORT @interface SUUpdater : NSObject */ @property (readonly, copy) NSDate *lastUpdateCheckDate; - -/*! - Called when an update is scheduled to be silently installed on quit. Swift compatible. - - \param updater the SUUpdater instance. - \param item The appcast item corresponding to the udpate that is proposed to be installed. - \param restartBlock Can be used to trigger an immediate silent install and relaunch. -*/ -- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)()) restartBlock; - - - /*! Appropriately schedules or cancels the update checking timer according to the preferences for time interval and automatic checks. diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 4a1a539a..2cf22912 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -10,6 +10,7 @@ #import "SUUpdaterDelegate.h" #import "SUUpdaterPrivate.h" +#import "SUErrors.h" #import "SUHost.h" #import "SUUpdatePermissionResponse.h" #import "SUUpdatePermissionPrompt.h" @@ -291,7 +292,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUHostDirectoryNotWritable userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"Host directory is not writable", nil)}]; - [self.delegate updater:nil didAbortWithError:error]; + [self.delegate updater:self didAbortWithError:error]; } return; } diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 39249ac4..1fc02673 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -14,6 +14,13 @@ #import "SUExport.h" +typedef NS_ENUM(NSInteger, SUDUpdateAlertChoice) { + SUDInstallUpdateChoice, + SUDRemindMeLaterChoice, + SUDSkipThisVersionChoice, + SUDOpenInfoURLChoice +}; + @protocol SUVersionComparison, SUVersionDisplay; @class SUUpdater, SUAppcast, SUAppcastItem; @@ -45,6 +52,12 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; @protocol SUUpdaterDelegate @optional +/*! + Suppress sparkle UI. This should prevent any Sparkle UI from popping up. + Updates should be handled by the host. + */ +-(BOOL)suppressSparkleUI; + /*! Returns whether to allow Sparkle to pop up. @@ -121,6 +134,16 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item; +/*! + Called when a valid update is found by the update driver and provides delegate ability to respond. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + \param responseBlock The block carrying the users response to update. + */ +- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item respondWithChoice:(void (^)(SUDUpdateAlertChoice))responseBlock; + + /*! Called when a valid update is not found. @@ -253,6 +276,15 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation; +/*! + Called when an update is scheduled to be silently installed on quit. Swift compatible. + + \param updater the SUUpdater instance. + \param item The appcast item corresponding to the udpate that is proposed to be installed. + \param restartBlock Can be used to trigger an immediate silent install and relaunch. + */ +- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)()) restartBlock; + /*! Calls after an update that was scheduled to be silently installed on quit has been canceled. diff --git a/generate_appcast/DSASignature.swift b/generate_appcast/DSASignature.swift index 1f46a251..2f9dc845 100644 --- a/generate_appcast/DSASignature.swift +++ b/generate_appcast/DSASignature.swift @@ -7,48 +7,48 @@ import Foundation func loadPrivateKey(privateKeyPath: URL) throws -> SecKey { let data = try Data(contentsOf: privateKeyPath); - + var cfitems: CFArray? = nil; var format = SecExternalFormat.formatOpenSSL; var type = SecExternalItemType.itemTypePrivateKey; - + let status = SecItemImport(data as CFData, nil, &format, &type, SecItemImportExportFlags(rawValue: UInt32(0)), nil, nil, &cfitems); if (status != errSecSuccess || cfitems == nil) { print("Private DSA key could not be imported", status); throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil); } - + if (format != SecExternalFormat.formatOpenSSL || type != SecExternalItemType.itemTypePrivateKey) { throw makeError(code: .signatureError, "Not an OpensSSL private key \(format) \(type)"); } - + return (cfitems as! NSArray)[0] as! SecKey; } func dsaSignature(path: URL, privateKey: SecKey) throws -> String { - + var error: Unmanaged?; - + let stream = InputStream(fileAtPath:path.path)!; let dataReadTransform = SecTransformCreateReadTransformWithReadStream(stream); - + let dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, 20, nil); guard let dataSignTransform = SecSignTransformCreate(privateKey, &error) else { print("can't use the key"); throw error!.takeRetainedValue(); } - + let group = SecTransformCreateGroupTransform(); SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error); if (error != nil) { throw error!.takeRetainedValue(); } - + SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataSignTransform, kSecTransformInputAttributeName, group, &error); if (error != nil) { throw error!.takeRetainedValue(); } - + let result = SecTransformExecute(group, &error) as! Data; return result.base64EncodedString(); }