Skip to content

Commit

Permalink
Add PFMoveIsInProgress method to work around applicationShouldTermina…
Browse files Browse the repository at this point in the history
…teAfterLastWindowClosed issue
  • Loading branch information
cstigler committed Jul 14, 2017
1 parent ff2fada commit 2d2318e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion PFMoveApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ extern "C" {
#endif

void PFMoveToApplicationsFolderIfNecessary(void);

BOOL PFMoveIsInProgress();

#ifdef __cplusplus
}
#endif
14 changes: 13 additions & 1 deletion PFMoveApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@


static NSString *AlertSuppressKey = @"moveToApplicationsFolderAlertSuppress";

static BOOL MoveInProgress = NO;

// Helper functions
static NSString *PreferredInstallLocation(BOOL *isUserDirectory);
Expand Down Expand Up @@ -70,6 +70,9 @@ void PFMoveToApplicationsFolderIfNecessary(void) {
// unless it's inside another app's bundle.
if (IsInApplicationsFolder(bundlePath) && !isNestedApplication) return;

// OK, looks like we'll need to do a move - set the status variable appropriately
MoveInProgress = YES;

// File Manager
NSFileManager *fm = [NSFileManager defaultManager];

Expand Down Expand Up @@ -141,6 +144,7 @@ void PFMoveToApplicationsFolderIfNecessary(void) {
if (!AuthorizedInstall(bundlePath, destinationPath, &authorizationCanceled)) {
if (authorizationCanceled) {
NSLog(@"INFO -- Not moving because user canceled authorization");
MoveInProgress = NO;
return;
}
else {
Expand All @@ -157,6 +161,7 @@ void PFMoveToApplicationsFolderIfNecessary(void) {
// Give the running app focus and terminate myself
NSLog(@"INFO -- Switching to an already running version");
[[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:[NSArray arrayWithObject:destinationPath]] waitUntilExit];
MoveInProgress = NO;
exit(0);
}
else {
Expand Down Expand Up @@ -189,13 +194,15 @@ void PFMoveToApplicationsFolderIfNecessary(void) {
[NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:[NSArray arrayWithObjects:@"-c", script, nil]];
}

MoveInProgress = NO;
exit(0);
}
// Save the alert suppress preference if checked
else if ([[alert suppressionButton] state] == NSOnState) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:AlertSuppressKey];
}

MoveInProgress = NO;
return;

fail:
Expand All @@ -204,9 +211,14 @@ void PFMoveToApplicationsFolderIfNecessary(void) {
alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:kStrMoveApplicationCouldNotMove];
[alert runModal];
MoveInProgress = NO;
}
}

BOOL PFMoveIsInProgress() {
return MoveInProgress;
}

#pragma mark -
#pragma mark Helper Functions

Expand Down

0 comments on commit 2d2318e

Please sign in to comment.