-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathQSPatchPlugIn.m
69 lines (55 loc) · 2.13 KB
/
QSPatchPlugIn.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// QSPatchPlugIn.m
// QSPatchPlugIn
//
// Created by Nicholas Jitkoff on 5/16/07.
// Copyright Blacktree 2007. All rights reserved.
//
#import "QSPatchPlugIn.h"
#import "NSEvent+BLTRExtensions.h"
@implementation QSProcessMonitor (Patch)
+ (void)initialize {
NSLog(@"Using QSProcessMonitor Patch");
}
- (NSDictionary *)infoForPSN:(ProcessSerialNumber)processSerialNumber {
NSDictionary *dict = (NSDictionary *)ProcessInformationCopyDictionary(&processSerialNumber,kProcessDictionaryIncludeAllInformationMask);
dict = [[[dict autorelease] mutableCopy] autorelease];
[dict setValue:[dict objectForKey:@"CFBundleName"]
forKey:@"NSApplicationName"];
[dict setValue:[dict objectForKey:@"BundlePath"]
forKey:@"NSApplicationPath"];
[dict setValue:[dict objectForKey:@"CFBundleIdentifier"]
forKey:@"NSApplicationBundleIdentifier"];
[dict setValue:[dict objectForKey:@"pid"]
forKey:@"NSApplicationProcessIdentifier"];
[dict setValue:[NSNumber numberWithLong:processSerialNumber.highLongOfPSN]
forKey:@"NSApplicationProcessSerialNumberHigh"];
[dict setValue:[NSNumber numberWithLong:processSerialNumber.lowLongOfPSN]
forKey:@"NSApplicationProcessSerialNumberLow"];
return dict;
}
- (BOOL)handleProcessEvent:(NSEvent *)theEvent{
ProcessSerialNumber psn;
psn.highLongOfPSN=[theEvent data1];
psn.lowLongOfPSN=[theEvent data2];
NSDictionary *processInfo = [self infoForPSN:psn];
switch ([theEvent subtype]){
case NSProcessDidLaunchSubType:
if (![[NSUserDefaults standardUserDefaults]boolForKey:@"QSShowBackgroundProcesses"]) return YES;
BOOL background=[[processInfo objectForKey:@"LSUIElement"]boolValue]||[[processInfo objectForKey:@"LSBackgroundOnly"]boolValue];
if (!background) return YES;
[self addProcessWithDict: processInfo];
break;
case NSProcessDidTerminateSubType:
[self removeProcessWithPSN:psn];
break;
case NSFrontProcessSwitched:
[[NSNotificationCenter defaultCenter] postNotificationName:@"QSActiveApplicationChanged" object: processInfo];
[self appChanged:nil];
break;
default:
break;
}
return YES;
};
@end