From dbbcc4144a7abef479ae9982563ed3a1cbdb725c Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 6 Dec 2010 08:58:38 +0000 Subject: =?UTF-8?q?=E2=80=A2=20finished=20implementation=20of=20SPChooseMe?= =?UTF-8?q?nuItemDialog=20=E2=80=A2=20simplified=20bundle=20command=20hand?= =?UTF-8?q?ling=20and=20handling=20for=20bundle=20commands=20which=20have?= =?UTF-8?q?=20the=20same=20key=20equivalent=20to=20be=20able=20to=20group?= =?UTF-8?q?=20similar=20bundle=20commands=20=E2=80=A2=20minor=20code=20imp?= =?UTF-8?q?rovements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPActivityTextFieldCell.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Source/SPActivityTextFieldCell.m') diff --git a/Source/SPActivityTextFieldCell.m b/Source/SPActivityTextFieldCell.m index 5bdfa96e..f97101b4 100644 --- a/Source/SPActivityTextFieldCell.m +++ b/Source/SPActivityTextFieldCell.m @@ -239,18 +239,26 @@ static inline NSRect SPTextLinkRectFromCellRect(NSRect inRect) // Remove highlight, and follow the link [cancelButton highlight:NO withFrame:linkRect inView:controlView]; + NSInteger status = 0; + // Cancel activity if([contextInfo objectForKey:@"type"] && [[contextInfo objectForKey:@"type"] isEqualToString:@"bashcommand"]) { NSInteger pid = [[contextInfo objectForKey:@"pid"] intValue]; if(pid > 0) { NSTask *killTask = [[NSTask alloc] init]; [killTask setLaunchPath:@"/bin/sh"]; - [killTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"kill -9 -%ld", pid], nil]]; + // [killTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"kill -9 -%ld", pid], nil]]; + [killTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"[[ `ps -ax | egrep '%ld.*%@' | wc -l` -eq \"4\" ]] && kill -9 -%ld 2&> /tmp/sp_kill_error.txt", pid, SPBundleTaskScriptCommandFilePath, pid], nil]]; [killTask launch]; [killTask waitUntilExit]; + status = [killTask terminationStatus]; [killTask release]; } } + // Remove it from the list directly since the list will be updated in the background + // to avoid to cancel a command which is already cancelled + if(status == 0) + [[[controlView delegate] onMainThread] removeActivity:[[contextInfo objectForKey:@"pid"] intValue]]; return YES; } -- cgit v1.2.3