mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Handle app termination in the user driver
If an automatic update needs to be applied at termination, the app delegate will need to hold responsibility of delaying termination until Sparkle is ready to relaunch
This commit is contained in:
1 parent
5a60ddaf8c
commit
0e97f0b4b6
6 files changed
+57
-28
No files matched your search
Vendored
-16
@@ -26,7 +26,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
@property (assign) BOOL postponingInstallation;
|
||||
@property (assign) BOOL showErrors;
|
||||
@property (assign) BOOL willUpdateOnTermination;
|
||||
@property (assign) BOOL isTerminating;
|
||||
@property (strong) NSTimer *showUpdateAlertTimer;
|
||||
|
||||
@end
|
||||
@@ -36,7 +35,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
@synthesize postponingInstallation;
|
||||
@synthesize showErrors;
|
||||
@synthesize willUpdateOnTermination;
|
||||
@synthesize isTerminating;
|
||||
@synthesize showUpdateAlertTimer;
|
||||
|
||||
- (void)showUpdateAlert
|
||||
@@ -51,12 +49,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
[self.updater.userUpdaterDriver registerForAppTermination:^{
|
||||
// We don't want to terminate the app if the user or someone else initiated a termination
|
||||
// Use a property instead of passing an argument to installWithToolAndRelaunch:
|
||||
// because we give the delegate an invocation to our install methods and
|
||||
// this code was added later :|
|
||||
self.isTerminating = YES;
|
||||
|
||||
[self installWithToolAndRelaunch:NO];
|
||||
}];
|
||||
|
||||
@@ -122,7 +114,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
|
||||
- (void)abortUpdate
|
||||
{
|
||||
self.isTerminating = NO;
|
||||
[self stopUpdatingOnTermination];
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
|
||||
@@ -171,13 +162,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
}]];
|
||||
}
|
||||
|
||||
- (void)terminateApp
|
||||
{
|
||||
if (!self.isTerminating) {
|
||||
[super terminateApp];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
if (self.showErrors) {
|
||||
|
||||
Vendored
+1
-7
@@ -544,13 +544,7 @@
|
||||
// Note: this is overridden by the automatic update driver to not terminate in some cases
|
||||
- (void)terminateApp
|
||||
{
|
||||
for (NSRunningApplication *runningApplication in [[NSWorkspace sharedWorkspace] runningApplications]) {
|
||||
if ([runningApplication.bundleURL.path isEqual:self.host.bundlePath]) {
|
||||
[runningApplication terminate];
|
||||
}
|
||||
}
|
||||
|
||||
[NSApp terminate:self];
|
||||
[self.updater.userUpdaterDriver terminateApplication];
|
||||
}
|
||||
|
||||
- (void)cleanUpDownload
|
||||
|
||||
Vendored
+5
@@ -13,6 +13,11 @@
|
||||
|
||||
@interface SUSparkleUserUpdaterDriver : NSObject <SUUserUpdaterDriver>
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host handlesTermination:(BOOL)handlesTermination;
|
||||
- (instancetype)initWithHost:(SUHost *)host;
|
||||
|
||||
@property (nonatomic, readonly, getter = isInstallingOnTermination) BOOL installingOnTermination;
|
||||
|
||||
- (void)sendTerminationSignalWithCompletion:(void (^)(void))finishTermination;
|
||||
|
||||
@end
|
||||
Vendored
+43
-3
@@ -34,6 +34,7 @@
|
||||
@interface SUSparkleUserUpdaterDriver ()
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, readonly) BOOL handlesTermination;
|
||||
|
||||
@property (nonatomic) SUStatusController *checkingController;
|
||||
@property (nonatomic, copy) void (^cancelUpdateCheck)(void);
|
||||
@@ -45,12 +46,14 @@
|
||||
@property (nonatomic, copy) void (^installAndRestart)(void);
|
||||
|
||||
@property (nonatomic, copy) void (^applicationWillTerminate)(void);
|
||||
@property (nonatomic, copy) void (^finishTermination)(void);
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUSparkleUserUpdaterDriver
|
||||
|
||||
@synthesize host = _host;
|
||||
@synthesize handlesTermination = _handlesTermination;
|
||||
@synthesize checkingController = _checkingController;
|
||||
@synthesize cancelUpdateCheck = _cancelUpdateCheck;
|
||||
@synthesize activeUpdateAlert = _activeUpdateAlert;
|
||||
@@ -58,16 +61,23 @@
|
||||
@synthesize cancelDownload = _cancelDownload;
|
||||
@synthesize installAndRestart = _installAndRestart;
|
||||
@synthesize applicationWillTerminate = _applicationWillTerminate;
|
||||
@synthesize finishTermination = _finishTermination;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host
|
||||
- (instancetype)initWithHost:(SUHost *)host handlesTermination:(BOOL)handlesTermination
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_host = host;
|
||||
_handlesTermination = handlesTermination;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host
|
||||
{
|
||||
return [self initWithHost:host handlesTermination:YES];
|
||||
}
|
||||
|
||||
- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@@ -332,7 +342,9 @@
|
||||
|
||||
self.applicationWillTerminate = applicationWillTerminate;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
|
||||
if (self.handlesTermination) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -341,18 +353,46 @@
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSProcessInfo processInfo] enableSuddenTermination];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
|
||||
if (self.handlesTermination) {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
|
||||
}
|
||||
|
||||
self.applicationWillTerminate = nil;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)__unused note
|
||||
{
|
||||
// Pass an empty block instead of nil to indicate the app
|
||||
// has already initiated termination
|
||||
[self sendTerminationSignalWithCompletion:^{}];
|
||||
}
|
||||
|
||||
- (BOOL)isInstallingOnTermination
|
||||
{
|
||||
return (self.applicationWillTerminate != nil);
|
||||
}
|
||||
|
||||
- (void)sendTerminationSignalWithCompletion:(void (^)(void))finishTermination
|
||||
{
|
||||
self.finishTermination = finishTermination;
|
||||
|
||||
if (self.applicationWillTerminate) {
|
||||
self.applicationWillTerminate();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)terminateApplication
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.finishTermination) {
|
||||
self.finishTermination();
|
||||
} else {
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)dismissUpdateInstallation
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
Vendored
+1
@@ -44,6 +44,7 @@
|
||||
|
||||
- (void)registerForAppTermination:(void (^)(void))applicationWillTerminate;
|
||||
- (void)unregisterForAppTermination;
|
||||
- (void)terminateApplication;
|
||||
|
||||
- (void)dismissUpdateInstallation;
|
||||
|
||||
|
||||
@@ -129,6 +129,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)terminateApplication
|
||||
{
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
|
||||
- (void)dismissUpdateInstallation
|
||||
{
|
||||
NSLog(@"Dismissing the installation.");
|
||||
@@ -148,8 +153,8 @@
|
||||
|
||||
- (void)windowDidLoad
|
||||
{
|
||||
//self.updater.userUpdaterDriver = [[SUSparkleUserUpdaterDriver alloc] initWithHost:[[SUHost alloc] initWithBundle:[NSBundle mainBundle]]];
|
||||
self.updater.userUpdaterDriver = [[SULoggerUpdateDriver alloc] init];
|
||||
self.updater.userUpdaterDriver = [[SUSparkleUserUpdaterDriver alloc] initWithHost:[[SUHost alloc] initWithBundle:[NSBundle mainBundle]]];
|
||||
//self.updater.userUpdaterDriver = [[SULoggerUpdateDriver alloc] init];
|
||||
}
|
||||
|
||||
- (NSString *)windowNibName
|
||||
|
||||
Reference in new issue
Block a user