-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTweak.xm
executable file
·424 lines (348 loc) · 17.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
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h>
extern "C" void AudioServicesPlaySystemSoundWithVibration(SystemSoundID inSystemSoundID, id unknown, NSDictionary *options);
@interface UIView (Force3DPrivate)
-(id)_gestureRecognizers;
@end
@interface SBUIIconForceTouchIconViewWrapperView : UIView
@end
@interface SBUIIconForceTouchWrapperViewController : UIViewController
@end
@interface SBUIIconForceTouchViewController : UIViewController {
SBUIIconForceTouchWrapperViewController *_primaryViewController;
SBUIIconForceTouchWrapperViewController *_secondaryViewController;
SBUIIconForceTouchIconViewWrapperView *_iconViewWrapperViewBelow;
SBUIIconForceTouchIconViewWrapperView *_iconViewWrapperViewAbove;
}
@end
@interface SBUIIconForceTouchController : NSObject {
SBUIIconForceTouchViewController *_iconForceTouchViewController;
}
+(BOOL)_isPeekingOrShowing;
@end
@interface SBUIAppIconForceTouchController : NSObject {
SBUIIconForceTouchController *_iconForceTouchController;
}
-(void)_setupWithGestureRecognizer:(id)arg1;
-(void)_presentAnimated:(BOOL)arg1 withCompletionHandler:(id)arg2;
-(void)dismissAnimated:(BOOL)arg1 withCompletionHandler:(id)arg2;
-(void)_peekAnimated:(BOOL)arg1 withRelativeTouchForce:(CGFloat)arg2 allowSmoothing:(BOOL)arg3;
-(void)setDataSource:(id)arg1;
-(void)setDelegate:(id)arg1;
@end
@interface SBIconController {
SBUIAppIconForceTouchController *_appIconForceTouchController;
}
+(id)sharedInstance;
-(void)_dismissAppIconForceTouchControllerIfNecessaryAnimated:(BOOL)arg1 withCompletionHandler:(id)arg2;
-(BOOL)_appIconForceTouchGestureRecognizerShouldBegin;
-(void)_cancelAppIconForceTouchGestureAndBeginEditing;
-(BOOL)isEditing;
@end
@interface SBIconView : UIView
@property (nonatomic,retain) UIGestureRecognizer *appIconForceTouchGestureRecognizer;
@property (nonatomic,assign) BOOL didPresentAfterPeek;
-(void)_handleSecondHalfLongPressTimer:(id)arg1;
-(void)cancelLongPressTimer;
-(void)cancelDrag;
-(SBUIIconForceTouchViewController *)_iconForceTouchViewController;
-(void)_configureLongPress3DTouchGesture;
@end
@interface FBSystemService
+(id)sharedInstance;
-(void)exitAndRelaunch:(BOOL)arg1;
@end
#define kIdentifier @"com.dgh0st.force3dappshortcuts"
#define kSettingsPath @"/var/mobile/Library/Preferences/com.dgh0st.force3dappshortcuts.plist"
#define kSettingsChangedNotification (CFStringRef)@"com.dgh0st.force3dappshortcuts/settingschanged"
#define kRespringNotification (CFStringRef)@"com.dgh0st.force3dappshortcuts/respring"
typedef enum GestureType : NSInteger {
doubleTap = 0,
swipeUp,
swipeDown,
swipeLeft,
swipeRight
} GestureType;
static BOOL isEnabled = YES;
static CGFloat longPressDuration = 0.2;
static CGFloat peekDuration = 0.175;
static CGFloat peekTouchForce = 0.5;
static BOOL isAutoDismissEnabled = YES;
static GestureType editingGesture = swipeUp;
static BOOL isVibrationEnabled = YES;
static NSInteger vibrationDuration = 30;
static CGFloat vibrationIntensity = 2.0;
static void reloadPrefs() {
CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
NSDictionary *prefs = nil;
if ([NSHomeDirectory() isEqualToString:@"/var/mobile"]) {
CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (keyList != nil) {
prefs = (NSDictionary *)CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (prefs == nil)
prefs = [[NSDictionary alloc] init];
CFRelease(keyList);
}
} else {
prefs = [[NSDictionary alloc] initWithContentsOfFile:kSettingsPath];
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
longPressDuration = [prefs objectForKey:@"longPressDuration"] ? [[prefs objectForKey:@"longPressDuration"] floatValue] : 0.2;
peekDuration = [prefs objectForKey:@"peekDuration"] ? [[prefs objectForKey:@"peekDuration"] floatValue] : 0.175;
peekTouchForce = [prefs objectForKey:@"peekTouchForce"] ? [[prefs objectForKey:@"peekTouchForce"] floatValue] : 0.5;
isAutoDismissEnabled = [prefs objectForKey:@"isAutoDismissEnabled"] ? [[prefs objectForKey:@"isAutoDismissEnabled"] boolValue] : YES;
editingGesture = [prefs objectForKey:@"editingGesture"] ? ((GestureType)[[prefs objectForKey:@"editingGesture"] intValue]) : swipeUp;
isVibrationEnabled = [prefs objectForKey:@"isVibrationEnabled"] ? [[prefs objectForKey:@"isVibrationEnabled"] boolValue] : YES;
vibrationDuration = [prefs objectForKey:@"vibrationDuration"] ? [[prefs objectForKey:@"vibrationDuration"] intValue] : 30;
vibrationIntensity = [prefs objectForKey:@"vibrationIntensity"] ? [[prefs objectForKey:@"vibrationIntensity"] floatValue] : 2.0;
[prefs release];
}
static void respringDevice() {
[[%c(FBSystemService) sharedInstance] exitAndRelaunch:YES];
}
static void hapticFeedback() {
if (isVibrationEnabled) {
NSMutableDictionary* dictionary = [NSMutableDictionary dictionary];
NSMutableArray* array = [NSMutableArray array];
[array addObject:[NSNumber numberWithBool:YES]];
[array addObject:[NSNumber numberWithInt:vibrationDuration]];
[dictionary setObject:array forKey:@"VibePattern"];
[dictionary setObject:[NSNumber numberWithFloat:vibrationIntensity] forKey:@"Intensity"];
AudioServicesPlaySystemSoundWithVibration(4095, nil, dictionary);
}
}
// Zenith Compatibility (it requires an oldView property)
@interface Force3DLongPressGestureRecognizer : UILongPressGestureRecognizer
@property (nonatomic, retain) UIView *oldView;
@end
@implementation Force3DLongPressGestureRecognizer
-(id)initWithTarget:(id)arg1 action:(SEL)arg2 {
self = [super initWithTarget:arg1 action:arg2];
if (self != nil)
self.oldView = nil;
return self;
}
-(void)dealloc {
[self.oldView release];
self.oldView = nil;
[super dealloc];
}
@end
@interface Force3DSwipeGestureRecognizer : UISwipeGestureRecognizer
@end
@implementation Force3DSwipeGestureRecognizer
@end
@interface Force3DTapGestureRecognizer : UITapGestureRecognizer
@end
@implementation Force3DTapGestureRecognizer
@end
%hook SBIconView
%property (nonatomic, assign) BOOL didPresentAfterPeek;
// Fixes gestures not being registered the first time homescreeen is invoked
-(id)initWithContentType:(NSUInteger)arg1 {
self = %orig(arg1);
if (isEnabled && self != nil)
[self _configureLongPress3DTouchGesture];
return self;
}
-(void)setLocation:(NSInteger)arg1 {
if (isEnabled)
[self _configureLongPress3DTouchGesture];
%orig(arg1);
}
-(void)_updateIconImageViewAnimated:(BOOL)arg1 {
if (isEnabled)
[self _configureLongPress3DTouchGesture];
%orig(arg1);
}
-(void)_applyEditingStateAnimated:(BOOL)arg1 {
if (isEnabled)
[self _configureLongPress3DTouchGesture];
%orig(arg1);
}
-(void)dealloc {
self.appIconForceTouchGestureRecognizer = nil;
%orig();
}
%new
-(void)_configureLongPress3DTouchGesture {
NSArray *gestureRecognizers = [[self _gestureRecognizers] copy];
for (UIGestureRecognizer *gestureRecognizer in gestureRecognizers)
if ([gestureRecognizer isKindOfClass:[Force3DLongPressGestureRecognizer class]] || [gestureRecognizer isKindOfClass:[Force3DSwipeGestureRecognizer class]] || [gestureRecognizer isKindOfClass:[Force3DTapGestureRecognizer class]])
[self removeGestureRecognizer:gestureRecognizer];
[gestureRecognizers release];
self.appIconForceTouchGestureRecognizer = nil;
if (![[%c(SBIconController) sharedInstance] isEditing]) {
Force3DLongPressGestureRecognizer *appIconForceTouchGestureRecognizer = [[Force3DLongPressGestureRecognizer alloc] initWithTarget:self action:@selector(_handle3DTouchLongPress:)];
appIconForceTouchGestureRecognizer.minimumPressDuration = longPressDuration;
UIGestureRecognizer *editingGestureRecognizer = nil;
if (editingGesture == swipeUp || editingGesture == swipeDown || editingGesture == swipeLeft || editingGesture == swipeRight) {
editingGestureRecognizer = [[Force3DSwipeGestureRecognizer alloc] initWithTarget:self action:@selector(_handleEditingeditingGestureRecognizer:)];
if (editingGesture == swipeUp)
((Force3DSwipeGestureRecognizer *)editingGestureRecognizer).direction = UISwipeGestureRecognizerDirectionUp;
else if (editingGesture == swipeDown)
((Force3DSwipeGestureRecognizer *)editingGestureRecognizer).direction = UISwipeGestureRecognizerDirectionDown;
else if (editingGesture == swipeLeft)
((Force3DSwipeGestureRecognizer *)editingGestureRecognizer).direction = UISwipeGestureRecognizerDirectionLeft;
else
((Force3DSwipeGestureRecognizer *)editingGestureRecognizer).direction = UISwipeGestureRecognizerDirectionRight;
// [self addGestureRecognizer:self.editingGestureRecognizer];
} else if (editingGesture == doubleTap) {
editingGestureRecognizer = [[Force3DTapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleEditingeditingGestureRecognizer:)];
((Force3DTapGestureRecognizer *)editingGestureRecognizer).numberOfTapsRequired = 2;
}
[self addGestureRecognizer:editingGestureRecognizer];
self.appIconForceTouchGestureRecognizer = [appIconForceTouchGestureRecognizer autorelease];
[editingGestureRecognizer release];
}
}
%new
-(void)_handle3DTouchLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
SBIconController *_iconController = [%c(SBIconController) sharedInstance];
if ([_iconController isEditing])
return; // do nothing when editing enabled
if ([_iconController _appIconForceTouchGestureRecognizerShouldBegin] && gestureRecognizer.state == UIGestureRecognizerStateBegan) {
// stop from going into editing mode or dragging mode
SBIconView *iconView = (SBIconView *)gestureRecognizer.view;
if ([iconView respondsToSelector:@selector(cancelLongPressTimer)])
[iconView cancelLongPressTimer];
else if ([iconView respondsToSelector:@selector(cancelDrag)])
[iconView cancelDrag];
// create shortcuts and peek
SBUIAppIconForceTouchController *_forceTouchAppController = [[%c(SBUIAppIconForceTouchController) alloc] init];
[_forceTouchAppController setDelegate:_iconController];
[_forceTouchAppController setDataSource:_iconController];
MSHookIvar<SBUIAppIconForceTouchController *>(_iconController, "_appIconForceTouchController") = _forceTouchAppController;
[_forceTouchAppController _setupWithGestureRecognizer:gestureRecognizer];
[_forceTouchAppController _peekAnimated:YES withRelativeTouchForce:peekTouchForce allowSmoothing:NO];
self.didPresentAfterPeek = NO;
// display shortcuts after a delay
[self performSelector:@selector(_display3DTouchShortcuts:) withObject:_forceTouchAppController afterDelay:peekDuration];
} else if (!self.didPresentAfterPeek && gestureRecognizer.state == UIGestureRecognizerStateChanged) {
// dismiss peeked shortcut if finger left icon view
SBUIAppIconForceTouchController *_forceTouchAppController = MSHookIvar<SBUIAppIconForceTouchController *>([%c(SBIconController) sharedInstance], "_appIconForceTouchController");
CGPoint location = [gestureRecognizer locationInView:self];
if (!CGRectContainsPoint(self.bounds, location))
[_forceTouchAppController dismissAnimated:YES withCompletionHandler:nil];
} else if (isAutoDismissEnabled && (gestureRecognizer.state == UIGestureRecognizerStateEnded || gestureRecognizer.state == UIGestureRecognizerStateRecognized)) {
// auto dimiss shortcuts menu if finger lifted outside the shortcuts menu view
SBUIAppIconForceTouchController *_forceTouchAppController = MSHookIvar<SBUIAppIconForceTouchController *>([%c(SBIconController) sharedInstance], "_appIconForceTouchController");
if (_forceTouchAppController != nil) {
SBUIIconForceTouchViewController *_iconForceTouchViewController = [self _iconForceTouchViewController];
if (_iconForceTouchViewController != nil) {
BOOL shouldDismiss = NO;
SBUIIconForceTouchWrapperViewController *_primaryViewController = MSHookIvar<SBUIIconForceTouchWrapperViewController *>(_iconForceTouchViewController, "_primaryViewController");
if (_primaryViewController != nil) {
// dismiss if not within the shortcuts view
CGPoint location = [gestureRecognizer locationInView:_primaryViewController.view];
shouldDismiss = !CGRectContainsPoint(_primaryViewController.view.bounds, location);
}
if (shouldDismiss) {
SBUIIconForceTouchWrapperViewController *_secondaryViewController = MSHookIvar<SBUIIconForceTouchWrapperViewController *>(_iconForceTouchViewController, "_secondaryViewController");
if (_secondaryViewController != nil) {
// dismiss if not within the shortcuts view
CGPoint location = [gestureRecognizer locationInView:_secondaryViewController.view];
shouldDismiss = !CGRectContainsPoint(_secondaryViewController.view.bounds, location);
}
}
if (shouldDismiss)
[_forceTouchAppController dismissAnimated:YES withCompletionHandler:nil];
}
}
}
}
%new
-(void)_display3DTouchShortcuts:(SBUIAppIconForceTouchController *)forceTouchAppController {
self.didPresentAfterPeek = YES;
if (forceTouchAppController != nil) {
if (self.appIconForceTouchGestureRecognizer.state == UIGestureRecognizerStateBegan || self.appIconForceTouchGestureRecognizer.state == UIGestureRecognizerStateChanged || self.appIconForceTouchGestureRecognizer.state == UIGestureRecognizerStateEnded || self.appIconForceTouchGestureRecognizer.state == UIGestureRecognizerStateRecognized) {
SBUIIconForceTouchViewController *_iconForceTouchViewController = [self _iconForceTouchViewController];
if (_iconForceTouchViewController != nil) {
BOOL shouldPresent = NO;
SBUIIconForceTouchIconViewWrapperView *_iconViewWrapperViewAbove = MSHookIvar<SBUIIconForceTouchIconViewWrapperView *>(_iconForceTouchViewController, "_iconViewWrapperViewAbove");
if (_iconViewWrapperViewAbove != nil) {
// display if within the icon view
CGPoint location = [self.appIconForceTouchGestureRecognizer locationInView:_iconViewWrapperViewAbove];
shouldPresent = CGRectContainsPoint(_iconViewWrapperViewAbove.bounds, location);
}
if (!shouldPresent) {
SBUIIconForceTouchIconViewWrapperView *_iconViewWrapperViewBelow = MSHookIvar<SBUIIconForceTouchIconViewWrapperView *>(_iconForceTouchViewController, "_iconViewWrapperViewBelow");
if (_iconViewWrapperViewBelow != nil) {
// display if within the icon view
CGPoint location = [self.appIconForceTouchGestureRecognizer locationInView:_iconViewWrapperViewBelow];
shouldPresent = CGRectContainsPoint(_iconViewWrapperViewBelow.bounds, location);
}
}
if (shouldPresent) {
// haptic feedback
hapticFeedback();
// display shortcut menu
[forceTouchAppController _presentAnimated:YES withCompletionHandler:nil];
return;
}
}
// dismiss peeked shortcuts (if execution ever reaches this point then it means something went wrong)
[forceTouchAppController dismissAnimated:YES withCompletionHandler:nil];
} else {
// dismiss peeked shortcuts
[forceTouchAppController dismissAnimated:YES withCompletionHandler:nil];
}
}
}
%new
-(SBUIIconForceTouchViewController *)_iconForceTouchViewController {
SBUIAppIconForceTouchController *_forceTouchAppController = MSHookIvar<SBUIAppIconForceTouchController *>([%c(SBIconController) sharedInstance], "_appIconForceTouchController");
if (_forceTouchAppController != nil) {
SBUIIconForceTouchController *_iconForceTouchController = MSHookIvar<SBUIIconForceTouchController *>(_forceTouchAppController, "_iconForceTouchController");
if (_iconForceTouchController != nil)
return (SBUIIconForceTouchViewController *)MSHookIvar<SBUIIconForceTouchViewController *>(_iconForceTouchController, "_iconForceTouchViewController");
}
return nil;
}
%new
-(void)_handleEditingeditingGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
// go into editing mode
if ([self respondsToSelector:@selector(_handleSecondHalfLongPressTimer:)])
[self _handleSecondHalfLongPressTimer:nil];
else if ([[%c(SBIconController) sharedInstance] respondsToSelector:@selector(_cancelAppIconForceTouchGestureAndBeginEditing)])
[[%c(SBIconController) sharedInstance] _cancelAppIconForceTouchGestureAndBeginEditing];
}
-(void)_updateJitter {
// just incase anything goes wrong (code from RevealMenu)
if (isEnabled)
[[%c(SBIconController) sharedInstance] _dismissAppIconForceTouchControllerIfNecessaryAnimated:YES withCompletionHandler:nil];
%orig();
}
-(void)setHighlighted:(BOOL)arg1 {
%orig(arg1);
if (arg1 && isEnabled && ![[%c(SBIconController) sharedInstance] isEditing]) {
if ([self respondsToSelector:@selector(cancelLongPressTimer)])
[self cancelLongPressTimer];
else if ([self respondsToSelector:@selector(cancelDrag)])
[self cancelDrag];
}
}
%end
%hook SBIconController
-(void)appIconForceTouchController:(id)arg1 didDismissForGestureRecognizer:(id)arg2 {
%orig(arg1, arg2);
SBUIAppIconForceTouchController *&_forceTouchAppController = MSHookIvar<SBUIAppIconForceTouchController *>(self, "_appIconForceTouchController");
[_forceTouchAppController release];
_forceTouchAppController = nil;
}
-(void)dealloc {
SBUIAppIconForceTouchController *&_forceTouchAppController = MSHookIvar<SBUIAppIconForceTouchController *>(self, "_appIconForceTouchController");
[_forceTouchAppController release];
_forceTouchAppController = nil;
%orig();
}
%end
%dtor {
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, kSettingsChangedNotification, NULL);
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, kRespringNotification, NULL);
}
%ctor {
reloadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)reloadPrefs, kSettingsChangedNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)respringDevice, kRespringNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
}