-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotifake.x
89 lines (63 loc) · 3.24 KB
/
Notifake.x
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#import "Notifake.h"
#import "libactivator-headers/libactivator.h"
static BOOL isDelayedNotificationEnabled = NO;
static NSString* SCtext = nil;
static NSString *bundleID = @"com.apple.Preferences";
static NSString *title = @"";
static NSString *content = @"";
static void __notifake_remote_log(NSString *text) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
RLog(@"%@: %@", dateString, text);
}
static void loadPrefs()
{
NSDictionary *prefs = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"dr.erast.notifakepreferences"];
if(prefs)
{
__notifake_remote_log(@"Preference changed!");
isDelayedNotificationEnabled = [([prefs objectForKey:@"enableDelayedNotification"] ?: @(false)) boolValue];
bundleID = [prefs objectForKey:@"selectedAppID"];
title = [prefs objectForKey: @"NTFNotificationTitle"];
content = [prefs objectForKey: @"NTFNotificationContent"];
}
__notifake_remote_log([NSString stringWithFormat: @"Title: %@\nContent: %@\nBundle: %@", title, content, bundleID]);
}
static void showNotif() {
__notifake_remote_log(@"Trigger!");
loadPrefs();
if (isDelayedNotificationEnabled) {
[[objc_getClass("JBBulletinManager") sharedInstance] showBulletinWithTitle:title
message:content
bundleID:bundleID];
}
__notifake_remote_log([NSString stringWithFormat: @"Title: %@\nContent: %@\nBundle: %@", title, content, bundleID]);
}
@interface NotifActivatorListener : NSObject<LAListener>
@end
@implementation NotifActivatorListener
-(void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event {
NSDictionary *prefs = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"dr.erast.notifakepreferences"];
UIApplication *application = [UIApplication sharedApplication];
double delay = [[prefs objectForKey: @"NTFNotificationDelay"] doubleValue];
__block UIBackgroundTaskIdentifier backgroundTaskID = [application beginBackgroundTaskWithName:@"BackgroundTask" expirationHandler:^{
[application endBackgroundTask:backgroundTaskID];
backgroundTaskID = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[NSThread sleepForTimeInterval:delay];
showNotif();
[application endBackgroundTask:backgroundTaskID];
backgroundTaskID = UIBackgroundTaskInvalid;
});
}
+(void)load {
[[%c(LAActivator) sharedInstance] registerListener:[self new] forName:@"dr.erast.notifake.listener"];
}
@end
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)showNotif, CFSTR("dr.erast.showNotifake/buttonpressed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("dr.erast.notifake/prefschanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
loadPrefs();
}