mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Allow delegate to decide how to proceed with new update
This commit is contained in:
1 parent
48e3a4277e
commit
17c51da8af
2 files changed
+74
-46
No files matched your search
Vendored
+48
-46
@@ -59,41 +59,39 @@
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
|
||||
[[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:respondWithChoice:)]) {
|
||||
[[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem respondWithChoice:^(SUDUpdateAlertChoice choice) {
|
||||
[self updateAlertFinishedWithChoice:(SUUpdateAlertChoice)choice];
|
||||
}];
|
||||
|
||||
return;
|
||||
}
|
||||
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<SUVersionDisplay> 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];
|
||||
}
|
||||
|
||||
if (self.automaticallyInstallUpdates) {
|
||||
[self updateAlertFinishedWithChoice:SUInstallUpdateChoice];
|
||||
return;
|
||||
}
|
||||
|
||||
// self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) {
|
||||
// [self updateAlertFinishedWithChoice:choice];
|
||||
// }];
|
||||
//
|
||||
// id<SUVersionDisplay> 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 ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) {
|
||||
// [[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]) {
|
||||
// NSWindow *window = [self.updateAlert window];
|
||||
// if ([self shouldDisableKeyboardShortcutForInstallButton]) {
|
||||
// [self.updateAlert disableKeyboardShortcutForInstallButton];
|
||||
// }
|
||||
// [window makeKeyAndOrderFront:self];
|
||||
// } else
|
||||
// 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];
|
||||
}
|
||||
|
||||
@@ -135,7 +133,7 @@
|
||||
break;
|
||||
|
||||
case SUOpenInfoURLChoice:
|
||||
[[NSWorkspace sharedWorkspace] openURL:[self.updateItem infoURL]];
|
||||
[[NSWorkspace sharedWorkspace] openURL:[self.updateItem releaseNotesURL]];
|
||||
[self abortUpdate];
|
||||
break;
|
||||
|
||||
@@ -152,18 +150,22 @@
|
||||
|
||||
- (void)downloadUpdate
|
||||
{
|
||||
BOOL createdStatusController = NO;
|
||||
if (self.statusController == nil) {
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
||||
createdStatusController = YES;
|
||||
}
|
||||
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
|
||||
[self.statusController setButtonEnabled:YES];
|
||||
|
||||
if (createdStatusController) {
|
||||
[self.statusController showWindow:self];
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
if(![[updater delegate] suppressUI])
|
||||
{
|
||||
BOOL createdStatusController = NO;
|
||||
if (self.statusController == nil) {
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
||||
createdStatusController = YES;
|
||||
}
|
||||
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
|
||||
[self.statusController setButtonEnabled:YES];
|
||||
|
||||
if (createdStatusController) {
|
||||
[self.statusController showWindow:self];
|
||||
}
|
||||
}
|
||||
|
||||
[super downloadUpdate];
|
||||
|
||||
Vendored
+26
@@ -18,6 +18,13 @@
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUVersionDisplayProtocol.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, SUDUpdateAlertChoice) {
|
||||
SUDInstallUpdateChoice,
|
||||
SUDRemindMeLaterChoice,
|
||||
SUDSkipThisVersionChoice,
|
||||
SUDOpenInfoURLChoice
|
||||
};
|
||||
|
||||
@class SUAppcastItem, SUAppcast;
|
||||
|
||||
@protocol SUUpdaterDelegate;
|
||||
@@ -53,6 +60,9 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
*/
|
||||
- (instancetype)initForBundle:(NSBundle *)bundle;
|
||||
|
||||
|
||||
@property (nonatomic) BOOL suppressUI;
|
||||
|
||||
/*!
|
||||
Explicitly checks for updates and displays a progress dialog while doing so.
|
||||
|
||||
@@ -117,7 +127,23 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
/*!
|
||||
Begins a "probing" check for updates which will not actually offer to
|
||||
update to that version.
|
||||
|
||||
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.
|
||||
|
||||
\param updater The SUUpdater instance.
|
||||
*/
|
||||
- (void)updaterDidNotFindUpdate:(SUUpdater *)updater;
|
||||
|
||||
/*!
|
||||
However, the delegate methods
|
||||
SUUpdaterDelegate::updater:didFindValidUpdate: and
|
||||
SUUpdaterDelegate::updaterDidNotFindUpdate: will be called,
|
||||
|
||||
Reference in new issue
Block a user