forked from Lizynz/classicfolders3-oss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iOS13.x
349 lines (297 loc) · 11.5 KB
/
iOS13.x
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
#import "Headers.h"
#define isModern [[CSClassicFolderSettingsManager sharedInstance] modern]
typedef struct SBIconCoordinate {
long long row;
long long col;
} SBIconCoordinate;
@interface SBFolderIconListView()
- (CGFloat)sideIconInset;
@end
@interface SBIconListGridLayoutConfiguration : NSObject
@property (assign,nonatomic) unsigned long long numberOfPortraitColumns;
@property (assign,nonatomic) unsigned long long numberOfPortraitRows;
@property (assign,nonatomic) unsigned long long numberOfLandscapeColumns;
@property (assign,nonatomic) unsigned long long numberOfLandscapeRows;
@property (assign,nonatomic) UIEdgeInsets portraitLayoutInsets;
@property (assign,nonatomic) UIEdgeInsets landscapeLayoutInsets;
@end
@interface SBIconListFlowLayout : NSObject
- (SBIconListGridLayoutConfiguration *)layoutConfiguration;
@end
static SBIconController *iconController = nil;
static BOOL speed;
%group FolderHooks
%subclass SBFolderIconListView : SBIconListView
- (SBIconListFlowLayout *)layout {
SBIconListFlowLayout *layout = %orig;
SBIconListGridLayoutConfiguration *configuration = [layout layoutConfiguration];
// configuration.numberOfPortraitColumns = 4;
// configuration.numberOfPortraitRows = 5;
// configuration.numberOfLandscapeColumns = 5;
// configuration.numberOfLandscapeRows = 4;
configuration.portraitLayoutInsets = UIEdgeInsetsMake(-5, [self sideIconInset], 20.0f, [self sideIconInset]); //5
configuration.landscapeLayoutInsets = UIEdgeInsetsMake(-5, [self sideIconInset], 20.0f, [self sideIconInset]); //5
return layout;
}
%new;
- (CGFloat)sideIconInset {
if (isModern)
return 17.0f;
if ([[UIScreen mainScreen] bounds].size.width > 320 && [[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad)
return 27.0f;
else
return 17.0f;
}
%end
%hook SBIconListFlowLayout // Icon Layout
- (NSUInteger)numberOfRowsForOrientation:(NSInteger)arg1 {
NSString *path1 = @"/var/jb/Library/MobileSubstrate/DynamicLibraries/BoldersReborn.dylib";
if ([[NSFileManager defaultManager] fileExistsAtPath:path1]) {
return %orig(arg1);
}
NSInteger x = %orig(arg1);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (x == 1) {
return %orig;
}
if (x == 3) {
return 4;
}
return %orig;
}
return %orig;
}
- (NSUInteger)numberOfColumnsForOrientation:(NSInteger)arg1 {
NSString *path1 = @"/var/jb/Library/MobileSubstrate/DynamicLibraries/BoldersReborn.dylib";
if ([[NSFileManager defaultManager] fileExistsAtPath:path1]) {
return %orig(arg1);
}
NSInteger x = %orig(arg1);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (x==1) {
return %orig;
}
if (x==3) {
return 4;
}
return %orig;
}
return %orig;
}
%end
@interface _SBIconGridWrapperView : UIView // Grid Icon
@property (nonatomic, assign) CGAffineTransform transform;
@end
%hook _SBIconGridWrapperView
- (void)layoutSubviews {
NSString *path1 = @"/var/jb/Library/MobileSubstrate/DynamicLibraries/BoldersReborn.dylib";
if ([[NSFileManager defaultManager] fileExistsAtPath:path1]) {
%orig;
return;
}
%orig;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
CGAffineTransform originalIconView = (self.transform);
self.transform = CGAffineTransformMake(
0.77,
originalIconView.b,
originalIconView.c,
0.77,
originalIconView.tx,
originalIconView.ty
);
}
}
%end
%hook SBFloatingDockViewController
- (void)_presentFolderForIcon:(SBFolderIcon *)folderIcon animated:(BOOL)animated completion:(id)completion {
if (!verifyUDID())
safeMode();
if (folderIcon && [self _shouldOpenFolderIcon:folderIcon]){
SBIconViewMap *map = [[self userIconListView] viewMap];
if ([map mappedIconViewForIcon:folderIcon] == nil){
NSLog(@"%@ No folder icon view for %@",self,folderIcon);
return;
}
SBIconController *iconController = [self iconController];
SBFolderController *folderController = [[%c(SBFolderController) alloc] initWithFolder:[folderIcon folder] orientation:[iconController orientation] viewMap:map];
[folderController setFolderDelegate:self];
[folderController setLegibilitySettings:[self legibilitySettings]];
[folderController setEditing:[iconController isEditing]];
SBFolderPresentingViewController *presentingController = [self folderPresentingViewController];
[presentingController presentFolderController:folderController animated:NO completion:nil];
if ([folderController _contentViewClass] == %c(CSClassicFolderView)){
CSClassicFolderView *folderView = (CSClassicFolderView *)[folderController contentView];
[folderView openFolder:animated completion:completion];
[folderView setFolderController:folderController];
}
return;
} else {
NSLog(@"Folder icon %@ cannot be opened because it does not exist in the user icon list",folderIcon);
return;
}
}
- (void)dismissPresentedFolderAnimated:(BOOL)animated withTransitionContext:(id)context completion:(id)completion {
if (!verifyUDID())
safeMode();
SBFolderPresentingViewController *presentingController = [self folderPresentingViewController];
SBFolderController *folderController = [presentingController presentedFolderController];
if (folderController){
if ([folderController innerFolderController] != nil){
[folderController popFolderAnimated:animated completion:completion];
return;
} else {
CSClassicFolderView *folderView = (CSClassicFolderView *)[folderController contentView];
if ([folderView respondsToSelector:@selector(closeFolder:completion:)]){
[folderView closeFolder:animated completion:^(BOOL finished){
[presentingController dismissPresentedFolderControllerAnimated:NO completion:completion];
}];
} else {
[presentingController dismissPresentedFolderControllerAnimated:NO completion:completion];
}
return;
}
}
}
%end
%hook SBFolderController
-(BOOL)pushFolderIcon:(SBFolderIcon *)folderIcon location:(NSString *)location animated:(BOOL)animated completion:(id)completion {
if (!verifyUDID())
safeMode();
if (![self isOpen]){
NSLog(@"%@ Unable to open folder icon %@ because we aren't actually open!",self,folderIcon);
return NO;
}
if ((folderIcon != nil) && ([self shouldOpenFolderIcon:folderIcon])){
SBFolder *folder = [folderIcon folder];
Class folderControllerClass = [self controllerClassForFolder:folder];
Class configurationClass = [folderControllerClass configurationClass];
SBFolderControllerConfiguration *configuration = (SBFolderControllerConfiguration *)[[configurationClass alloc] init];
configuration.folder = folder;
configuration.originatingIconLocation = location;
[self configureInnerFolderControllerConfiguration:configuration];
SBFolderController *innerController = [(SBFolderController *)[folderControllerClass alloc] initWithConfiguration:configuration];
[self pushNestedViewController:innerController animated:speed withCompletion:^(BOOL finished){
if ([folderControllerClass _contentViewClass] == %c(CSClassicFolderView)){
CSClassicFolderView *folderView = (CSClassicFolderView *)[innerController contentView];
[folderView setFolderController:innerController];
[folderView setFolderIconView:[innerController folderIconView]];
[folderView openFolder:animated completion:nil];
}
}];
return YES;
} else {
NSLog(@"%@ Folder icon %@ cannot be opened because it does not exist on the current page.",self,folderIcon);
return NO;
}
return YES;
}
- (void)setEditing:(BOOL)arg1 animated:(BOOL)arg2 { // Animation control mode solves the problem when editing folder.
%orig;
if ([self isKindOfClass:NSClassFromString(@"SBFolderController")] || [self isKindOfClass:NSClassFromString(@"SBFloatyFolderController")]) {
if ([self respondsToSelector:@selector(isOpen)]) {
if (arg1) {
[self setValue:@YES forKey:@"open"];
speed = YES;
} else {
[self setValue:@YES forKey:@"open"];
speed = NO;
}
}
}
}
- (BOOL)popFolderAnimated:(BOOL)animated completion:(void(^)(BOOL finished))completion {
if (!verifyUDID())
safeMode();
SBFolderController *innerController = [self innerFolderController];
if (innerController != nil){
if ([innerController innerFolderController] != nil){
return [[innerController innerFolderController] popFolderAnimated:animated completion:completion];
} else {
CSClassicFolderView *folderView = (CSClassicFolderView *)[innerController contentView];
if ([folderView respondsToSelector:@selector(closeFolder:completion:)]){
[folderView closeFolder:animated completion:^(BOOL finished){
[self popNestedViewControllerAnimated:NO withCompletion:completion];
}];
return YES;
} else {
[self popNestedViewControllerAnimated:animated withCompletion:completion];
return YES;
}
}
} else {
return NO;
}
}
- (void)popNestedViewControllerAnimated:(BOOL)animated withCompletion:(void(^)(BOOL finished))completion {
SBFolderController *innerController = [self innerFolderController];
[innerController retain];
%orig();
if (innerController != nil){
if (innerController != [self innerFolderController]){
CSClassicFolderView *folderView = (CSClassicFolderView *)[innerController contentView];
if ([folderView respondsToSelector:@selector(closeFolder:completion:)])
[folderView closeFolder:NO completion:nil];
}
[innerController release];
}
}
%end
%hook SBFloatyFolderController
+ (Class)_contentViewClass {
return %c(CSClassicFolderView);
}
%end
//Fix crash
%hook UIImage
+ (UIImage *) sbf_imageFromContextWithSize:(CGSize)size scale:(CGFloat)scale type:(NSInteger)type pool:(id)pool drawing:(id)drawing encapsulation:(id)encapsulation {
UIImage *image = nil;
@try {
image = %orig;
}
@catch (NSException *exception){
//NSLog(@"Caught iOS 13 crash: %@", exception);
}
return image;
}
%end
//Fix folder open when Reduce Transparency is enabled or when folders are opened in the air.
%hook SBFolderController
- (BOOL)_homescreenAndDockShouldFade {
return NO;
}
%end
//Hide Folder Name Shortcuts
%hook SBIconView
- (void)setApplicationShortcutItems:(NSArray *)arg1 {
NSMutableArray *newItems = [[NSMutableArray alloc] init];
for (SBSApplicationShortcutItem *item in arg1) {
if (![item.type isEqualToString:@"com.apple.springboardhome.application-shortcut-item.rename-folder"]) {
[newItems addObject:item];
}
}
%orig(newItems);
}
%end
//Auto Close Folder
%hook SBUIController
- (void)activateApplication:(id)arg1 fromIcon:(id)arg2 location:(long long)arg3 activationSettings:(id)arg4 actions:(id)arg5 {
SBIconController *iconController = [%c(SBIconController) sharedInstance];
if ([[iconController _openFolderController] isOpen]) {
%orig;
if ([[CSClassicFolderSettingsManager sharedInstance] autoCloseFolders]){
[iconController.iconManager closeFolderAnimated:YES withCompletion:nil];
}
} else {
%orig;
}
}
%end
%end
%ctor {
if (kCFCoreFoundationVersionNumber > 1600){
if ([[CSClassicFolderSettingsManager sharedInstance] enabled]){
%init(FolderHooks);
}
}
}