-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tweak.xm
154 lines (133 loc) · 6.61 KB
/
Tweak.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#import "Headers.h"
#import "FrontBoard.h"
#import "AssertionDaemon.h"
#include <notify.h>
@interface SBApplication : NSObject
-(id)bundleIdentifier;
-(void)resumeToQuit;
-(void)resumeForContentAvailable;
-(void)setBadge:(id)arg1 ;
-(unsigned)applicationState;
@end
@interface SBApplicationController : NSObject
+(id)sharedInstance;
-(SBApplication *)applicationWithPid:(NSInteger)pid;
@end
@interface UIApplication(ActivateSuspended)
-(BOOL)launchApplicationWithIdentifier:(id)identifier suspended:(BOOL)s;
@end
%group SpringBoardHooks
%hook SBBulletinBannerController
-(void)observer:(BBObserver *)obs addBulletin:(BBBulletin *)bulletin forFeed:(unsigned long long)feed {
NSLog(@"Bulletin: %@",bulletin);
if (bulletin.sectionID && [bulletin.sectionID isEqualToString:@"net.whatsapp.WhatsApp"]) { //check for whatsapp
//activate app
[[UIApplication sharedApplication] launchApplicationWithIdentifier:@"net.whatsapp.WhatsApp" suspended:YES];
[[objc_getClass("FBProcessManager") sharedInstance] createApplicationProcessForBundleID:@"net.whatsapp.WhatsApp"];
//section parameters
BBObserver *observer = bulletin.firstValidObserver;
BBSectionParameters *parameters = [observer parametersForSectionID:bulletin.sectionID];
BBSectionSubtypeParameters *subParameters = [parameters parametersForSubtype:bulletin.sectionSubtype];
[subParameters setPreservesUnlockActionCase:YES];
[parameters.defaultSubtypeParameters setPreservesUnlockActionCase:YES];
[parameters.allSubtypeParameters setObject:subParameters forKey:@(0)];
[observer updateSectionParameters:parameters forSectionID:bulletin.sectionID];
//actions
BBAction *replyAction = [%c(BBAction) actionWithIdentifier:@"NuntiusWhatsAppQuickReplyAction"]; //create an action with an identifier
[replyAction setRemoteViewControllerClassName:@"NTInlineWhatsAppReplyViewController"]; //set classname
[replyAction setRemoteServiceBundleIdentifier:@"com.apple.mobilesms.notification"]; //set bundle id
[replyAction setActionType:2];
BBAppearance *appearance = [%c(BBAppearance) appearanceWithTitle:[[NSBundle mainBundle] localizedStringForKey:@"REPLY" value:@"Reply" table:@"SpringBoard"]];
[appearance setColor:(BBColor *)[%c(BBColor) colorWithRed:99.f/255.f green:235.f/255.f blue:31.f/255.f alpha:1.0]];
[appearance setViewClassName:@"NTInlineWhatsAppReplyViewController"];
[replyAction setAppearance:appearance];
[replyAction setAuthenticationRequired:FALSE];
[replyAction setShouldDismissBulletin:YES];
BBAction *closeAction = [%c(BBAction) actionWithIdentifier:@"NuntiusWhatsAppCloseAction"];
[closeAction setActionType:3];
NSMutableDictionary *bbActions = bulletin.actions ? [bulletin.actions mutableCopy] : [NSMutableDictionary dictionary];
[bbActions setObject:closeAction forKey:@"acknowledge"];
[bbActions setObject:replyAction forKey:@"alternate"];
[bulletin setActions:[bbActions copy]]; //save actions to bulletin
//sub actions
NSMutableDictionary *supplementaryActions = bulletin.supplementaryActionsByLayout;
NSMutableArray *subActions = [supplementaryActions objectForKey:@(0)] ? [[supplementaryActions objectForKey:@(0)] mutableCopy] : [NSMutableArray array];
[subActions addObject:replyAction];
[supplementaryActions setObject:[subActions copy] forKey:@(0)];
[bulletin setSupplementaryActionsByLayout:supplementaryActions];
//buttons
NSMutableArray *bbButtons = bulletin.buttons ? [bulletin.buttons mutableCopy] : [NSMutableArray array];
BBButton *closeButton = [%c(BBButton) buttonWithTitle:@"Close" action:closeAction identifier:@"NuntiusWhatsAppCloseAction"];
BBButton *qrButton = [%c(BBButton) buttonWithTitle:[[NSBundle mainBundle] localizedStringForKey:@"REPLY" value:@"Reply" table:@"SpringBoard"] action:replyAction identifier:@"NuntiusWhatsAppQuickReplyAction"];
[bbButtons addObject:closeButton];
[bbButtons addObject:qrButton];
[bulletin setButtons:[bbButtons copy]];
NSDictionary *context = bulletin.context ?: [NSDictionary dictionary];
NSString *JID = @"not_set";
BOOL isRunning = FALSE;
if (context[@"remoteNotification"]) {
JID = context[@"remoteNotification"][@"aps"][@"u"];
JID = [JID stringByAppendingString:@"@s.whatsapp.net"];
} else if (context[@"localNotification"]) { //local notification
isRunning = TRUE;
NSData *localNotificationData = context[@"localNotification"];
UILocalNotification *localNotification = [NSKeyedUnarchiver unarchiveObjectWithData:localNotificationData];
JID = [localNotification userInfo][@"jid"];
}
@try {
[bulletin setContext:@{@"body":bulletin.message ?: @"empty",
@"recordID":bulletin.recordID ?: @"empty",
@"bulletinID":bulletin.bulletinID ?: @"empty",
@"publisherBulletinID":bulletin.publisherBulletinID ?: @"empty",
@"JID":JID,
@"isRunning":@(isRunning)
}];
} @catch (NSException *e) {
NSLog(@"[NT][SBBulletinBannerController] CAUGHT EXCEPTION: %@",e);
}
//change presenting action to our action
[[self _bannerContextForBulletin:bulletin] setPresentingActionIdentifier:@"NuntiusWhatsAppQuickReplyAction"];
}
//call original method with modified banner context
%orig(obs,bulletin,feed);
}
%end
%hook SBLockScreenActionContextFactory
-(id)lockScreenActionContextForBulletin:(BBBulletin *)bulletin action:(BBAction *)action origin:(int)arg3 pluginActionsAllowed:(BOOL)arg4 context:(id)arg5 completion:(/*^block*/id)arg6 {
SBMutableLockScreenActionContext *ctx = %orig;
if ([bulletin.sectionID isEqualToString:@"net.whatsapp.WhatsApp"] && [action.identifier isEqualToString:@"NuntiusWhatsAppQuickReplyAction"]) {
[ctx setRequiresUIUnlock:NO];
}
return ctx;
}
%end
%end
void nt_initializeSpringBoard() {
__block BKSProcessAssertion *assertion = nil;
static int activationToken = 0;
notify_register_dispatch("com.sharedroutine.nuntius.activate", &activationToken, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^(int token) {
uint64_t pid = -1;
notify_get_state(token,&pid);
SBApplication *app = [[%c(SBApplicationController) sharedInstance] applicationWithPid:pid];
if (app) {
if (assertion) {
[assertion invalidate];
assertion = nil;
}
assertion = [[%c(BKSProcessAssertion) alloc] initWithPID:pid flags:0x7 reason:10006 name:@"nuntius_activate" withHandler:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25.0f * NSEC_PER_SEC),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{
if (assertion) {
[assertion invalidate];
assertion = nil;
}
});
}
});
}
%ctor {
NSString *processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"SpringBoard"]) {
nt_initializeSpringBoard();
%init(SpringBoardHooks);
}
}