Permalink
Browse files

Relaunch the helper after a successful update.

  • Loading branch information...
1 parent 9589180 commit 2f30b4bf6007acd2e5e0750d49c664359540b163 @victorpimentel committed Nov 27, 2011
Showing with 43 additions and 5 deletions.
  1. +2 −0 Classes/PreferencesController.m
  2. +1 −0 Classes/TVShowsHelper.h
  3. +14 −1 Classes/TVShowsHelper.m
  4. +26 −4 Relaunch.m
@@ -397,7 +397,9 @@ - (void) loadLaunchAgent
[aTask setLaunchPath:@"/bin/launchctl"];
[aTask setArguments:[NSArray arrayWithObjects:@"load",@"-w",[self launchAgentPath],nil]];
[aTask launch];
+ #if PREFPANE
[aTask waitUntilExit];
+ #endif
[aTask release];
}
@@ -68,5 +68,6 @@
#pragma mark -
#pragma mark Sparkle Delegate Methods
- (void) updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update;
+- (void) updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update;
@end
@@ -892,7 +892,7 @@ - (IBAction) showFeedback:(id)sender
- (IBAction) quitHelper:(id)sender
{
- [[[PreferencesController new] autorelease] enabledControlDidChange:NO];
+ [[[[PreferencesController alloc] init] autorelease] enabledControlDidChange:NO];
[NSApp terminate];
}
@@ -930,6 +930,19 @@ - (void) updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update
}
}
+- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update
+{
+ // Relaunch the TVShows Helper :)
+ NSString *daemonPath = [[NSBundle bundleWithIdentifier: TVShowsAppDomain] pathForResource:@"relaunch" ofType:nil];
+ NSString *launchAgentPath = [[[[PreferencesController alloc] init] autorelease] launchAgentPath];
+
+ [NSTask launchedTaskWithLaunchPath:daemonPath
+ arguments:[NSArray arrayWithObjects:launchAgentPath, @"",
+ [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]];
+
+ LogInfo(@"Relaunching TVShows Helper after the successful update.");
+}
+
- (void) dealloc
{
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
View
@@ -14,11 +14,26 @@
#import <Cocoa/Cocoa.h>
#import "TVShows_Prefix.pch"
+#import "AppInfoConstants.h"
// Thanks to Matt Patenaude and his blog post on how to relaunch an application.
-// Slightly modified to work with a Preference Pane.
+// Slightly modified to work with a Preference Pane and a Launch Helper.
// http://iloveco.de/relaunching-your-application/
+void relaunchHelper(NSString *launchAgentPath)
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSTask *aTask = [[NSTask alloc] init];
+ [aTask setLaunchPath:@"/bin/launchctl"];
+ [aTask setArguments:[NSArray arrayWithObjects:@"load",@"-w",launchAgentPath,nil]];
+ [aTask launch];
+ [aTask waitUntilExit];
+ [aTask release];
+
+ [pool drain];
+}
+
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -30,12 +45,19 @@ int main(int argc, char *argv[])
NSString *appPath = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
NSString *prefPath = [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding];
- BOOL success = [[NSWorkspace sharedWorkspace] openFile:[prefPath stringByExpandingTildeInPath]
- withApplication:[appPath stringByExpandingTildeInPath]];
+ BOOL success = NO;
+
+ if (prefPath.length == 0) {
+ relaunchHelper(appPath);
+ success = YES;
+ } else {
+ success = [[NSWorkspace sharedWorkspace] openFile:[prefPath stringByExpandingTildeInPath]
+ withApplication:[appPath stringByExpandingTildeInPath]];
+ }
if (!success)
NSLog(@"Could not relaunch application at %@", appPath);
[pool drain];
return (success) ? 0 : 1;
-}
+}

0 comments on commit 2f30b4b

Please sign in to comment.