diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-11-29 21:25:52 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-11-29 21:25:52 +0000 |
commit | c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7 (patch) | |
tree | f3b1a2864fbead4c7810303eb60b83b2457d677e /Source/SPAppController.m | |
parent | cef5a0200f433e53bd27b2516e5ac269205f0420 (diff) | |
download | sequelpro-c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7.tar.gz sequelpro-c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7.tar.bz2 sequelpro-c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7.zip |
• Bundle commands
- register running commands for each SPDatabaseDocument or if the command runs via 'General' for NSApp delegate
- kill all running commands before SP will be terminated
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r-- | Source/SPAppController.m | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 55eb4e17..12b9e9a4 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -57,6 +57,7 @@ bundleUsedScopes = [[NSMutableArray alloc] initWithCapacity:1]; bundleKeyEquivalents = [[NSMutableDictionary alloc] initWithCapacity:1]; installedBundleUUIDs = [[NSMutableDictionary alloc] initWithCapacity:1]; + runningBASHprocesses = [[NSMutableArray alloc] init]; [NSApp setDelegate:self]; } @@ -780,7 +781,7 @@ return; } - NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; + NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil callerDocument:self withName:([cmdData objectForKey:SPBundleFileNameKey])?[cmdData objectForKey:SPBundleFileNameKey]:@"" error:&err]; [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; @@ -831,6 +832,26 @@ } +- (void)registerBASHCommand:(NSDictionary*)commandDict +{ + [runningBASHprocesses addObject:commandDict]; +} + +- (void)unRegisterBASHCommand:(NSInteger)pid +{ + for(id cmd in runningBASHprocesses) { + if([[cmd objectForKey:@"pid"] integerValue] == pid) { + [runningBASHprocesses removeObject:cmd]; + break; + } + } +} + +- (NSArray*)runningBASHProcesses +{ + return (NSArray*)runningBASHprocesses; +} + #pragma mark - #pragma mark Window management @@ -1507,6 +1528,41 @@ } } +/** + * If Sequel Pro is terminating kill all running BASH scripts + */ +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender +{ + + // Kill all registered BASH commands + for (NSWindow *aWindow in [NSApp orderedWindows]) { + if([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) { + for(SPDatabaseDocument *doc in [[aWindow windowController] documents]) { + for(NSDictionary* cmd in [doc runningBASHProcesses]) { + NSInteger pid = [[cmd objectForKey:@"pid"] intValue]; + NSTask *killTask = [[NSTask alloc] init]; + [killTask setLaunchPath:@"/bin/sh"]; + [killTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"kill -9 -%ld", pid], nil]]; + [killTask launch]; + [killTask waitUntilExit]; + [killTask release]; + } + } + } + } + for(NSDictionary* cmd in [self runningBASHProcesses]) { + NSInteger pid = [[cmd objectForKey:@"pid"] intValue]; + NSTask *killTask = [[NSTask alloc] init]; + [killTask setLaunchPath:@"/bin/sh"]; + [killTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"kill -9 -%ld", pid], nil]]; + [killTask launch]; + [killTask waitUntilExit]; + [killTask release]; + } + return YES; + +} + #pragma mark - /** @@ -1521,6 +1577,7 @@ if(bundleCategories) [bundleCategories release]; if(bundleKeyEquivalents) [bundleKeyEquivalents release]; if(installedBundleUUIDs) [installedBundleUUIDs release]; + if (runningBASHprocesses) [runningBASHprocesses release]; [prefsController release], prefsController = nil; |