-
Notifications
You must be signed in to change notification settings - Fork 0
/
Smuggle.xm
198 lines (173 loc) · 6.17 KB
/
Smuggle.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
#import "Smuggle.h"
%group Smuggle
%hook SBAppSwitcherModel
-(id)appLayoutsIncludingHiddenAppLayouts:(BOOL)arg1 {
id r;
if(!editMode){
r = %orig(NO);
}else {
r = %orig(YES);
}
return r;
}
static SBAppSwitcherModel *__strong sharedInstance;
-(id)init {
id r = %orig;
sharedInstance = r;
return r;
}
%new
+(id)sharedInstance {
return sharedInstance;
}
%end
%hook SBTransitionSwitcherModifierEvent
-(long long)toEnvironmentMode {
long long r = %orig;
if(r == 2 && button) {
[UIView animateWithDuration:0.4 animations:^ {
button.alpha = 1;
buttonLabel.alpha = 1;
}];
}
return r;
}
-(long long)fromEnvironmentMode {
long long r = %orig;
if(r == 2 && button) {
[UIView animateWithDuration:0.15 animations:^ {
button.alpha = 0;
buttonLabel.alpha = 0;
}];
}
if(editMode) {
editMode = NO;
buttonLabel.text = @"Edit";
}
return r;
}
%end
%hook SBMainSwitcherViewController
-(BOOL)toggleMainSwitcherNoninteractivelyWithSource:(long long)arg1 animated:(BOOL)arg2 {
UIView *view1 = MSHookIvar<UIView*>(self, "_floatingSwitcherDimmingView");
UIView *view = view1.superview;
if(!button){
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
button.layer.cornerRadius = 16;
button.clipsToBounds = YES;
[view insertSubview:button atIndex:2];
button.translatesAutoresizingMaskIntoConstraints = false;
[button.centerXAnchor constraintEqualToAnchor:view.centerXAnchor constant:0].active = YES;
[button.bottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:-40].active = YES;
[button.widthAnchor constraintEqualToAnchor: view.widthAnchor multiplier:0.16].active = YES;
[button.heightAnchor constraintEqualToAnchor: view.heightAnchor multiplier:0.045].active = YES;
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
effectView.frame = button.bounds;
effectView.userInteractionEnabled = NO;
effectView.alpha = 0.60;
effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[button addSubview:effectView];
buttonLabel = [[UILabel alloc]initWithFrame:button.bounds];
buttonLabel.text = @"Edit";
buttonLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
buttonLabel.textAlignment = NSTextAlignmentCenter;
buttonLabel.textColor = [UIColor whiteColor];
[view insertSubview:buttonLabel atIndex:1];
buttonLabel.translatesAutoresizingMaskIntoConstraints = false;
[buttonLabel.topAnchor constraintEqualToAnchor:button.topAnchor constant:0].active = YES;
[buttonLabel.bottomAnchor constraintEqualToAnchor:button.bottomAnchor constant:0].active = YES;
[buttonLabel.leftAnchor constraintEqualToAnchor:button.leftAnchor constant:0].active = YES;
[buttonLabel.rightAnchor constraintEqualToAnchor:button.rightAnchor constant:0].active = YES;
}
return %orig;
}
%new
-(void)buttonPressed:(UIButton*)sender {
if(!editMode) {
editMode = YES;
buttonLabel.text = @"Done";
[[%c(SBMainSwitcherViewController) sharedInstance] toggleMainSwitcherNoninteractivelyWithSource:1 animated:NO];
[[%c(SBMainSwitcherViewController) sharedInstance] toggleMainSwitcherNoninteractivelyWithSource:1 animated:NO];
} else {
editMode = NO;
buttonLabel.text = @"Edit";
[[%c(SBMainSwitcherViewController) sharedInstance] toggleMainSwitcherNoninteractivelyWithSource:1 animated:NO];
[[%c(SBMainSwitcherViewController) sharedInstance] toggleMainSwitcherNoninteractivelyWithSource:1 animated:NO];
}
}
%end
%hook SBSwitcherAppSuggestionContentView
-(void)didMoveToWindow {
%orig;
}
%end
%hook SBFluidSwitcherItemContainer
-(void)_handlePageViewTap:(id)arg1 {
if(!editMode){
%orig;
} else {
[self handleTap:arg1];
}
}
%new
-(void)handleTap:(UITapGestureRecognizer*)gesture {
if(gesture.state != UIGestureRecognizerStateEnded) return;
SBReusableSnapshotItemContainer *container = (SBReusableSnapshotItemContainer*)gesture.view;
SBAppLayout *appLayout = container.snapshotAppLayout;
SBDisplayItem *appDisplay = [appLayout.rolesToLayoutItemsMap objectForKey:@1];
NSString *bundleID = appDisplay.bundleIdentifier;
if(![SparkAppList doesIdentifier:@"eu.kvaek.smuggleprefs" andKey:@"hiddenAppsSwitcher" containBundleIdentifier:bundleID]) {
[SparkAppList addBundleID:bundleID forIdentifier:@"eu.kvaek.smuggleprefs" andKey:@"hiddenAppsSwitcher"];
[container setAlpha:0.5];
}else {
[SparkAppList removeBundleID:bundleID forIdentifier:@"eu.kvaek.smuggleprefs" andKey:@"hiddenAppsSwitcher"];
[container setAlpha:1];
}
}
-(void)layoutSubviews {
%orig;
SBAppSwitcherReusableSnapshotView *snapshotView = (SBAppSwitcherReusableSnapshotView*)self.contentView;
SBAppLayout *appLayout = snapshotView.appLayout;
SBDisplayItem *appDisplay = [appLayout.rolesToLayoutItemsMap objectForKey:@1];
NSString *bundleID = appDisplay.bundleIdentifier;
if([SparkAppList doesIdentifier:@"eu.kvaek.smuggleprefs" andKey:@"hiddenAppsSwitcher" containBundleIdentifier:bundleID]) {
SBApplication *currentApp = [(SpringBoard*)[UIApplication sharedApplication] _accessibilityFrontMostApplication];
NSString *currentAppBundle = [currentApp bundleIdentifier];
if(currentAppBundle == bundleID) return;
SBAppSwitcherModel *appSwitcherModel = [%c(SBAppSwitcherModel) sharedInstance];
if(editMode) {
[self setAlpha:0.5];
} else {
[appSwitcherModel hide:appLayout];
}
}
}
%end
%hook SBIconListModel
-(id)insertIcon:(id)arg1 atIndex:(unsigned long long)arg2 options:(unsigned long long)arg3 {
if([SparkAppList doesIdentifier:@"eu.kvaek.smuggleprefs" andKey:@"hiddenAppsHS" containBundleIdentifier:[arg1 applicationBundleID]]){
return nil;
}else {
return %orig;
}
}
-(BOOL)addIcon:(id)arg1 asDirty:(BOOL)arg2 {
if([SparkAppList doesIdentifier:@"eu.kvaek.smuggleprefs" andKey:@"hiddenAppsHS" containBundleIdentifier:[arg1 applicationBundleID]]){
return nil;
}else {
return %orig;
}
}
%end
%end
%ctor {
// Prefs
HBPreferences *preferences = [[HBPreferences alloc] initWithIdentifier:@"eu.kvaek.smuggleprefs"];
[preferences registerBool:&tweakEnabled default:NO forKey:@"tweakEnabled"];
if(tweakEnabled) {
log(@"Loading tweak..");
%init(Smuggle);
}
}