From 9c0ccd4a575124f4e7e054f89e5ad00bc409c50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 28 Dec 2016 16:06:14 +0100 Subject: [PATCH 1/7] Put latest version first to make wildcard filename matching easier --- generate_appcast/Appcast.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate_appcast/Appcast.swift b/generate_appcast/Appcast.swift index 65f042bf..889d8188 100644 --- a/generate_appcast/Appcast.swift +++ b/generate_appcast/Appcast.swift @@ -65,7 +65,7 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey) throws -> [String:[ continue; } - let deltaBaseName = appBaseName + item.version + "-" + latestItem.version; + let deltaBaseName = appBaseName + latestItem.version + "-" + item.version; let deltaPath = archivesSourceDir.appendingPathComponent(deltaBaseName).appendingPathExtension("delta"); var delta:DeltaUpdate; From 271d504f6d1ed06f5d340e35c90a325322cffb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 28 Dec 2016 16:06:24 +0100 Subject: [PATCH 2/7] Expose magic numbers --- generate_appcast/Appcast.swift | 5 ++++- generate_appcast/FeedXML.swift | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/generate_appcast/Appcast.swift b/generate_appcast/Appcast.swift index 889d8188..407ebc0e 100644 --- a/generate_appcast/Appcast.swift +++ b/generate_appcast/Appcast.swift @@ -5,6 +5,9 @@ import Foundation +// Maximum number of delta updates (per OS). +let maxDeltas = 5; + func makeError(code: SUError, _ description: String) -> NSError { return NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(code.rawValue)), userInfo: [ NSLocalizedDescriptionKey: description, @@ -84,7 +87,7 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey) throws -> [String:[ if delta.fileSize / 7 < latestItem.fileSize / 8 { // Max 3 deltas per version (arbitrary limit to reduce amount of work) numDeltas += 1; - if numDeltas > 3 { + if numDeltas > maxDeltas { break; } diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index 6e6ae6ea..099fc82f 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -5,6 +5,8 @@ import Foundation +let maxVersionsInFeed = 5; + func findElement(name: String, parent: XMLElement) -> XMLElement? { if let found = try? parent.nodes(forXPath: name) { if found.count > 0 { @@ -79,7 +81,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { let createNewItem = existingItems.count == 0; // Update all old items, but aim for less than 5 in new feeds - if createNewItem && numItems >= 5 { + if createNewItem && numItems >= maxVersionsInFeed { continue; } numItems += 1; From dc1151a5ffaa2aa9d05168086832e7337373f937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 3 Jan 2017 16:13:15 +0000 Subject: [PATCH 3/7] Null warning --- TestApplication/SUTestApplicationDelegate.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TestApplication/SUTestApplicationDelegate.m b/TestApplication/SUTestApplicationDelegate.m index 10929a4b..39812ce0 100644 --- a/TestApplication/SUTestApplicationDelegate.m +++ b/TestApplication/SUTestApplicationDelegate.m @@ -155,8 +155,10 @@ static NSString * const UPDATED_VERSION = @"2.0"; // Copy our appcast over to the server directory NSURL *appcastDestinationURL = [[serverDirectoryURL URLByAppendingPathComponent:appcastName] URLByAppendingPathExtension:appcastExtension]; + NSURL *appcastPath = [mainBundle URLForResource:appcastName withExtension:appcastExtension]; + assert(appcastPath); NSError *copyAppcastError = nil; - if (![fileManager copyItemAtURL:[mainBundle URLForResource:appcastName withExtension:appcastExtension] toURL:appcastDestinationURL error:©AppcastError]) { + if (![fileManager copyItemAtURL:appcastPath toURL:appcastDestinationURL error:©AppcastError]) { NSLog(@"Failed to copy appcast into cache directory with error %@", copyAppcastError); assert(NO); } From 8fa136c0a36cb6f1908bdbbd874c271ffd92b1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 3 Jan 2017 16:29:39 +0000 Subject: [PATCH 4/7] Invalidate timer when auto-update window is shown In case it's shown manually, not by the timer --- Sparkle/SUAutomaticUpdateDriver.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 9ae7eb1e..ab825ffc 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -49,6 +49,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)showUpdateAlert { self.interruptible = NO; + [self invalidateShowUpdateAlertTimer]; self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { [self automaticUpdateAlertFinishedWithChoice:choice]; }]; From 49845d82460dcc5484922194cf601be7eeeb40f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 3 Jan 2017 16:30:03 +0000 Subject: [PATCH 5/7] Re-init alert when called again A lazy way to bring it to front --- Sparkle/SUAutomaticUpdateDriver.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index ab825ffc..f5cb6047 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -50,6 +50,11 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 { self.interruptible = NO; [self invalidateShowUpdateAlertTimer]; + + if (self.alert) { + [self.alert close]; + } + self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { [self automaticUpdateAlertFinishedWithChoice:choice]; }]; From 6181c9276ac51aaac5dab3f0f2d065ba421e0332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 3 Jan 2017 16:30:19 +0000 Subject: [PATCH 6/7] Close alert on abort --- Sparkle/SUAutomaticUpdateDriver.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index f5cb6047..10198963 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -146,6 +146,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)abortUpdate { + [self.alert close]; + self.isTerminating = NO; [self stopUpdatingOnTermination]; [self invalidateShowUpdateAlertTimer]; @@ -160,6 +162,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)automaticUpdateAlertFinishedWithChoice:(SUAutomaticInstallationChoice)choice { + self.alert = nil; switch (choice) { case SUInstallNowChoice: From 2be4dc11a0d8218ba7de4b67612e952eee61c4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 3 Jan 2017 17:40:57 +0000 Subject: [PATCH 7/7] Resume pending automatic update when possible Fixes #970 --- Sparkle/SUAutomaticUpdateDriver.m | 8 ++++++++ Sparkle/SUUpdateDriver.h | 3 ++- Sparkle/SUUpdateDriver.m | 3 +++ Sparkle/SUUpdater.m | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 10198963..46817b1c 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -113,6 +113,14 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } } +-(BOOL)resumeUpdateInteractively { + if ([self isInterruptible]) { + [self showUpdateAlert]; + return YES; + } + return NO; +} + - (void)stopUpdatingOnTermination { if (self.willUpdateOnTermination) diff --git a/Sparkle/SUUpdateDriver.h b/Sparkle/SUUpdateDriver.h index 7e132aa1..ab03781d 100644 --- a/Sparkle/SUUpdateDriver.h +++ b/Sparkle/SUUpdateDriver.h @@ -26,7 +26,8 @@ extern NSString *const SUUpdateDriverFinishedNotification; - (instancetype)initWithUpdater:(id)updater; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (void)abortUpdate; - +/** If there is an update waiting to be installed, show UI indicating so. Return NO otherwise (e.g. if it's not supported). */ +- (BOOL)resumeUpdateInteractively; - (void)showAlert:(NSAlert *)alert; @property (getter=isInterruptible, readonly) BOOL interruptible; diff --git a/Sparkle/SUUpdateDriver.m b/Sparkle/SUUpdateDriver.m index 0aed1dfe..f83d2355 100644 --- a/Sparkle/SUUpdateDriver.m +++ b/Sparkle/SUUpdateDriver.m @@ -52,6 +52,9 @@ NSString *const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdateDriverFinishedNotification object:self]; } +-(BOOL)resumeUpdateInteractively { + return NO; +} - (void)showAlert:(NSAlert *)alert { // Only UI-based subclass shows the actual alert diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index bd2e5a2b..7794db19 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -291,6 +291,9 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (IBAction)checkForUpdates:(id)__unused sender { if (self.driver && [self.driver isInterruptible]) { + if ([self.driver resumeUpdateInteractively]) { + return; + } [self.driver abortUpdate]; } @@ -305,6 +308,9 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (void)installUpdatesIfAvailable { if (self.driver && [self.driver isInterruptible]) { + if ([self.driver resumeUpdateInteractively]) { + return; + } [self.driver abortUpdate]; }