-
Notifications
You must be signed in to change notification settings - Fork 7
/
SwipyFolders.xm
1631 lines (1223 loc) · 57.6 KB
/
SwipyFolders.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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import <substrate.h>
#import "SwipyFolders.h"
/**
* The preferences
*
*/
static NSUserDefaults *preferences;
static bool enabled;
static bool showedFirstTimeMessage;
static bool enableFolderPreview;
static bool hideGreyFolderBackground;
static bool closeFolderOnOpen;
static bool longHoldInvokesEditMode;
static NSInteger singleTapMethod;
static NSInteger swipeUpMethod;
static NSInteger swipeDownMethod;
static NSInteger doubleTapMethod;
static NSInteger shortHoldMethod;
static NSInteger longHoldMethod;
static CGFloat shortHoldTime;
static CGFloat longHoldTime;
static CGFloat doubleTapTime;
static NSInteger forceTouchMethod;
static NSInteger singleTapMethodCustomAppIndex;
static NSInteger swipeUpMethodCustomAppIndex;
static NSInteger swipeDownMethodCustomAppIndex;
static NSInteger doubleTapMethodCustomAppIndex;
static NSInteger shortHoldMethodCustomAppIndex;
static NSInteger longHoldMethodCustomAppIndex;
static NSInteger forceTouchMethodCustomAppIndex;
static NSInteger nestedFolderBehaviour;
static NSDictionary *customFolderSettings;
static bool classicFoldersEnabled;
static bool HAS_BIOPROTECT;
static void loadPreferences() {
preferences = [[NSUserDefaults alloc] initWithSuiteName:@"nl.jessevandervelden.swipyfoldersprefs"];
classicFoldersEnabled = NO;
if([NSFileManager.defaultManager fileExistsAtPath:@"/private/var/mobile/Library/Preferences/org.coolstar.classicfolders.plist"] && [NSFileManager.defaultManager fileExistsAtPath:@"/Library/MobileSubstrate/DynamicLibraries/ClassicFolders.dylib"]) {
NSUserDefaults *classicFolderPreferences = [[NSUserDefaults alloc] initWithSuiteName:@"org.coolstar.classicfolders"];
classicFoldersEnabled = ([classicFolderPreferences boolForKey:@"enabled"]) ? YES : NO;
}
if([NSFileManager.defaultManager fileExistsAtPath:@"/private/var/mobile/Library/Preferences/net.limneos.bioprotect.plist"] && [NSFileManager.defaultManager fileExistsAtPath:@"/Library/MobileSubstrate/DynamicLibraries/BioProtect.dylib"]) {
NSUserDefaults *bioProtectPreferences = [[NSUserDefaults alloc] initWithSuiteName:@"net.limneos.bioprotect"];
HAS_BIOPROTECT = ([bioProtectPreferences boolForKey:@"Enabled"]) ? YES : NO;
}
[preferences registerDefaults:@{
@"enabled": @YES,
@"showedFirstTimeMessage": @NO,
@"enableFolderPreview": @YES,
@"hideGreyFolderBackground": @NO,
@"closeFolderOnOpen": @YES,
@"longHoldInvokesEditMode": @NO,
@"singleTapMethod": [NSNumber numberWithInteger:2],
@"swipeUpMethod": [NSNumber numberWithInteger:1],
@"swipeDownMethod": [NSNumber numberWithInteger:0],
@"doubleTapMethod": [NSNumber numberWithInteger:0],
@"doubleTapTime": [NSNumber numberWithFloat:0.2],
@"shortHoldMethod": [NSNumber numberWithInteger:0],
@"shortHoldTime": [NSNumber numberWithFloat:0.2],
@"longHoldMethod": [NSNumber numberWithInteger:0],
@"longHoldTime": [NSNumber numberWithFloat:0.2],
@"forceTouchMethod":[NSNumber numberWithInteger:4],
@"singleTapMethodCustomAppIndex": [NSNumber numberWithInteger:3],
@"swipeUpMethodCustomAppIndex": [NSNumber numberWithInteger:3],
@"swipeDownMethodCustomAppIndex": [NSNumber numberWithInteger:3],
@"doubleTapMethodCustomAppIndex": [NSNumber numberWithInteger:3],
@"shortHoldMethodCustomAppIndex": [NSNumber numberWithInteger:3],
@"longHoldMethodCustomAppIndex": [NSNumber numberWithInteger:3],
@"forceTouchMethodCustomAppIndex": [NSNumber numberWithInteger:3],
@"nestedFolderBehaviour": [NSNumber numberWithInteger:0],
}];
enabled = [preferences boolForKey:@"enabled"];
showedFirstTimeMessage = [preferences boolForKey:@"showedFirstTimeMessage"];
enableFolderPreview = [preferences boolForKey:@"enableFolderPreview"];
hideGreyFolderBackground = [preferences boolForKey:@"hideGreyFolderBackground"];
closeFolderOnOpen = [preferences boolForKey:@"closeFolderOnOpen"];
longHoldInvokesEditMode = [preferences boolForKey:@"longHoldInvokesEditMode"];
singleTapMethod = [preferences integerForKey:@"singleTapMethod"];
swipeUpMethod = [preferences integerForKey:@"swipeUpMethod"];
swipeDownMethod = [preferences integerForKey:@"swipeDownMethod"];
doubleTapMethod = [preferences integerForKey:@"doubleTapMethod"];
doubleTapTime = [preferences floatForKey:@"doubleTapTime"];
shortHoldMethod = [preferences integerForKey:@"shortHoldMethod"];
shortHoldTime = [preferences floatForKey:@"shortHoldTime"];
longHoldMethod = [preferences integerForKey:@"longHoldMethod"];
longHoldTime = [preferences floatForKey:@"longHoldTime"];
forceTouchMethod = [preferences integerForKey:@"forceTouchMethod"];
singleTapMethodCustomAppIndex = [preferences integerForKey:@"singleTapMethodCustomAppIndex"];
swipeUpMethodCustomAppIndex = [preferences integerForKey:@"swipeUpMethodCustomAppIndex"];
swipeDownMethodCustomAppIndex = [preferences integerForKey:@"swipeDownMethodCustomAppIndex"];
doubleTapMethodCustomAppIndex = [preferences integerForKey:@"doubleTapMethodCustomAppIndex"];
shortHoldMethodCustomAppIndex = [preferences integerForKey:@"shortHoldMethodCustomAppIndex"];
longHoldMethodCustomAppIndex = [preferences integerForKey:@"longHoldMethodCustomAppIndex"];
forceTouchMethodCustomAppIndex = [preferences integerForKey:@"forceTouchMethodCustomAppIndex"];
nestedFolderBehaviour = [preferences integerForKey:@"nestedFolderBehaviour"];
customFolderSettings = [preferences dictionaryForKey:@"customFolderSettings"];
[preferences release];
}
static UIColor *colorShiftedBy(UIColor *color, CGFloat shift) {
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
return [UIColor colorWithRed:red + shift green:green + shift blue:blue + shift alpha:alpha];
}
static void saveFolderSettings(NSDictionary *folderSettings) {
NSUserDefaults *preferences = [[NSUserDefaults alloc] initWithSuiteName:@"nl.jessevandervelden.swipyfoldersprefs"];
[preferences setObject:folderSettings forKey:@"customFolderSettings"];
[preferences synchronize];
customFolderSettings = [folderSettings copy];
}
static void setFolderSetting(NSString *folderID, NSString *key, id setting) {
NSMutableDictionary *mutableCustomFolderSettings = [customFolderSettings mutableCopy];
NSMutableDictionary *mutableFolderSettings = [customFolderSettings[folderID] mutableCopy];
if(!mutableFolderSettings) mutableFolderSettings = [NSMutableDictionary new];
if(!mutableCustomFolderSettings) mutableCustomFolderSettings = [NSMutableDictionary new];
[mutableFolderSettings setObject:setting forKey:key];
[mutableCustomFolderSettings setObject:mutableFolderSettings forKey:folderID];
saveFolderSettings(mutableCustomFolderSettings);
}
/**
* Setting the folder preview (one icon in folder preview)
*
*/
/*%hook SBIconImageView
-(id)setFrame:(CGRect)frame{
frame = CGRectMake(frame.origin.x, frame.origin.y, 20, 20);
return %orig(frame);
}
%end*/
%hook SBFolderIconImageView
static UIImageView *customImageView;
-(id)initWithFrame:(CGRect)arg1{
//UIView *view = %orig;
self = %orig;
if(enabled) {
//CGSize size = [%c(SBIconView) defaultIconImageSize];
CGRect iconFrame = self.frame;//CGRectMake(0, 0, 60, 60);
if(!hideGreyFolderBackground) {
CGFloat iconSize = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 45 : 54;
CGFloat offset = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 8.5 : 12;
iconFrame = CGRectMake(offset, offset, iconSize, iconSize); //Full size is 60
} else MSHookIvar<UIView *>(self, "_backgroundView").hidden = YES;
self.customImageView = [[UIImageView alloc] initWithFrame:iconFrame];
self.customImageView.backgroundColor = [UIColor clearColor];
[self insertSubview:self.customImageView atIndex:0];
}
return self;
}
%new(v@:@) - (void)setCustomImageView:(UIImageView *)imageView {
objc_setAssociatedObject(self, &customImageView, imageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new(@@:) - (UIImageView *)customImageView {
return objc_getAssociatedObject(self, &customImageView);
}
-(void)dealloc {
[self.customImageView release];
%orig;
}
- (void)_showLeftMinigrid{
%orig;
SBFolder *folder = self._folderIcon.folder;
NSString *folderID = folder.folderID;
SBIconController *iconController = [%c(SBIconController) sharedInstance];
if(iconController.isEditing && ![folder.oldFolderID isEqualToString:@""]) {
folderID = folder.oldFolderID;
}
NSDictionary *folderSettings = customFolderSettings[folderID];
if(enabled){
UIImageView *innerFolderImageView = MSHookIvar<UIImageView *>(self, "_leftWrapperView");
if((enableFolderPreview && !([folderSettings[@"customFolderAppearance"] intValue] == 1 && ([folderSettings[@"customFolderEnableFolderPreview"] intValue] == 0 || [folderSettings objectForKey:@"customFolderEnableFolderPreview"] == nil))) || ([folderSettings[@"customFolderAppearance"] intValue] == 1 && [folderSettings[@"customFolderEnableFolderPreview"] intValue] == 1)){
SBIcon *firstIcon = [folder getFirstIcon];
UIImage *firstImage = [firstIcon getIconImage:2];
self.customImageView.image = firstImage;
[self hideInnerFolderImageView: YES];
CGSize size = [%c(SBIconView) defaultIconImageSize];
CGRect iconFrame = CGRectMake(0, 0, size.width, size.height);
if((!hideGreyFolderBackground && !([folderSettings[@"customFolderAppearance"] intValue] == 1 && [folderSettings[@"customFolderHideGreyFolderBackground"] intValue] == 1)) || ([folderSettings[@"customFolderAppearance"] intValue] == 1 && [folderSettings[@"customFolderEnableFolderPreview"] intValue] == 1 && [folderSettings[@"customFolderHideGreyFolderBackground"] intValue] == 0)) {
CGFloat iconSize = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 45 : 54;
CGFloat offset = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 8.5 : 12;
iconFrame = CGRectMake(offset, offset, iconSize, iconSize);
}
self.customImageView.frame = iconFrame;
[self bringSubviewToFront:self.customImageView];
if([folderSettings[@"customFolderHideGreyFolderBackground"] intValue] == 1) {
MSHookIvar<UIView *>(self, "_backgroundView").hidden = YES;
}
} else {
self.customImageView.image = nil;
[self hideInnerFolderImageView: NO];
[self sendSubviewToBack:self.customImageView]; //Misschien weg?
[self bringSubviewToFront:innerFolderImageView];
}
}
}
%new -(void)hideInnerFolderImageView:(BOOL)hide {
UIImageView *innerFolderImageView = MSHookIvar<UIImageView *>(self, "_leftWrapperView");
innerFolderImageView.hidden = hide;
}
%end
/**
* Overwriting some folder opening animations
*
*/
%hook SBFolderIconZoomAnimator
-(void)_prepareAnimation{
%orig;
SBFolderIconImageView *folderIconImageView = self.targetIconView._folderIconImageView;
if(folderIconImageView.customImageView.image != nil && !self.targetIcon.folder.open) { //Yes the last argument returns NO already
SBFolderView *innerFolderView = MSHookIvar<SBFolderView *>(self, "_innerFolderView");
UIView *scrollView = MSHookIvar<UIView *>(innerFolderView, "_scrollView");
UIImageView *leftView = MSHookIvar<UIImageView *>(folderIconImageView, "_leftWrapperView");
leftView.hidden = YES;
UIImageView *rightView = MSHookIvar<UIImageView *>(folderIconImageView, "_rightWrapperView");
rightView.hidden = YES;
folderIconImageView.customImageView.hidden = NO;
[folderIconImageView bringSubviewToFront:folderIconImageView.customImageView];
folderIconImageView.customImageView.alpha = 0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[folderIconImageView.customImageView setAlpha:1.0];
[scrollView setAlpha:0.0];
[UIView commitAnimations];
} else if(self.targetIcon.folder.open) {
folderIconImageView.customImageView.hidden = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) {
folderIconImageView.customImageView.hidden = NO;
});
}
//If not calling %orig; the icons behind the screen are not removed, so cool iOS 10 gimmick?
}
%end
%hook SBFolderIconView
- (void)setIcon:(id)arg1 {
%orig;
if([[%c(SBIconController) sharedInstance] respondsToSelector:@selector(_handleShortcutMenuPeek:)]) {
self.shortcutMenuPeekGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:[%c(SBIconController) sharedInstance] action:@selector(_handleShortcutMenuPeek:)];
self.shortcutMenuPresentProgress = [[UIPreviewForceInteractionProgress alloc] initWithGestureRecognizer:self.shortcutMenuPeekGesture];
[self cancelLongPressTimer];
}
}
%end
static SBIcon *firstIcon;
static SBIconView *tappedIcon;
static NSDate *lastTouchedTime;
static NSDate *lastTappedTime;
static NSDate *forceTouchOpenedTime;
static BOOL doubleTapRecognized;
static BOOL forceTouchRecognized;
static BOOL showFirstIconShortcuts;
/*
%hook SBUIAppIconForceTouchController
- (id)_shortcutViewControllerForDataProvider:(id)arg1; //ios 10
%end
*/
/**
* FINALLLLYYYYYYYYYYYYYY The real iOS 10 methods to modify shortcuts
*/
%hook SBUIAppIconForceTouchControllerDataProvider
- (id)applicationBundleIdentifier {
//DEEESSSS
SBIconController *iconController = [%c(SBIconController) sharedInstance];
if(iconController.lastTouchedIcon.isFolderIcon && enabled) {
NSDictionary *methodDict = [iconController.lastTouchedIcon.getIconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if(method == 4 || showFirstIconShortcuts) {
SBFolderIcon *folderIcon = (SBFolderIcon*)iconController.lastTouchedIcon;
SBFolder* folder = folderIcon.folder;
SBIcon *firstIcon = [folder getFirstIcon];
return firstIcon.application.bundleIdentifier;
}
}
return %orig;
}
- (id)applicationBundleURL { //Needed for the right icons
SBIconController *iconController = [%c(SBIconController) sharedInstance];
if(iconController.lastTouchedIcon.isFolderIcon && enabled) {
NSDictionary *methodDict = [iconController.lastTouchedIcon.getIconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if(method == 4 || showFirstIconShortcuts) {
SBFolderIcon *folderIcon = (SBFolderIcon*)iconController.lastTouchedIcon;
SBFolder* folder = folderIcon.folder;
SBIcon *firstIcon = [folder getFirstIcon];
NSString *pathString = [NSString stringWithFormat:@"file://%@",firstIcon.application.path];
return [NSURL URLWithString:pathString];
}
}
return %orig;
}
- (id)applicationShortcutItems {
SBIconController *iconController = [%c(SBIconController) sharedInstance];
if(iconController.lastTouchedIcon.isFolderIcon && enabled) {
NSDictionary *methodDict = [iconController.lastTouchedIcon.getIconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if(method == 0) {
return nil;
}
if(method == 4 || showFirstIconShortcuts) {
SBFolderIcon *folderIcon = (SBFolderIcon*)iconController.lastTouchedIcon;
SBFolder* folder = folderIcon.folder;
SBIcon *firstIcon = [folder getFirstIcon];
//SBIconView *firstIconView = firstIcon.getIconView;
//SBUIForceTouchGestureRecognizer *ftGestureRecognizer = firstIconView.appIconForceTouchGestureRecognizer;
//NSArray *applicationShortcutItems = %orig;
NSMutableArray *newItems = [NSMutableArray array]; //WithArray:applicationShortcutItems];
[newItems addObjectsFromArray:firstIcon.application.dynamicApplicationShortcutItems];
[newItems addObjectsFromArray:firstIcon.application.staticApplicationShortcutItems];
return newItems;
}
}
return %orig;
}
%end
/**
* Methods to iterate all folders, for folder specific options in the preference pane
*
*/
CPDistributedMessagingCenter *messagingCenter;
%hook SBIconController
- (id)init {
static dispatch_once_t once;
dispatch_once(&once, ^{
messagingCenter = [%c(CPDistributedMessagingCenter) centerNamed:@"nl.jessevandervelden.swipyfolders.center"];
[messagingCenter runServerOnCurrentThread];
[messagingCenter registerForMessageName:@"foldersRepresentation" target:self selector:@selector(handleMessageNamed:withUserInfo:)];
});
return %orig;
}
%new - (NSDictionary*)handleMessageNamed:(NSString *)name withUserInfo:(NSDictionary *)userinfo { //Only going to use for sending over folders so no additional checks needed
NSArray *folderArray = [[[self rootFolder] folderIcons] allObjects];
NSMutableDictionary *foldersRepresentation = [NSMutableDictionary dictionary];
for (int i=0; i<[folderArray count]; i++) {
SBFolderIcon *folderIcon = [folderArray objectAtIndex:i];
SBFolder *folder = folderIcon.folder;
//NSString *defaultDisplayName = MSHookIvar<NSString*>(folder, "defaultDisplayName");
NSArray *folderAppIcons = [folder.allIcons allObjects]; //orderedIcons iOS 9+
NSMutableArray *applicationBundleIDs = [[NSMutableArray alloc] init];
for(int k=0; k<[folderAppIcons count] && k<9; k++ ) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:k inSection:0];
SBIcon *appIcon = (SBApplicationIcon*)[folder iconAtIndexPath:indexPath];
if(appIcon.application.bundleIdentifier != nil){
[applicationBundleIDs addObject:appIcon.application.bundleIdentifier];
//SBApplicationIcon *appIcon = [folderAppIcons objectAtIndex:k];
}else {
SBLeafIcon *leafIcon = (SBLeafIcon*)appIcon;
if(leafIcon.leafIdentifier != nil) {
[applicationBundleIDs addObject:leafIcon.leafIdentifier];
} else {
[applicationBundleIDs addObject:@""];
}
}
}
NSMutableDictionary *folderDictionary = [NSMutableDictionary dictionary];
[folderDictionary setObject:folder.displayName forKey:@"displayName"]; // String
[folderDictionary setObject:applicationBundleIDs forKey:@"applicationBundleIDs"]; //NSArray with bundle id strings
NSString *folderID = folder.folderID;
[folderDictionary setObject:folderID forKey:@"folderID"];
[foldersRepresentation setObject:folderDictionary forKey:folderID]; //[NSString stringWithFormat:@"%d", i]
}
return foldersRepresentation;
}
/**
* Some bugfixes on pre 9.3 devices:
*
*/
//- (void)folderControllerShouldClose:(id)arg1; //9.3 not needed
// Okay, this may look crazy, but without preventing closeFolderAnimated, a 3D touch will close the folder
- (void)closeFolderAnimated:(_Bool)arg1 {
if(enabled && forceTouchMethod == 1) {
} else {
%orig;
}
}
//In order to still being able to close the folder with the home button:
- (void)handleHomeButtonTap {
%orig;
if ([self hasOpenFolder] && enabled && forceTouchMethod == 1) { //9.0/9.1
if([[%c(SBIconController) sharedInstance] respondsToSelector:@selector(closeFolderAnimated:withCompletion:)]) {
[[%c(SBIconController) sharedInstance] closeFolderAnimated:YES withCompletion:nil];
}
}
}
/**
* Finally the real deal:
*
*/
//A method for 3D Touch actions
static BOOL interactionProgressDidComplete = NO;
/*
- (void)_handleAppIconForceTouchGestureRecognizer:(UILongPressGestureRecognizer *)recognizer; //iOS 10
*/
/* This works basically
static id itemz2;
-(id)appIconForceTouchController:(id)controller applicationShortcutItemsForGestureRecognizer:(UIGestureRecognizer *)recognizer { //iOS 10
id selfie = %orig;
if(!itemz2) itemz2 = [selfie retain];
return itemz2;
SBIconView *iconView = (SBIconView*)recognizer.view;
if(iconView.isFolderIconView) {
NSDictionary *methodDict = [iconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if(method == 4) {
SBFolderIcon *folderIcon = ((SBFolderIconView *)iconView).folderIcon;
SBFolder* folder = folderIcon.folder;
SBApplicationIcon *firstIcon = (SBApplicationIcon*)[folder getFirstIcon];
NSMutableArray *newItems = [NSMutableArray array];
[newItems addObjectsFromArray:firstIcon.application.dynamicApplicationShortcutItems];
[newItems addObjectsFromArray:firstIcon.application.staticApplicationShortcutItems];
for (SBSApplicationShortcutItem *item in newItems) {
//[item setBundleIdentifierToLaunh: firstIcon.application.bundleIdentifier];
//UIApplicationShortcutIcon *fakeShortcutIcon = [[%c(UIApplicationShortcutIcon) alloc] initWithSBSApplicationShortcutIcon: [[%c(SBSApplicationShortcutSystemIcon) alloc] initWithType:UIApplicationShortcutIconTypeCompose];
//NSLog(@"swipyfolders: check deze %@", [SBSApplicationShortcutItem ])
//UIImage *appImage = [UIImage _applicationIconImageForBundleIdentifier:firstIcon.application.bundleIdentifier format:1 scale:[UIScreen mainScreen].scale];
//UIImage *iconImage = [UIImage imageWithData:item.icon.imagePNGData];
NSLog(@"swipyfodlers: %@", item.icon);
if([item.icon isKindOfClass:%c(SBSApplicationShortcutTemplateIcon)]) {
NSLog(@"swipyfodlers: %@", item.icon.templateImageName);
}
//SBSApplicationShortcutIcon *shortcutIcon = [[%c(SBSApplicationShortcutCustomImageIcon) alloc] initWithImagePNGData:UIImagePNGRepresentation(iconImage)];
//[item setIcon:shortcutIcon];
}
return newItems;
}
}
return %orig;
}*/
//IOS 10, change the recognizer view to the firstIconView in the folder, just before launching the shortcut item. Otherwise it doesn't know what to do
//[recognizer setView: firstIcon.getIconView]; can basically called anywhere AFTER showing all shortcutitems but BEFORE launching the actual shortcut. This needs to be set back too.
- (BOOL)appIconForceTouchController:(SBUIAppIconForceTouchController *)forceTouchController shouldActivateApplicationShortcutItem:(SBSApplicationShortcutItem*)shortcutItem atIndex:(unsigned long long)index forGestureRecognizer:(SBUIForceTouchGestureRecognizer *)recognizer {
SBIconView *iconView = (SBIconView*)recognizer.view;
if(iconView.isFolderIconView && enabled) {
NSDictionary *methodDict = [iconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if(method == 4) {
SBFolderIcon *folderIcon = ((SBFolderIconView *)iconView).folderIcon;
SBFolder* folder = folderIcon.folder;
SBApplicationIcon *firstIcon = (SBApplicationIcon*)[folder getFirstIcon];
[recognizer setView: firstIcon.getIconView];
//Needs to be set back too, otherwise it will fuck up the next time
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) {
[recognizer setView: iconView];
});
return %orig(forceTouchController, shortcutItem, index, recognizer);
}
}
return %orig;
}
/**
* Handle force touch methods on iOS 9 ONLY
*
*/
- (void)_handleShortcutMenuPeek:(UILongPressGestureRecognizer *)recognizer { //iOS 9
SBIconView *iconView = (SBIconView*)recognizer.view;
firstIcon = nil;
if(!iconView.isFolderIconView) {
%orig;
return;
}
SBFolderIcon *folderIcon = ((SBFolderIconView *)iconView).folderIcon;
SBFolder* folder = folderIcon.folder;
firstIcon = [folder getFirstIcon];
NSDictionary *methodDict = [iconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if (!self.isEditing && iconView.isFolderIconView && method != 0 && firstIcon && enabled) {
switch (recognizer.state) {
case UIGestureRecognizerStateBegan: {
[iconView cancelLongPressTimer];
forceTouchRecognized = YES;
interactionProgressDidComplete = false;
self.presentedShortcutMenu = [[%c(SBApplicationShortcutMenu) alloc] initWithFrame:[UIScreen mainScreen].bounds application:firstIcon.application iconView:iconView interactionProgress:iconView.shortcutMenuPresentProgress orientation:1];
self.presentedShortcutMenu.applicationShortcutMenuDelegate = self;
UIViewController *rootView = [[UIApplication sharedApplication].keyWindow rootViewController];
[rootView.view addSubview:self.presentedShortcutMenu];
SBIconView *forceTouchIconView = MSHookIvar<SBIconView *>(self.presentedShortcutMenu, "_proxyIconView");
SBFolderIconImageView *folderIconImageView = MSHookIvar<SBFolderIconImageView *>(forceTouchIconView, "_iconImageView");
UIView* folderBackgroundView = MSHookIvar<UIView *>(folderIconImageView, "_backgroundView");
SBWallpaperController *wallpaperCont = [%c(SBWallpaperController) sharedInstance];
UIColor *dominantColor = [wallpaperCont averageColorForVariant:1];
folderBackgroundView.backgroundColor = colorShiftedBy(dominantColor, 0.15);
folderBackgroundView.alpha = 0;
UIImageView *folderImageView = MSHookIvar<UIImageView *>(folderIconImageView, "_leftWrapperView");
if (method == 4) {
[folderIconImageView bringSubviewToFront:folderIconImageView.customImageView];
folderIconImageView.customImageView.alpha = 0;
}
[UIView transitionWithView:folderImageView
duration:0.5f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
if (method == 4) {
folderIconImageView.customImageView.image = [firstIcon getIconImage:2];
folderIconImageView.customImageView.alpha = 1;
folderImageView.hidden = YES;
}
folderBackgroundView.alpha = 1;
} completion:nil];
}break;
case UIGestureRecognizerStateChanged: {
[iconView cancelLongPressTimer];
if (method == 4) [self.presentedShortcutMenu updateFromPressGestureRecognizer:recognizer];
}break;
case UIGestureRecognizerStateEnded: {
if (method == 4 && self.presentedShortcutMenu.isPresented) {
SBApplicationShortcutMenuContentView *contentView = MSHookIvar<id>(self.presentedShortcutMenu,"_contentView");
NSMutableArray *itemViews = MSHookIvar<NSMutableArray *>(contentView,"_itemViews");
for(SBApplicationShortcutMenuItemView *item in itemViews) {
if (item.highlighted == YES) {
[self.presentedShortcutMenu menuContentView:contentView activateShortcutItem:item.shortcutItem index:item.menuPosition];
break;
}
}
} else if(method != 4) {
[self.presentedShortcutMenu dismissAnimated:true completionHandler:nil];
}
}break;
default:
break;
}
iconView.highlighted = NO;
} else {
%orig;
}
}
- (void)setIsEditing:(_Bool)editing {
%orig;
if(editing && [self respondsToSelector:@selector(_cleanupForDismissingShortcutMenu:)]) {
[self _cleanupForDismissingShortcutMenu:self.presentedShortcutMenu];
}
}
/**
* Methods for setting other gestures on the folder icon
*
*/
- (void) iconHandleLongPress:(SBIconView *)iconView {
lastTouchedTime = nil;
%orig;
}
- (void) iconTouchBegan:(SBIconView *)iconView {
lastTouchedTime = [[NSDate date] retain];
%orig;
}
- (void)iconTapped:(SBIconView *)iconView {
if (!self.isEditing && iconView.isFolderIconView && enabled) {
NSDate *nowTime = [[NSDate date] retain];
if (shortHoldMethod != 0 && lastTouchedTime && [nowTime timeIntervalSinceDate:lastTouchedTime] >= shortHoldTime) {
[iconView sf_method:[iconView getFolderSetting:@"ShortHoldMethod" withDefaultSetting:shortHoldMethod withDefaultCustomAppIndex:shortHoldMethodCustomAppIndex] withForceTouch:NO];
lastTouchedTime = nil;
iconView.highlighted = NO;
return;
} else if (doubleTapMethod != 0) {
if (iconView == tappedIcon) {
if (doubleTapMethod != 0 && [nowTime timeIntervalSinceDate:lastTappedTime] < doubleTapTime) {
doubleTapRecognized = YES;
[iconView sf_method:[iconView getFolderSetting:@"DoubleTapMethod" withDefaultSetting:doubleTapMethod withDefaultCustomAppIndex:doubleTapMethodCustomAppIndex] withForceTouch:NO];
lastTappedTime = nil;
iconView.highlighted = NO;
return;
}
}
tappedIcon = iconView;
lastTappedTime = nowTime;
doubleTapRecognized = NO;
iconView.highlighted = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(doubleTapTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) {
if (!doubleTapRecognized && iconView == tappedIcon) {
[iconView sf_method:[iconView getFolderSetting:@"SingleTapMethod" withDefaultSetting:singleTapMethod withDefaultCustomAppIndex:singleTapMethodCustomAppIndex] withForceTouch:NO];
}
});
} else {
NSDictionary *method = [iconView getFolderSetting:@"SingleTapMethod" withDefaultSetting:singleTapMethod withDefaultCustomAppIndex:singleTapMethodCustomAppIndex];
[iconView sf_method:method withForceTouch:NO];
iconView.highlighted = NO;
return;
}
} else {
if(self.hasOpenFolder && !iconView.isFolderIconView && enabled) {
[iconView.icon openAppFromFolder:self.openFolder.folderID];
if(closeFolderOnOpen) [self closeFolderAnimated:NO withCompletion:nil];
}
%orig;
}
forceTouchRecognized = NO;
}
%end
/**
* Additional force touch methods for doing an action on force touch iOS 10
*
*/
%hook SBUIIconForceTouchController
-(void)_presentAnimated:(BOOL)arg1 withCompletionHandler:(id)arg2{
if(enabled && arg2) { //So basically when we call it ourselfs (in sf_methods we send arg2=nil) to let NOT run this. Fucking ugly, but hey it works :P
SBUIIconForceTouchIconViewWrapperView *wrapperView = MSHookIvar<SBUIIconForceTouchIconViewWrapperView *>(self.iconForceTouchViewController, "_iconViewWrapperViewAbove");
if([wrapperView respondsToSelector:@selector(iconView)]) {
SBFolderIconView *iconView = (SBFolderIconView*)wrapperView.iconView;
if([iconView isKindOfClass:%c(SBFolderIconView)]) {
if([iconView isFolderIconView]) {
NSDictionary *methodDict = [iconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if(method != 4 && method != 8){
BOOL animated = (method == 0);
%orig(animated, nil);
[self _dismissAnimated:NO withCompletionHandler:nil];
if(method != 0) [iconView sf_method:methodDict withForceTouch:YES]; //DEES *****
return;
}
}
}
}
}
%orig;
}
%end
/*
* Protecting folders for those with BioProtect
* even fixing security breach introduced by BioProtect (to open apps by force touch)
*/
static BOOL isProtected = NO;
%hook SBApplicationShortcutMenu //iOS 9
- (void)menuContentView:(id)arg1 activateShortcutItem:(id)arg2 index:(long long)arg3 {
if(HAS_BIOPROTECT){
if([self.iconView isFolderIconView]) {
SBFolder* folder = ((SBFolderIconView *)self.iconView).folderIcon.folder;
SBIcon *firstIcon = [folder getFirstIcon];
NSString *bundleIdentifier = firstIcon.application.bundleIdentifier;
if ([[%c(BioProtectController) sharedInstance ] requiresAuthenticationForIdentifier: bundleIdentifier ] && !isProtected){
NSArray *arguments=[NSArray arrayWithObjects:[NSValue valueWithPointer:&arg1],[NSValue valueWithPointer:&arg2],[NSValue valueWithPointer:&arg3],NULL];
[[%c(BioProtectController) sharedInstance] authenticateForIdentifier:bundleIdentifier object:self selector:@selector(onBioProtectSuccessWithMenuContentView:activateShortcutItem:index:) arrayOfArgumentsAsNSValuePointers:arguments];
return;
}
}
}
isProtected = NO;
%orig;
}
%new - (void) onBioProtectSuccessWithMenuContentView:(id)arg1 activateShortcutItem:(id)arg2 index:(long long)arg3 {
isProtected = YES;
[self menuContentView:arg1 activateShortcutItem:arg2 index:arg3];
}
/**
* Some methods to let 3D Touch work on folder icons, and some animations
*
*/
- (void)interactionProgress:(id)arg1 didEnd:(_Bool)arg2 {
if (enabled && arg2 && self.iconView.isFolderIconView) {
NSDictionary *methodDict = [self.iconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
if(method != 4 && method != 0){
[self dismissAnimated:false completionHandler:nil];
[self.iconView sf_method:methodDict withForceTouch:YES];
return;
}
}
%orig;
}
- (void)dismissAnimated:(_Bool)arg1 completionHandler:(id)arg2{
if(enabled && arg1 && self.iconView.isFolderIconView) {
SBIconView *forceTouchIconView = MSHookIvar<SBIconView *>(self, "_proxyIconView");
SBFolderIconImageView *folderIconImageView = MSHookIvar<SBFolderIconImageView *>(forceTouchIconView, "_iconImageView");
UIImageView *folderImageView = MSHookIvar<UIImageView *>(folderIconImageView, "_leftWrapperView");
UIView* folderBackgroundView = MSHookIvar<UIView *>(folderIconImageView, "_backgroundView");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
if (folderIconImageView.customImageView.image != nil) [folderIconImageView.customImageView setAlpha:0.0];
else [folderImageView setAlpha:0.0];
[folderBackgroundView setAlpha:0.0];
[UIView commitAnimations];
}
%orig;
}
- (void)_finishPeekingWithCompletionHandler:(id)arg1 {
if(enabled && self.iconView.isFolderIconView) {
SBIconView *forceTouchIconView = MSHookIvar<SBIconView *>(self, "_proxyIconView");
SBFolderIconImageView *folderIconImageView = MSHookIvar<SBFolderIconImageView *>(forceTouchIconView, "_iconImageView");
UIImageView *folderImageView = MSHookIvar<UIImageView *>(folderIconImageView, "_leftWrapperView");
UIView* folderBackgroundView = MSHookIvar<UIView *>(folderIconImageView, "_backgroundView");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
if (folderIconImageView.customImageView.image != nil) [folderIconImageView.customImageView setAlpha:0.0];
else [folderImageView setAlpha:0.0];
[folderBackgroundView setAlpha:0.0];
[UIView commitAnimations];
}
%orig;
}
- (id)_shortcutItemsToDisplay {
//Sometimes the labelview of the forceTouchIconView isn't hidden, (even normal aplications) so in order to prevent that:
SBIconView *forceTouchIconView = MSHookIvar<SBIconView *>(self, "_proxyIconView");
forceTouchIconView.labelView.hidden = YES;
NSMutableArray *items = %orig;
if (enabled) {
NSDictionary *methodDict = [self.iconView getFolderSetting:@"ForceTouchMethod" withDefaultSetting:forceTouchMethod withDefaultCustomAppIndex:forceTouchMethodCustomAppIndex];
NSInteger method = [methodDict[@"method"] intValue];
//In order to set blurring on forceTouch folderIcons, where the first app doesn't support Force Touch, add a fake action
if ([items count] == 0 && self.iconView.isFolderIconView && method != 4 && method != 0) {
SBSApplicationShortcutItem *action = [[%c(SBSApplicationShortcutItem) alloc] init];
[action setLocalizedTitle:@"Fake Action"];
[items addObject:action];
}
}
return items;
}
%end
%hook SBIconView
/**
* Get folder specific settings
*
*/
%property (nonatomic, assign) id swipeUp;
%property (nonatomic, assign) id swipeDown;
%property (nonatomic, assign) id longHold;
%new - (BOOL)isFolderIconView {
return self.icon.isFolderIcon && !([self.icon respondsToSelector:@selector(isNewsstandIcon)] && self.icon.isNewsstandIcon);
}
%new - (NSDictionary*)getFolderSetting:(NSString*)setting withDefaultSetting:(NSInteger)globalSetting withDefaultCustomAppIndex:(NSInteger)globalAppIndex {
SBFolder *folder = ((SBIconView *)self).icon.folder;
NSDictionary *folderSettings = customFolderSettings[folder.folderID];
NSNumber *sendMethod = [NSNumber numberWithInt:globalSetting];
NSNumber *sendAppIndex = [NSNumber numberWithInt:globalAppIndex];
NSString *method = [NSString stringWithFormat:@"customFolder%@",setting];
if([folderSettings[@"customFolderFunctionallity"] intValue] == 1){
if([folderSettings objectForKey:method]) sendMethod = [NSNumber numberWithInt:[[folderSettings objectForKey:method] intValue]];
if([[folderSettings objectForKey:method] intValue] == 5){
NSString *appIndexSetting = [NSString stringWithFormat:@"customFolder%@CustomAppIndex",setting];
sendAppIndex = [NSNumber numberWithInt:[[folderSettings objectForKey:appIndexSetting] intValue]];
}
}
NSMutableDictionary *sendInfo = [NSMutableDictionary new];
[sendInfo setObject:sendMethod forKey:@"method"];
[sendInfo setObject:sendAppIndex forKey:@"customAppIndex"];
if(folderSettings[@"lastOpenedApp"]) [sendInfo setObject:folderSettings[@"lastOpenedApp"] forKey:@"lastOpenedApp"];
return sendInfo;
}
/**
* Add the last gestures to the folder icon
*
*/
- (void)setIcon:(SBIcon*)icon {
%orig;
//SBIconController* iconController = [%c(SBIconController) sharedInstance];
if (self.isFolderIconView) {
if(!self.swipeUp) {
self.swipeUp = [[%c(UISwipeGestureRecognizer) alloc] initWithTarget:self action:@selector(sf_swipeUp:)];