-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tweak.mm
157 lines (130 loc) · 7.94 KB
/
Tweak.mm
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
155
156
157
#import "Headers.h"
#import "NSObject+SafeKVC.h"
#import "DDNotificationToolsManager.h"
#define kStatusBarSettingsChanged @"DynasticDevelopmentiNDTStatusBarSettingsChangedNotificationName"
static NSDate *getOverrideDate() {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateStyle = NSDateFormatterNoStyle;
formatter.timeStyle = NSDateFormatterShortStyle;
NSDateComponents *components = [[NSCalendar currentCalendar] components: NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:[NSDate date]];
components.hour = 9;
components.minute = 41;
return [[NSCalendar currentCalendar] dateFromComponents:components];
}
static DDNotificationToolsManager *manager;
static NSMutableArray *notificationRequests = [NSMutableArray array];
static BOOL spoofsCarrier = NO;
static BOOL spoofsTime = NO;
static NSString *carrierName = @"";
@interface NotificationToolsManagerDelegate: NSObject <DDNotificationToolsManagerDelegate>
@end
@implementation NotificationToolsManagerDelegate
- (void)receivedNotifications:(NSArray *)notifications {
for (NSDictionary *info in notifications) {
NSTimeInterval start = [info[@"start"] doubleValue];
NSDictionary *notif = info[@"notification"];
NSString *title = notif[@"title"];
NSString *content = notif[@"content"];
NSString *appID = notif[@"bundleIdentifier"];
NCNotificationRequest *request = [%c(NCNotificationRequest) notificationRequestWithSectionId:appID notificationId:[NSString stringWithFormat:@"debug-notif-req-%@", [NSUUID UUID].UUIDString] threadId:[NSString stringWithFormat:@"debug-thread-req-%@", [NSUUID UUID].UUIDString] title:title message:content timestamp:[NSDate date] destinations:[NSSet setWithObjects:@"BulletinDestinationCoverSheet", @"BulletinDestinationBanner", @"BulletinDestinationNotificationCenter", @"BulletinDestinationLockScreen", nil]];
SBApplication *app = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:appID];
if (app) {
[request.content safelySetValue:app.displayName forKey:@"header"];
UIImage *iconImage = [UIImage _applicationIconImageForBundleIdentifier:app.bundleIdentifier format:5 scale:[UIScreen mainScreen].scale];
if (iconImage) {
[request.content safelySetValue:iconImage forKey:@"_icon"];
[request.content safelySetValue:@[iconImage] forKey:@"_icons"];
}
} else {
[request.content safelySetValue:appID forKey:@"header"];
}
[request.content safelySetValue:[NSDate date] forKey:@"_date"];
[request.options safelySetValue:@(1) forKey:@"_canPlaySound"];
[request.options safelySetValue:@(1) forKey:@"_canTurnOnDisplay"];
[request.options safelySetValue:@(1) forKey:@"_alertsWhenLocked"];
[request safelySetValue:[[%c(NCNotificationSound) alloc] init] forKey:@"_sound"];
[request.sound safelySetValue:@(2) forKey:@"_soundType"];
[request.sound safelySetValue:[(TLAlertConfiguration *)[%c(TLAlertConfiguration) alloc] initWithType:17] forKey:@"_alertConfiguration"];
[NSTimer scheduledTimerWithTimeInterval:start repeats:NO block:^(NSTimer *timer) {
[((SpringBoard *)[UIApplication sharedApplication]).notificationDispatcher.dispatcher postNotificationWithRequest:request];
[notificationRequests addObject:request];
}];
}
}
- (void)settingNamed:(NSString *)name changedTo:(NSString *)value {
if ([name isEqualToString:@"spoofsCarrier"]) {
spoofsCarrier = [value isEqualToString:@"1"];
} else if ([name isEqualToString:@"spoofsTime"]) {
spoofsTime = [value isEqualToString:@"1"];
} else if ([name isEqualToString:@"carrierName"]) {
carrierName = value;
}
StatusBarOverrideData *overrides = [%c(UIStatusBarServer) getStatusBarOverrideData];
if (spoofsTime) {
overrides->overrideItemIsEnabled[BatteryDetail] = YES;
overrides->values.itemIsEnabled[BatteryDetail] = YES;
overrides->overrideBatteryCapacity = YES;
overrides->values.batteryCapacity = 100;
overrides->overrideBatteryState = YES;
overrides->values.batteryState = 0;
overrides->overrideBatteryDetailString = YES;
NSString *batteryDetailString = [NSString stringWithFormat:@"%@%%", @(overrides->values.batteryCapacity)];
strcpy(overrides->values.batteryDetailString, [batteryDetailString cStringUsingEncoding:NSUTF8StringEncoding]);
}
if (spoofsCarrier) {
strcpy(overrides->values.serviceString, [carrierName cStringUsingEncoding:NSUTF8StringEncoding]);
overrides->overrideItemIsEnabled[SignalStrengthBars] = 1;
overrides->values.itemIsEnabled[SignalStrengthBars] = 1;
overrides->overrideGsmSignalStrengthBars = 1;
overrides->values.gsmSignalStrengthBars = 5;
}
overrides->overrideServiceString = spoofsCarrier;
[[[UIApplication sharedApplication] statusBar] setLocalDataOverrides:overrides];
[[[UIApplication sharedApplication] statusBar] forceUpdateData:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:kStatusBarSettingsChanged object:nil];
((SBDateTimeController *)[%c(SBDateTimeController) sharedInstance]).overrideDate = spoofsTime ? getOverrideDate() : nil;
}
- (void)triggeredActionNamed:(NSString *)name {
if ([name isEqualToString:@"respring"]) {
SBSRelaunchAction *restartAction = [%c(SBSRelaunchAction) actionWithReason:@"RestartRenderServer" options:4 targetURL:nil];
[[%c(FBSSystemService) sharedService] sendActions:[NSSet setWithObject:restartAction] withResult:nil];
} else if ([name isEqualToString:@"clearAll"]) {
for (NCNotificationRequest *request in notificationRequests) {
[((SpringBoard *)[UIApplication sharedApplication]).notificationDispatcher.dispatcher withdrawNotificationWithRequest:request];
}
notificationRequests = [NSMutableArray array];
}
}
- (void)considerInvitationFromDeviceNamed:(NSString *)deviceName responseHandler:(void (^)(BOOL))responseHandler {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"iNDT Connection Request"
message:[NSString stringWithFormat:@"'%@' would like to connect to and control some functionality of your device.", deviceName]
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Allow" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
responseHandler(YES);
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Decline" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
responseHandler(NO);
}]];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// keyWindow is deprecated on iOS 13, shouldn't be used for apps with multiple scenes which is okay because SpringBoard is SpringBoard.
[[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:alert animated:YES completion:nil];
#pragma clang diagnostic pop
}
- (NSDictionary *)getConnectedPayload {
return @{@"type": @"settings", @"settings": @{@"carrierName": carrierName, @"spoofsCarrier": spoofsCarrier ? @"1" : @"0", @"spoofsTime": spoofsTime ? @"1" : @"0"}};
}
@end
%hook NCNotificationListViewController
- (void)notificationListCellRequestsDismissAction:(NCNotificationListCell *)cell completion:(/*^block*/id)completion {
%orig;
NCNotificationRequest *request = cell.contentViewController.notificationRequest;
if (request && [[request notificationIdentifier] rangeOfString:@"debug-notif-req-"].location != NSNotFound) {
[((SpringBoard *)[UIApplication sharedApplication]).notificationDispatcher.dispatcher withdrawNotificationWithRequest:request];
}
}
%end
%ctor {
manager = [[DDNotificationToolsManager alloc] init];
manager.delegate = [[NotificationToolsManagerDelegate alloc] init];
}