/
ControlCenter.xm
90 lines (77 loc) · 3.72 KB
/
ControlCenter.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
#import "HeaderFiles.h"
#import <Traverse/Traverse.h>
#include <objc/runtime.h>
@interface SBControlCenterController : UIViewController
+ (id)sharedInstance;
- (BOOL)isVisible;
@end
@interface SBApplicationShortcutMenu ()
- (id)my_shortcutItemsToDisplay;
@end
%hook SBApplicationShortcutMenu
+ (void)initialize {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class myClass = [self class];
SEL originalSelector = @selector(_shortcutItemsToDisplay);
SEL swizzledSelector = @selector(my_shortcutItemsToDisplay);
Method originalMethod = class_getInstanceMethod(myClass, originalSelector);
Method swizzledMethod = class_getInstanceMethod(myClass, swizzledSelector);
BOOL didAddMethod = class_addMethod(myClass,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(myClass,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
HBLogDebug(@"Swizzling '-(id)_shortcutItemsToDisplay;'");
});
}
- (id)initWithFrame:(struct CGRect)arg1 application:(id)arg2 iconView:(id)arg3 interactionProgress:(id)arg4 orientation:(long long)arg5 {
self = %orig;
if ([((SBIconView*)arg3).superview isKindOfClass:NSClassFromString(@"SBControlCenterButton")]) {
}
return self;
}
%new
- (id)my_shortcutItemsToDisplay {
HBLogDebug(@"Calling swizzled method for '-(id)_shortcutItemsToDisplay;'");
NSMutableArray *objects = [[self my_shortcutItemsToDisplay] mutableCopy];
if ([[NSClassFromString(@"SBControlCenterController") sharedInstance] isVisible] != YES || self.application.bundleIdentifier == nil) {
return objects;
}
// NSArray *aryObjects;
// NSUserDefaults *prefs = [[NSUserDefaults alloc] initWithSuiteName:@"com.bolencki13.customft"];
// if ([prefs integerForKey:@"CCActionType"] == 0) {
// aryObjects = [[TRShortCutManager sharedInstance] shortCutsForAppWithBundleID:bundleID withType:TRShortCutTypeControlCenter];
// } else if ([prefs integerForKey:@"CCActionType"] == 1) {
// aryObjects = [[TRShortCutManager sharedInstance] shortCutsForAppWithBundleID:bundleID withType:TRShortCutTypeSpringboard];
// } else {
// aryObjects = [[TRShortCutManager sharedInstance] shortCutsForAppWithBundleID:bundleID withType:TRShortCutTypeAll];
// }
NSUserDefaults *prefs = [[NSUserDefaults alloc] initWithSuiteName:@"com.bolencki13.customft"];
if ([prefs boolForKey:@"addMenu"] == YES) {
if ([prefs boolForKey:@"addNotEvery"] == NO) {
SBSApplicationShortcutItem *newAction = [[SBSApplicationShortcutItem alloc] init];
[newAction setIcon:[[SBSApplicationShortcutSystemIcon alloc] initWithType:UIApplicationShortcutIconTypeAdd]];
[newAction setLocalizedTitle:@"New"];
[newAction setLocalizedSubtitle:@"Add New Action"];
[newAction setType:@"com.bolencki13.customft-newAction"];
[objects addObject:newAction];
} else if ([prefs boolForKey:@"addNotEvery"] == YES && [objects count] == 0) {
SBSApplicationShortcutItem *newAction = [[SBSApplicationShortcutItem alloc] init];
[newAction setIcon:[[SBSApplicationShortcutSystemIcon alloc] initWithType:UIApplicationShortcutIconTypeAdd]];
[newAction setLocalizedTitle:@"New"];
[newAction setLocalizedSubtitle:@"Add New Action"];
[newAction setType:@"com.bolencki13.customft-newAction"];
[objects addObject:newAction];
}
}
return objects;
}
%end