This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
RARunningAppsProvider.xm
75 lines (58 loc) · 1.82 KB
/
RARunningAppsProvider.xm
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
70
71
72
73
74
75
#import "RARunningAppsProvider.h"
@implementation RARunningAppsProvider
+(instancetype) sharedInstance
{
SHARED_INSTANCE2(RARunningAppsProvider,
sharedInstance->apps = [NSMutableArray array];
sharedInstance->targets = [NSMutableArray array];
sharedInstance->lock = [[NSLock alloc] init];
);
}
-(void) addRunningApp:(__unsafe_unretained SBApplication*)app
{
[lock lock];
[apps addObject:app];
for (NSObject<RARunningAppsProviderDelegate>* target in targets)
if ([target respondsToSelector:@selector(appDidStart:)])
dispatch_async(dispatch_get_main_queue(), ^{
[target appDidStart:app];
});
[lock unlock];
}
-(void) removeRunningApp:(__unsafe_unretained SBApplication*)app
{
[lock lock];
[apps removeObject:app];
for (NSObject<RARunningAppsProviderDelegate>* target in targets)
if ([target respondsToSelector:@selector(appDidDie:)])
dispatch_async(dispatch_get_main_queue(), ^{
[target appDidDie:app];
});
[lock unlock];
}
-(void) addTarget:(__weak NSObject<RARunningAppsProviderDelegate>*)target
{
[lock lock];
if ([targets containsObject:target] == NO)
[targets addObject:target];
[lock unlock];
}
-(void) removeTarget:(__weak NSObject<RARunningAppsProviderDelegate>*)target
{
[lock lock];
[targets removeObject:target];
[lock unlock];
}
-(NSArray*) runningApplications { return apps; }
-(NSMutableArray*) mutableRunningApplications { return apps; }
@end
%hook SBApplication
- (void)updateProcessState:(unsafe_id)arg1
{
%orig;
if (self.isRunning && [RARunningAppsProvider.sharedInstance.mutableRunningApplications containsObject:self] == NO)
[RARunningAppsProvider.sharedInstance addRunningApp:self];
else if (!self.isRunning && [RARunningAppsProvider.sharedInstance.mutableRunningApplications containsObject:self])
[RARunningAppsProvider.sharedInstance removeRunningApp:self];
}
%end