-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRootViewController.m
400 lines (309 loc) · 18 KB
/
RootViewController.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
//BundleIDs Originally created by @NoahSaso
//Updated in 2018 by @TD_Advocate
//Huge thanks to @TheTomMetzger and @Skittyblock for their massive amounts of help with updating and adding new features
//Shoutout to @xerusdesign for making the new icon and @EthanWhited for helping resolve an iOS 13 crash w/app icons in the table view
#import "SkittyAppListViewController.h"
SkittyAppListViewController *controller;
//Set showID alert to nil for auto dismiss
UIAlertController *showID = nil;
//Set copyAllAlert alert to nil for auto dismiss
UIAlertController *copyAllAlert = nil;
//Create array of bundleIDs to be used for copyAllButton
NSMutableArray *bundleIDs;
UIVisualEffectView *effectWelcomeView;
UIVisualEffectView *effectWelcomeView2;
static void setAppList(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
if ([(__bridge NSDictionary *)userInfo count] < 2) { // people must have at least two apps, right?
return;
}
NSLog(@"[SPEC] setAppList: %@", userInfo);
[controller recieveAppList:(__bridge NSDictionary *)userInfo];
}
static void post() {
NSLog(@"[SPEC] post");
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), CFSTR("xyz.skitty.skittyapplist.getapps"), nil, nil, true);
}
@implementation SkittyAppListViewController
- (NSArray *)specifiers {
return nil;
}
- (id)init {
self = [super init];
if (self) {
self.title = @"Bundle IDs";
CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), NULL, setAppList, CFSTR("xyz.skitty.skittyapplist.setapps"), nil, CFNotificationSuspensionBehaviorDeliverImmediately);
[self getAppList];
NSString *prefPath = @"/var/mobile/Library/Preferences/xyz.skitty.skittyapplist.apps.plist";
NSMutableDictionary *prefs = [NSMutableDictionary dictionaryWithContentsOfFile:prefPath];
NSArray *apps;
if ([[NSFileManager defaultManager] fileExistsAtPath:prefPath]) {
apps = [prefs objectForKey:@"Disabled"];
} else {
apps = @[];
}
self.preferencesAppList = apps;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.obscuresBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = YES;
self.searchController.delegate = self;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.placeholder = @"Search";
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO; // unfortunatly, this is required.
if(@available(iOS 13.0, *)) {
self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
self.navigationBar.backgroundView.effectView1.effect = self.blurEffect;
} else {
self.navigationBar.backgroundView.effectView1.effect = nil;
}
self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.view.frame = [UIScreen mainScreen].bounds;
self.tableDynamicColor = [UIColor colorWithDynamicProvider:^UIColor *(UITraitCollection *traitCollection) {
BOOL isDarkMode = traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
BOOL isLightMode = traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight;
BOOL isUnspecified = traitCollection.userInterfaceStyle == UIUserInterfaceStyleUnspecified;
if (isDarkMode) {
return [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1.0f];
} if (isLightMode) {
return [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
}
if (isUnspecified) {
return [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
}
return [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
}];
self.tableView.backgroundColor = self.tableDynamicColor;
self.backgroundDynamicColor = [UIColor colorWithDynamicProvider:^UIColor *(UITraitCollection *traitCollection) {
BOOL isDarkMode = traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
BOOL isLightMode = traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight;
BOOL isUnspecified = traitCollection.userInterfaceStyle == UIUserInterfaceStyleUnspecified;
if (isDarkMode) {
return [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1.0f];
} if (isLightMode) {
return [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
}
if (isUnspecified) {
return [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
}
return [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
}];
self.view.backgroundColor = self.backgroundDynamicColor;
[self.view addSubview:self.tableView];
// This is probably a terrible way to do it.
controller = self;
}
return self;
}
- (void)viewDidLoad {
//Create copyAllButton on right side of the navbar
UIBarButtonItem *copyAllButton = [[UIBarButtonItem alloc]
initWithTitle:@"Copy All"
style:UIBarButtonItemStylePlain
target:self
action:@selector(copyAllButton:)];
self.navigationItem.rightBarButtonItem = copyAllButton;
copyAllButton.tintColor = [UIColor systemPinkColor];
[[UINavigationBar appearance] setTintColor:[UIColor systemPinkColor]];
[super viewDidLoad];
}
// App List
- (void)getAppList {
if (self.appList.count == 0) {
self.appList = @{@"Loading!": @"Loading..."};
}
post();
}
- (void)recieveAppList:(NSDictionary *)appList {
if ([appList count] < 2) {
return;
}
self.fullAppList = appList;
[self updateAppList:appList];
}
- (void)updateAppList:(NSDictionary *)appList {
NSArray *ids = [appList keysSortedByValueUsingComparator:^(NSString *obj1, NSString *obj2) {
return [obj1 compare:obj2];
}];
self.appList = appList;
self.identifiers = ids;
[self.tableView reloadData];
}
// Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (void)viewWillLayoutSubviews {
self.tableView.frame = [UIScreen mainScreen].bounds;
self.view.frame = [UIScreen mainScreen].bounds;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SkittyAppCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:3 reuseIdentifier:@"SkittyAppCell"];
}
cell.detailTextLabel.textColor = [UIColor systemGray2Color];
if (![self.preferencesAppList containsObject:self.identifiers[indexPath.row]]) {
}
self.labelDynamicColor = [UIColor colorWithDynamicProvider:^UIColor *(UITraitCollection *traitCollection) {
BOOL isDarkMode = traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
BOOL isLightMode = traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight;
BOOL isUnspecified = traitCollection.userInterfaceStyle == UIUserInterfaceStyleUnspecified;
if (isDarkMode) {
return [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
} if (isLightMode) {
return [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1.0f];
}
if (isUnspecified) {
return [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1.0f];
}
return [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1.0f];
}];
cell.textLabel.textColor = self.labelDynamicColor;
cell.textLabel.text = [self.fullAppList objectForKey:self.identifiers[indexPath.row]];
cell.detailTextLabel.text = self.identifiers[indexPath.row];
cell.imageView.image = [UIImage _applicationIconImageForBundleIdentifier:self.identifiers[indexPath.row] format:0 scale:[UIScreen mainScreen].scale];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//copy single selected application bundle ID to clipboard
[UIPasteboard generalPasteboard].string = self.identifiers[indexPath.row];
self.bundleidController = [[OBWelcomeController alloc] initWithTitle:[self.fullAppList objectForKey:self.identifiers[indexPath.row]] detailText:@"" icon:[UIImage _applicationIconImageForBundleIdentifier:self.identifiers[indexPath.row] format:0 scale:[UIScreen mainScreen].scale]];
[self.bundleidController addBulletedListItemWithTitle:@"BundleID" description:self.identifiers[indexPath.row] image:[UIImage systemImageNamed:@"rectangle.stack.fill"]];
[self.bundleidController addBulletedListItemWithTitle:@"Copied" description:@"BundleID copied to ClipBoard" image:[UIImage systemImageNamed:@"doc.on.doc.fill"]];
self.continueButtonTint = [OBBoldTrayButton buttonWithType:1];
[self.continueButtonTint addTarget:self action:@selector(dismissVCTint) forControlEvents:UIControlEventTouchUpInside];
[self.continueButtonTint setTitle:@"Swipe or Press To Dismiss" forState:UIControlStateNormal];
[self.continueButtonTint setClipsToBounds:YES];
[self.continueButtonTint setTitleColor:[UIColor systemPinkColor] forState:UIControlStateNormal];
self.continueButtonTint.tintColor = [UIColor clearColor];
[self.continueButtonTint.layer setCornerRadius:15];
[self.bundleidController.buttonTray addButton:self.continueButtonTint];
[self.bundleidController set_shouldInlineButtontray: YES];
UISwipeGestureRecognizer *gestureRecognizerDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerDown:)];
[gestureRecognizerDown setDirection:(UISwipeGestureRecognizerDirectionDown)];
[self.bundleidController.viewIfLoaded addGestureRecognizer:gestureRecognizerDown];
//self.bundleidController.buttonTray.effectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
effectWelcomeView = [[UIVisualEffectView alloc] initWithFrame:self.bundleidController.viewIfLoaded.bounds];
effectWelcomeView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
[self.bundleidController.viewIfLoaded insertSubview:effectWelcomeView atIndex:0];
effectWelcomeView.translatesAutoresizingMaskIntoConstraints = false;
[effectWelcomeView.bottomAnchor constraintEqualToAnchor:self.bundleidController.viewIfLoaded.bottomAnchor constant:0].active = YES;
[effectWelcomeView.leftAnchor constraintEqualToAnchor:self.bundleidController.viewIfLoaded.leftAnchor constant:0].active = YES;
[effectWelcomeView.rightAnchor constraintEqualToAnchor:self.bundleidController.viewIfLoaded.rightAnchor constant:0].active = YES;
[effectWelcomeView.topAnchor constraintEqualToAnchor:self.bundleidController.viewIfLoaded.topAnchor constant:0].active = YES;
self.bundleidController.viewIfLoaded.backgroundColor = [UIColor clearColor];
//[self.bundleidController.buttonTray addCaptionText:@"BundleIDsXi"];
self.bundleidController.modalPresentationStyle = UIModalPresentationPageSheet;
self.bundleidController.modalInPresentation = NO;
self.bundleidController.view.tintColor = [UIColor systemPinkColor];
[self presentViewController:self.bundleidController animated:YES completion:nil];
}
-(void)dismissVCTint {
[self.bundleidController dismissViewControllerAnimated:YES completion:nil];
}
-(void)swipeHandlerDown:(id)sender {
[self.bundleidController dismissViewControllerAnimated:YES completion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.identifiers.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return nil;
}
// Search Bar
- (void)searchWithText:(NSString *)text {
NSDictionary *newAppList;
if (text.length == 0) {
newAppList = self.fullAppList;
} else {
NSMutableDictionary *mutableList = [[NSMutableDictionary alloc] init];
NSArray *ids = [self.fullAppList keysSortedByValueUsingComparator:^(NSString *obj1, NSString *obj2) {
return [obj1 compare:obj2];
}];
NSArray<NSString *> *names = [[self.fullAppList allValues] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
for (int i = 0; i < names.count; i++) {
if ([names[i].lowercaseString rangeOfString:text.lowercaseString].location != NSNotFound) {
[mutableList setObject:names[i] forKey:ids[i]];
}
}
newAppList = [mutableList copy];
}
[self updateAppList:newAppList];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text {
[self searchWithText:text];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[searchBar setShowsCancelButton:YES animated:YES];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
[self searchWithText:searchBar.text];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
[searchBar setShowsCancelButton:NO animated:YES];
[self searchWithText:nil];
}
//How the Copy All button works
-(void)copyAllButton:(id)sender {
NSString* copiedAllString = @"";
for (int i=0; i < self.appList.count; i ++) {
//Create the string of all application names
NSString *allNames = [NSString stringWithFormat:@"%@~", [self.fullAppList objectForKey:self.identifiers[i]]];
//NSString *allNames = [NSString stringWithFormat:@"%@\n", [self.fullAppList objectForKey:self.fullAppList][i]];
//Add the string of application names to the copied all string
copiedAllString = [copiedAllString stringByAppendingString:allNames];
//Create the string of all application bundle IDs
NSString *allBundles = [NSString stringWithFormat:@"%@%@", self.identifiers[i], @" "];
//Add the string of application bundle IDs to the copied all string
copiedAllString = [copiedAllString stringByAppendingString:allBundles];
}
//copy all bundle IDs to clipboard
[UIPasteboard generalPasteboard].string = copiedAllString;
self.copyallController = [[OBWelcomeController alloc] initWithTitle:@"BundleIDsXI" detailText:@"" icon:nil];
[self.copyallController addBulletedListItemWithTitle:@"Copied" description:@"All Bundle IDs copied to ClipBoard" image:[UIImage systemImageNamed:@"doc.on.doc.fill"]];
self.continueButtonTint2 = [OBBoldTrayButton buttonWithType:1];
[self.continueButtonTint2 addTarget:self action:@selector(dismissVCTint2) forControlEvents:UIControlEventTouchUpInside];
[self.continueButtonTint2 setTitle:@"Swipe or Press To Dismiss" forState:UIControlStateNormal];
[self.continueButtonTint2 setClipsToBounds:YES];
[self.continueButtonTint2 setTitleColor:[UIColor systemPinkColor] forState:UIControlStateNormal];
self.continueButtonTint2.tintColor = [UIColor clearColor];
[self.continueButtonTint2.layer setCornerRadius:15];
[self.copyallController.buttonTray addButton:self.continueButtonTint2];
[self.copyallController set_shouldInlineButtontray: YES];
self.copyallController.buttonTray.effectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
effectWelcomeView2 = [[UIVisualEffectView alloc] initWithFrame:self.copyallController.viewIfLoaded.bounds];
effectWelcomeView2.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
[self.copyallController.viewIfLoaded insertSubview:effectWelcomeView2 atIndex:0];
effectWelcomeView2.translatesAutoresizingMaskIntoConstraints = false;
[effectWelcomeView2.bottomAnchor constraintEqualToAnchor:self.copyallController.viewIfLoaded.bottomAnchor constant:0].active = YES;
[effectWelcomeView2.leftAnchor constraintEqualToAnchor:self.copyallController.viewIfLoaded.leftAnchor constant:0].active = YES;
[effectWelcomeView2.rightAnchor constraintEqualToAnchor:self.copyallController.viewIfLoaded.rightAnchor constant:0].active = YES;
[effectWelcomeView2.topAnchor constraintEqualToAnchor:self.copyallController.viewIfLoaded.topAnchor constant:0].active = YES;
self.copyallController.viewIfLoaded.backgroundColor = [UIColor clearColor];
//[self.copyallController.buttonTray addCaptionText:@"BundleIDsXi"];
self.copyallController.modalPresentationStyle = UIModalPresentationPageSheet;
self.copyallController.modalInPresentation = NO;
self.copyallController.view.tintColor = [UIColor systemPinkColor];
[self presentViewController:self.copyallController animated:YES completion:nil];
//copy all bundle IDs to clipboard
[UIPasteboard generalPasteboard].string = copiedAllString;
}
-(void)dismissVCTint2 {
[self.copyallController dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[self.tableView setNeedsDisplay];
[self.view setNeedsDisplay];
[self.bundleidController.viewIfLoaded setNeedsDisplay];
[effectWelcomeView setNeedsDisplay];
[self.copyallController.viewIfLoaded setNeedsDisplay];
[effectWelcomeView2 setNeedsDisplay];
}
@end