From e24212f7976a45ef11b06300607ba34103799cf3 Mon Sep 17 00:00:00 2001 From: Dmytro Tretiakov Date: Wed, 30 Jul 2014 16:59:30 +0300 Subject: [PATCH] Add possibility to check update is in progress. --- SUUpdater.h | 2 ++ SUUpdater.m | 14 ++++++++++++++ finish_installation.m | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/SUUpdater.h b/SUUpdater.h index 1dd77a7d..e04bc641 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -73,6 +73,8 @@ - (BOOL)updateInProgress; +- (BOOL)isUpdateInProgress; + @end diff --git a/SUUpdater.m b/SUUpdater.m index 31f88d24..5d441d7f 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -44,6 +44,20 @@ static NSMutableDictionary *sharedUpdaters = nil; static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; + +- (BOOL)isUpdateInProgress +{ + BOOL result = NO; + NSConnection *connection = [NSConnection connectionWithRegisteredName:[NSString stringWithFormat:@"Sparkle %@", [[host bundle] bundleIdentifier]] host:nil]; + if (connection != nil) + { + NSDistantObject *proxyBundle = [connection rootProxy]; + result = proxyBundle != nil; + } + + return result; +} + + (SUUpdater *)sharedUpdater { return [self updaterForBundle:[NSBundle mainBundle]]; diff --git a/finish_installation.m b/finish_installation.m index 216fd8cb..582c15f4 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -32,6 +32,8 @@ - (void) relaunch; - (void) install; +- (SUHost *) host; + - (void) showAppIconInDock:(NSTimer *)aTimer; - (void) watchdog:(NSTimer *)aTimer; @@ -174,6 +176,11 @@ selfPath: (NSString*)inSelfPath alreadyInstalled:(BOOL)inalreadyInstalled exit(EXIT_FAILURE); } +- (SUHost *) host +{ + return host; +} + @end int main (int argc, const char * argv[]) @@ -201,13 +208,22 @@ int main (int argc, const char * argv[]) #endif [NSApplication sharedApplication]; - [[[TerminationListener alloc] initWithHostPath: (argc > 1) ? argv[1] : NULL + + NSConnection *connection = [[[NSConnection alloc] init] autorelease]; + TerminationListener *listener = [[[TerminationListener alloc] initWithHostPath: (argc > 1) ? argv[1] : NULL executablePath: (argc > 2) ? argv[2] : NULL parentProcessId: (argc > 3) ? atoi(argv[3]) : 0 folderPath: (argc > 4) ? argv[4] : NULL shouldRelaunch: (argc > 5) ? atoi(argv[5]) : 1 selfPath: selfPath alreadyInstalled: (argc > 6) ? atoi(argv[6]) : 0] autorelease]; + + [connection setRootObject:listener]; + if (![connection registerName:[NSString stringWithFormat:@"Sparkle %@", [[[listener host] bundle] bundleIdentifier]]]) + { + NSLog(@"%s server: could not register server. Is one already running?\n", argv[0]); + } + [[NSApplication sharedApplication] run]; [pool drain];