-
Notifications
You must be signed in to change notification settings - Fork 8
/
Tweak.xm
682 lines (538 loc) · 24.6 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
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#pragma mark Includes & Defines
#import <notify.h>
#import <substrate.h>
#import "ControlCenterUI.h"
#import "SpringBoard.h"
#import "FrontBoard.h"
#import "FrontBoardServices.h"
#import "SelectionPage.h"
#import "Tweak.h"
#import "ManualLayout.h"
#import "AppPage.h"
#pragma mark Helpers
static void LoadPrefs() {
CFPreferencesAppSynchronize(CFSTR(BUNDLEID_C));
CFBooleanRef enabled = (CFBooleanRef)CFPreferencesCopyAppValue(CFSTR(PREFS_ENABLED_C), CFSTR(BUNDLEID_C));
if (enabled) {
isTweakEnabled = CFBooleanGetValue(enabled);
}
CFNumberRef aPSM = (CFNumberRef)CFPreferencesCopyAppValue(CFSTR(PREFS_APPPAGESCALE_C), CFSTR(BUNDLEID_C));
if (aPSM) {
appPageScaleMultiplier = [(NSNumber*)aPSM doubleValue];
}
CFBooleanRef iFR = (CFBooleanRef)CFPreferencesCopyAppValue(CFSTR(PREFS_ISFIRSTRUN_C), CFSTR(BUNDLEID_C));
if (iFR) {
isNotFirstRun = !CFBooleanGetValue(iFR);
} else {
isNotFirstRun = false;
}
[[NSNotificationCenter defaultCenter] postNotificationName:@PREFS_CHANGE_ID object:nil];
}
static void RemoveAllPages() {
[[NSNotificationCenter defaultCenter] postNotificationName:@NOTIFICATION_REMOVEALLPAGES object:nil];
}
static CGFloat DegreesToRadians(CGFloat degrees) {
return degrees * M_PI / 180;
};
int rotationDegreesForInterfaceOrientation(UIInterfaceOrientation orientation) {
int rotationDegrees;
switch(orientation) {
case UIInterfaceOrientationPortrait:
rotationDegrees = 0;
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotationDegrees = 180;
break;
case UIInterfaceOrientationLandscapeLeft:
rotationDegrees = 90;
break;
case UIInterfaceOrientationLandscapeRight:
rotationDegrees = 270;
break;
}
return rotationDegrees;
}
CGFloat rotationRadiansForInterfaceOrientation(UIInterfaceOrientation orientation) {
return DegreesToRadians(rotationDegreesForInterfaceOrientation(orientation));
}
static CGAffineTransform transformToRect(CGRect sourceRect, CGRect finalRect, UIInterfaceOrientation viewRotation) {
if (UIInterfaceOrientationIsLandscape(viewRotation)) {
CGFloat width = finalRect.size.width;
CGFloat y = finalRect.origin.y;
finalRect.origin.y = finalRect.origin.x;
finalRect.origin.x = y;
finalRect.size.width = finalRect.size.height;
finalRect.size.height = width;
}
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, -(CGRectGetMidX(sourceRect)-CGRectGetMidX(finalRect)), -(CGRectGetMidY(sourceRect)-CGRectGetMidY(finalRect)));
transform = CGAffineTransformScale(transform, finalRect.size.width/sourceRect.size.width, finalRect.size.height/sourceRect.size.height);
transform = CGAffineTransformRotate(transform, rotationRadiansForInterfaceOrientation(viewRotation));
return transform;
}
#pragma mark Hooks
%hook SBApplication
%new
- (void)appcenter_setBackgrounded:(BOOL)backgrounded withCompletion:(void (^)(BOOL))completion {
FBSceneManager *sceneManager = [%c(FBSceneManager) sharedInstance];
FBScene *scene = [sceneManager sceneWithIdentifier:[self bundleIdentifier]];
id <FBSceneClientProvider> clientProvider = [scene clientProvider];
id <FBSceneClient> client = [scene client];
FBSSceneSettings *settings = [scene settings];
FBSMutableSceneSettings *mutableSettings = [settings mutableCopy];
[mutableSettings setBackgrounded:backgrounded];
FBSSceneSettingsDiff *settingsDiff = [%c(FBSSceneSettingsDiff) diffFromSettings:settings toSettings:mutableSettings];
[clientProvider beginTransaction];
[client host:scene didUpdateSettings:mutableSettings withDiff:settingsDiff transitionContext:nil completion:completion];
[clientProvider endTransaction];
}
%new
- (void)appcenter_startBackgroundingWithCompletion:(void (^)(BOOL))completion {
if (![self isRunning]) {
[[%c(FBSSystemService) sharedService] openApplication:[self bundleIdentifier] options:@{ FBSOpenApplicationOptionKeyActivateSuspended : @true } withResult:^{
[self appcenter_setBackgrounded:false withCompletion:completion];
SBAppSwitcherModel *model = [%c(SBAppSwitcherModel) sharedInstance];
SBApplication *application = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:[self bundleIdentifier]];
[model addToFront:[model _displayItemForApplication:application] role:2];
}];
return;
}
[self appcenter_setBackgrounded:false withCompletion:completion];
}
%new
- (void)appcenter_stopBackgroundingWithCompletion:(void (^)(BOOL))completion {
[self appcenter_setBackgrounded:true withCompletion:completion];
}
%end
ACAppSelectionPageViewController *selectionViewController = nil;
NSMutableArray<NSString*> *appPages = nil;
NSMutableDictionary<NSString*, SBAppSwitcherSnapshotView*> *snapshotViewCache = nil;
static BOOL filterPlatterViews = false;
BOOL reloadingControlCenter = false;
BOOL isTweakEnabled = true;
CGFloat appPageScaleMultiplier = 1.0;
BOOL isNotFirstRun = false;
%hook CCUIFirstUsePanelViewController
- (void)viewDidLoad {
%orig;
MSHookIvar<UILabel*>(self, "_titleLabel").text = @"App Center";
NSString *text = @"iPhone controls, Now Playing, and App Center each have their own cards.";
MSHookIvar<UILabel*>(self, "_explanitoryText").text = text;
MSHookIvar<UIImageView*>(self, "_lastPageGlyphImageView").transform = CGAffineTransformMakeScale(-1, 1);
}
- (void)_tappedContinueButton:(id)arg1 {
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_SCROLL_TO_SELECTIONPAGE object:self];
%orig;
}
%end
%hook CCUIControlCenterViewController
%property (nonatomic, retain) FBSceneHostWrapperView *animationWrapperView;
- (id)pagePlatterViewsForContainerView:(id)arg1 {
if (filterPlatterViews) {
NSArray *result = %orig;
NSMutableArray *mutableResult = [result mutableCopy];
NSMutableArray *platterViewsToRemove = [NSMutableArray new];
for (CCUIControlCenterPagePlatterView *platterView in mutableResult) {
if ([platterView.contentView isKindOfClass:[ACAppPageView class]]) {
[platterViewsToRemove addObject:platterView];
}
}
for (CCUIControlCenterPagePlatterView *platterView in platterViewsToRemove) {
[mutableResult removeObject:platterView];
}
[platterViewsToRemove release];
return [mutableResult autorelease];
} else {
return %orig;
}
}
%new
- (void)appcenter_displayFirstRunAlert {
[[CCUIControlCenterDefaults standardDefaults] setHasAcknowledgedFirstUseAlert:false];
}
%new
- (void)appcenter_scrollToSelectionPage {
[self scrollToPage:[self.contentViewControllers count] - 1 animated:true withCompletion:^(BOOL b){}];
}
%new
- (void)appcenter_savePages {
CFPreferencesSetAppValue(CFSTR(PREFS_APPPAGES_C), appPages, CFSTR(BUNDLEID_C));
CFPreferencesAppSynchronize(CFSTR(BUNDLEID_C));
}
%new
- (void)appcenter_removeAllPages {
if ([appPages count] > 0) {
for (UIViewController *contentViewController in [self contentViewControllers]) {
if ([contentViewController isKindOfClass:[ACAppPageViewController class]]) {
NSString *bundleIdentifier = [[(ACAppPageViewController*)contentViewController app] bundleIdentifier];
if (bundleIdentifier) {
ACAppPageViewController *appPageViewController = (ACAppPageViewController*)contentViewController;
if (![bundleIdentifier isEqualToString:[[(SpringBoard*)[%c(SpringBoard) sharedApplication] _accessibilityFrontMostApplication] bundleIdentifier]]) {
[[appPageViewController app] appcenter_stopBackgroundingWithCompletion:nil];
}
[appPageViewController.sceneHostManager disableHostingForRequester:REQUESTER];
}
[self _removeContentViewController:contentViewController];
}
}
[appPages removeAllObjects];
[self appcenter_savePages];
reloadingControlCenter = true;
[self controlCenterWillPresent];
reloadingControlCenter = false;
[selectionViewController.gridViewController.collectionView reloadData];
}
}
%new
- (void)appcenter_main {
LoadPrefs();
if (!isTweakEnabled) {
return;
}
if (!isNotFirstRun) {
[self appcenter_displayFirstRunAlert];
CFPreferencesSetAppValue(CFSTR(PREFS_ISFIRSTRUN_C), kCFBooleanFalse, CFSTR(BUNDLEID_C));
CFPreferencesAppSynchronize(CFSTR(BUNDLEID_C));
}
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
(CFNotificationCallback)RemoveAllPages,
CFSTR(NOTIFICATION_REMOVEALLPAGES),
NULL,
CFNotificationSuspensionBehaviorCoalesce
);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appcenter_removeAllPages) name:@NOTIFICATION_REMOVEALLPAGES object:nil];
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
(CFNotificationCallback)LoadPrefs,
CFSTR(PREFS_CHANGE_ID),
NULL,
CFNotificationSuspensionBehaviorCoalesce
);
snapshotViewCache = [NSMutableDictionary new];
appPages = [NSMutableArray new];
NSArray *savedPages = (NSArray*)CFPreferencesCopyAppValue(CFSTR(PREFS_APPPAGES_C), CFSTR(BUNDLEID_C));
if (savedPages) {
for (NSString *bundleID in savedPages) {
ACAppPageViewController *appPage = [[ACAppPageViewController alloc] initWithBundleIdentifier:bundleID];
if (appPage) {
[appPages addObject:bundleID];
[self _addContentViewController:appPage];
} // else there's a problem with the page (maybe the corresponding app was uninstalled), so we don't want it loaded or saved.
}
}
selectionViewController = [[ACAppSelectionPageViewController alloc] initWithNibName:nil bundle:nil];
[self _addContentViewController:selectionViewController];
[selectionViewController release];
[self appcenter_registerForDetectingLockState];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appcenter_scrollToSelectionPage)
name:NOTIFICATION_SCROLL_TO_SELECTIONPAGE
object:nil];
}
- (void)viewDidLoad {
%orig;
[self appcenter_main];
}
%new
- (void)appcenter_registerForDetectingLockState {
int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate", ¬ify_token,dispatch_get_main_queue(), ^(int token) {
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
if (state == 0) { // unlocked
[self appcenter_reloadForUnlock];
}
});
}
%new
- (void)appcenter_reloadForUnlock {
if (selectionViewController) {
[selectionViewController reloadForUnlock];
}
if ([self isPresented]) {
for (UIViewController *contentViewController in [self contentViewControllers]) {
if ([contentViewController isKindOfClass:[ACAppPageViewController class]]) {
[(ACAppPageViewController*) contentViewController reloadForUnlock];
}
}
}
}
%new
- (void)appcenter_appSelected:(NSString*)bundleIdentifier {
if ([appPages containsObject:bundleIdentifier]) {
for (UIViewController *contentViewController in [self contentViewControllers]) {
if ([contentViewController isKindOfClass:[ACAppPageViewController class]]) {
if ([[[(ACAppPageViewController*)contentViewController app] bundleIdentifier] isEqualToString:bundleIdentifier]) {
ACAppPageViewController *appPageViewController = (ACAppPageViewController*)contentViewController;
if (![bundleIdentifier isEqualToString:[[(SpringBoard*)[%c(SpringBoard) sharedApplication] _accessibilityFrontMostApplication] bundleIdentifier]]) {
[[appPageViewController app] appcenter_stopBackgroundingWithCompletion:nil];
} else {
[[[selectionViewController gridViewController] collectionView] reloadData];
}
[appPageViewController.sceneHostManager disableHostingForRequester:REQUESTER];
[self _removeContentViewController:contentViewController];
[appPages removeObject:bundleIdentifier];
[self appcenter_savePages];
reloadingControlCenter = true;
[self controlCenterWillPresent];
reloadingControlCenter = false;
[[[selectionViewController gridViewController] collectionView] reloadData];
}
}
}
return;
}
SBApplication *application = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:bundleIdentifier];
if (!application) {
reloadingControlCenter = true;
[self controlCenterWillPresent];
reloadingControlCenter = false;
[[[selectionViewController gridViewController] collectionView] reloadData];
return;
}
[appPages addObject:bundleIdentifier];
[self appcenter_savePages];
ACAppIconCell *selectedCell = selectionViewController.selectedCell;
CGRect initialIconPosition = [selectedCell.imageView convertRect:selectedCell.imageView.bounds toView:self.view];
SBIcon *icon = [[(SBIconController*)[%c(SBIconController) sharedInstance] model] expectedIconForDisplayIdentifier:bundleIdentifier];
int iconFormat = [icon iconFormatForLocation:0];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:initialIconPosition];
imageView.image = [icon getCachedIconImage:iconFormat];
imageView.hidden = true;
[self.view addSubview:imageView];
ACAppPageViewController *appPage = [[ACAppPageViewController alloc] initWithBundleIdentifier:bundleIdentifier];
[appPage setIsPageAnimating:true];
[self _removeContentViewController:selectionViewController];
[self _addContentViewController:appPage];
[self _addContentViewController:selectionViewController];
[self _addOrRemovePagesBasedOnVisibility];
reloadingControlCenter = true;
[self controlCenterWillPresent];
reloadingControlCenter = false;
[self scrollToPage:[self.contentViewControllers count] - 1 animated:false withCompletion:^(BOOL b) {
[appPage startSendingTouchesToApp];
}];
MSHookIvar<UIViewController*>(self, "_selectedViewController") = [self appcenter_containerViewControllerForContentView:appPage.view];
[self _updatePageControl];
[application appcenter_startBackgroundingWithCompletion:^(BOOL success) {
dispatch_async(dispatch_get_main_queue(), ^{
// darkening view fix
CCUIBackgroundDarkeningWithPlatterCutoutView *darkeningView = [[%c(CCUIBackgroundDarkeningWithPlatterCutoutView) alloc] initWithFrame:[[UIScreen mainScreen] bounds] darkeningColor:[UIColor colorWithWhite:0 alpha:0.6] platterCornerRadius:10];
UIView *platterView = [(UIView*)[[self pagePlatterViewsForContainerView:MSHookIvar<id>(self, "_containerView")] lastObject] superview];
CGRect frame = darkeningView.frame;
frame.origin.x = ([self.contentViewControllers count] - 1) * MSHookIvar<UIScrollView*>(self, "_pagesScrollView").frame.size.width;
frame.origin.y = -platterView.superview.frame.origin.y;
darkeningView.frame = frame;
[MSHookIvar<UIView*>(self, "_pagesScrollView") addSubview:darkeningView];
[MSHookIvar<UIView*>(self, "_pagesScrollView") sendSubviewToBack:darkeningView];
[darkeningView release];
FBSceneHostManager *sceneHostManager = [[application mainScene] contextHostManager];
self.animationWrapperView = [sceneHostManager hostViewForRequester:ANIMATION_REQUESTER enableAndOrderFront:true];
imageView.hidden = false;
self.animationWrapperView.layer.cornerRadius = 10;
self.animationWrapperView.transform = transformToRect(self.animationWrapperView.bounds, imageView.frame, application.statusBarOrientation);
self.animationWrapperView.alpha = 0;
self.animationWrapperView.clipsToBounds = true;
[self.view addSubview:self.animationWrapperView];
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^{
UIScrollView *pagesScrollView = MSHookIvar<UIScrollView*>(self, "_pagesScrollView");
pagesScrollView.contentOffset = CGPointMake(pagesScrollView.frame.size.width * ([self.contentViewControllers count] - 2), 0);
imageView.transform = CGAffineTransformMakeScale(5.0, 5.0);
imageView.center = CGPointMake([[UIScreen mainScreen] bounds].size.width / 2, [[UIScreen mainScreen] bounds].size.height / 2);
imageView.alpha = 0;
CGFloat scale = [ACManualLayout defaultAppPageScale]*appPageScaleMultiplier;
CGRect toRect = CGRectApplyAffineTransform([[UIScreen mainScreen] bounds], CGAffineTransformMakeScale(scale, scale));
toRect.origin = CGPointMake(CGRectGetMidX([[UIScreen mainScreen] bounds]) - (toRect.size.width / 2), CGRectGetMidY([[UIScreen mainScreen] bounds]) - (toRect.size.height / 2) - APP_PAGE_PADDING);
self.animationWrapperView.transform = transformToRect(self.animationWrapperView.bounds, toRect, application.statusBarOrientation);
self.animationWrapperView.alpha = 1;
} completion:^(BOOL completed) {
[[self.animationWrapperView.scene contextHostManager] disableHostingForRequester:ANIMATION_REQUESTER];
[[self.animationWrapperView.scene contextHostManager] enableHostingForRequester:REQUESTER orderFront:true];
[self.animationWrapperView removeFromSuperview];
[darkeningView removeFromSuperview];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ACAppCellStopActivity" object:self];
[[[selectionViewController gridViewController] collectionView] reloadData];
[appPage setIsPageAnimating:false];
}];
});
}];
[imageView release];
[appPage release];
}
%new
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[[NSNotificationCenter defaultCenter] postNotificationName:SCROLL_BEGIN_ID object:self];
}
%new
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[[NSNotificationCenter defaultCenter] postNotificationName:SCROLL_END_ID object:self];
}
- (void)viewWillLayoutSubviews {
if (!selectionViewController.searching) {
%orig;
}
}
%new
- (void)keyboardWillShow:(NSNotification*)notification {
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[[NSNotificationCenter defaultCenter] postNotificationName:@"KeyboardWillShow" object:nil];
UIViewController *containerVC = [self appcenter_containerViewControllerForContentView:selectionViewController.view];
if (selectionViewController.searching) {
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = containerVC.view.frame;
CGFloat maxMove = -[self.view convertPoint:[containerVC.view convertPoint:containerVC.view.frame.origin toView:nil] fromView:nil].y;
frame.origin.y = [ACManualLayout ccEdgeSpacing] + MAX(-keyboardSize.height, maxMove);
containerVC.view.frame = frame;
} completion:^(BOOL success) {
CCUIControlCenterContainerView *containerView = MSHookIvar<CCUIControlCenterContainerView*>(self, "_containerView");
[containerView _updateMasks];
}];
}
}
%new
- (void)keyboardWillHide:(NSNotification*)notification {
UIViewController *containerVC = [self appcenter_containerViewControllerForContentView:selectionViewController.view];
if (containerVC.view.frame.origin.y != 0) {
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = containerVC.view.frame;
frame.origin.y = 0;
containerVC.view.frame = frame;
CCUIControlCenterContainerView *containerView = MSHookIvar<CCUIControlCenterContainerView*>(self, "_containerView");
[containerView _updateMasks];
}];
}
}
%new
- (CCUIControlCenterPageContainerViewController*)appcenter_containerViewControllerForContentView:(UIView*)contentView {
NSArray *pageContainers = MSHookIvar<NSArray*>(self, "_allPageContainerViewControllers");
for (CCUIControlCenterPageContainerViewController *vc in pageContainers) {
if (vc.contentViewController.view == contentView) {
return vc;
}
}
return nil;
}
%end
%hook CCUIControlCenterContainerView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (!selectionViewController.searching) {
return %orig;
}
CGPoint pointInView = [self convertPoint:point toView:selectionViewController.view];
return [selectionViewController.view hitTest:pointInView withEvent:event];
}
- (void)_updateMasks {
filterPlatterViews = true;
%orig;
filterPlatterViews = false;
}
- (void)setRevealPercentage:(CGFloat)revealPercentage {
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_REVEAL_ID object:nil userInfo:@{ @"revealPercentage" : @(revealPercentage) }];
%orig;
}
- (void)controlCenterWillPresent {
%orig;
NSArray *platterViews = [[self delegate] pagePlatterViewsForContainerView:self];
for (CCUIControlCenterPagePlatterView *platterView in platterViews) {
[platterView layoutSubviews];
}
}
%end
%hook CCUIControlCenterPagePlatterView
- (void)layoutSubviews {
if ([self.contentView isKindOfClass:[ACAppPageView class]]) {
MSHookIvar<UIView*>(self, "_baseMaterialView").hidden = true;
MSHookIvar<UIView*>(self, "_whiteLayerView").hidden = true;
} else {
%orig;
}
}
- (void)_recursivelyVisitSubviewsOfView:(id)arg1 forPunchedThroughView:(id)arg2 collectingMasksIn:(id)arg3 {
if ([self.contentView isKindOfClass:[ACAppPageView class]]) {
if ([[(ACAppPageView*)self.contentView appIdentifier] isEqualToString:[[(SpringBoard*)[%c(SpringBoard) sharedApplication] _accessibilityFrontMostApplication] bundleIdentifier]]) {
%orig;
}
return;
}
%orig;
}
%end
%hook SBAppSwitcherModel
%new
- (NSArray*)recentAppIdentifiers {
NSArray<SBDisplayItem*> *mainSwitcherDisplayItems = MSHookIvar<NSArray*>(self, "_recentDisplayItems");
NSMutableArray *recentAppIdentifiers = [NSMutableArray new];
for (int i = 0; i < [mainSwitcherDisplayItems count]; i++) {
if ([recentAppIdentifiers count] > 9) {
break;
}
SBDisplayItem *item = mainSwitcherDisplayItems[i];
if ([[[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:[item displayIdentifier]] hasHiddenTag]) {
continue;
}
[recentAppIdentifiers addObject:[item displayIdentifier]];
}
return [recentAppIdentifiers autorelease];
}
- (void)_applicationActivationStateDidChange:(SBApplication*)arg1 withLockScreenViewController:(id)arg2 andLayoutElement:(id)arg3 {
%orig;
if ([arg1 isActivating]) {
if ([self.recentAppIdentifiers containsObject:[arg1 bundleIdentifier]]) {
[self.recentAppIdentifiers removeObject:[arg1 bundleIdentifier]];
}
[self.recentAppIdentifiers addObject:[arg1 bundleIdentifier]];
}
}
%new
- (NSArray<NSString*>*)appcenter_model {
NSArray<NSString*>* model = [self.recentAppIdentifiers subarrayWithRange:NSMakeRange(0, MIN(9, [self.recentAppIdentifiers count]))];
NSMutableArray<NSString*> *filteredModel = [NSMutableArray new];
for (NSString *displayIdentifier in model) {
if ([displayIdentifier isEqualToString:[[(SpringBoard*)[UIApplication sharedApplication] _accessibilityFrontMostApplication] bundleIdentifier]]) {
continue;
}
SBApplication *application = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:displayIdentifier];
if (!application) {
goto skip;
}
if (![snapshotViewCache objectForKey:displayIdentifier]) {
SBAppSwitcherSnapshotView *snapshotView = [%c(SBAppSwitcherSnapshotView) appSwitcherSnapshotViewForDisplayItem:[self _displayItemForApplication:application] orientation:UIInterfaceOrientationPortrait preferringDownscaledSnapshot:true loadAsync:false withQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
snapshotView.layer.cornerRadius = 10;
snapshotView.clipsToBounds = true;
snapshotViewCache[displayIdentifier] = snapshotView;
}
for (NSString *bundleIdentifier in appPages) {
if ([displayIdentifier isEqualToString:bundleIdentifier]) {
goto skip;
}
}
[filteredModel addObject:displayIdentifier];
skip:
continue;
}
NSMutableArray *unfilteredModel = [NSMutableArray new];
[unfilteredModel addObjectsFromArray:appPages];
[unfilteredModel addObjectsFromArray:filteredModel];
for (NSString *identifier in [snapshotViewCache allKeys]) {
if (![unfilteredModel containsObject:identifier]) {
[snapshotViewCache removeObjectForKey:identifier];
}
}
[unfilteredModel release];
return [filteredModel autorelease];
}
%end