-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTweak.xm
522 lines (454 loc) · 27.2 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
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
#include "DVirtualHome.h"
#include <notify.h>
static void preferencesChanged() {
CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
NSDictionary *prefs = nil;
if ([NSHomeDirectory() isEqualToString:@"/var/mobile"]) {
CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (keyList) {
prefs = (NSDictionary *)CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (!prefs) {
prefs = [NSDictionary new];
}
CFRelease(keyList);
}
} else {
prefs = [[NSDictionary alloc] initWithContentsOfFile:kSettingsPath];
}
if (prefs) {
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
singleTapAction = [prefs objectForKey:@"singleTapAction"] ? (Action)[[prefs objectForKey:@"singleTapAction"] intValue] : home;
doubleTapAction = [prefs objectForKey:@"doubleTapAction"] ? (Action)[[prefs objectForKey:@"doubleTapAction"] intValue] : switcher;
longHoldAction = [prefs objectForKey:@"longHoldAction"] ? (Action)[[prefs objectForKey:@"longHoldAction"] intValue] : reachability;
tapAndHoldAction = [prefs objectForKey:@"tapAndHoldAction"] ? (Action)[[prefs objectForKey:@"tapAndHoldAction"] intValue] : siri;
isVibrationEnabled = [prefs objectForKey:@"isVibrationEnabled"] ? [[prefs objectForKey:@"isVibrationEnabled"] boolValue] : YES;
vibrationIntensity = [prefs objectForKey:@"vibrationIntensity"] ? [[prefs objectForKey:@"vibrationIntensity"] floatValue] : 0.75;
vibrationDuration = [prefs objectForKey:@"vibrationDuration"] ? [[prefs objectForKey:@"vibrationDuration"] intValue] : 30;
}
[prefs release];
}
static void hapticVibe() {
NSMutableDictionary *vibDict = [NSMutableDictionary dictionary];
NSMutableArray *vibArr = [NSMutableArray array];
[vibArr addObject:[NSNumber numberWithBool:YES]];
[vibArr addObject:[NSNumber numberWithInt:vibrationDuration]]; // duration
[vibDict setObject:vibArr forKey:@"VibePattern"];
[vibDict setObject:[NSNumber numberWithFloat:vibrationIntensity] forKey:@"Intensity"];
AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, vibDict);
}
// iOS 13+ doesn't currently support disable actions during lockscreen biometric authentication
static BOOL disableActions = NO;
static BOOL isLongPressGestureActive = NO;
static int notify_token = 0;
static BOOL disableActionsForScreenOff = NO;
%hook SBDashBoardViewController
-(void)biometricEventMonitor:(id)arg1 handleBiometricEvent:(NSUInteger)arg2 { // iOS 10 - 10.1
%orig(arg1, arg2);
// Touch Up or Down
disableActions = arg2 != 0 && arg2 != 1;
}
-(void)handleBiometricEvent:(NSUInteger)arg1 { // iOS 10.2 - 12
%orig(arg1);
// Touch Up or Down
disableActions = arg1 != 0 && arg1 != 1;
}
%end
%group iOS13plus
%hook _SBTransientOverlayPresentedEntity
-(void)setDisableAutoUnlockAssertion:(id)arg1 {
%orig(arg1);
// during biometric authentication this is what is called to disable auto unlocking so we can disable actions
disableActions = arg1 != nil;
}
%end
%end
static inline void lockOrUnlockOrientation(UIInterfaceOrientation orientation) {
SBOrientationLockManager *orientationLockManager = [%c(SBOrientationLockManager) sharedInstance];
if ([orientationLockManager isUserLocked]) {
[orientationLockManager unlock];
} else {
[orientationLockManager lock:orientation];
}
}
static inline void ResetGestureRecognizers(SBHomeHardwareButtonGestureRecognizerConfiguration *configuration) {
UIHBClickGestureRecognizer *_singleTapGestureRecognizer = configuration.singleTapGestureRecognizer;
UILongPressGestureRecognizer *_longTapGestureRecognizer = configuration.longTapGestureRecognizer;
SBHBDoubleTapUpGestureRecognizer *_doubleTapUpGestureRecognizer = [configuration doubleTapUpGestureRecognizer];
UILongPressGestureRecognizer *_tapAndHoldTapGestureRecognizer = configuration.tapAndHoldTapGestureRecognizer;
_singleTapGestureRecognizer.enabled = NO;
_singleTapGestureRecognizer.enabled = YES;
_longTapGestureRecognizer.enabled = NO;
_longTapGestureRecognizer.enabled = YES;
_doubleTapUpGestureRecognizer.enabled = NO;
_doubleTapUpGestureRecognizer.enabled = YES;
_tapAndHoldTapGestureRecognizer.enabled = NO;
_tapAndHoldTapGestureRecognizer.enabled = YES;
}
static NSString *lastApplicationIdentifier = nil;
static NSString *currentApplicationIdentifier = nil;
// The last app feature was copied from LastApp (https://github.com/ashikase/LastApp/ and Tateu's fork)
%hook SpringBoard
%property (nonatomic, retain) NSString *lastApplicationIdentifier;
%property (nonatomic, retain) NSString *currentApplicationIdentifier;
-(void)frontDisplayDidChange:(id)arg1 {
%orig;
if (arg1 != nil && [arg1 isKindOfClass:%c(SBApplication)]) {
NSString *newBundleIdentifier = [(SBApplication *)arg1 bundleIdentifier];
if (![currentApplicationIdentifier isEqualToString:newBundleIdentifier]) {
lastApplicationIdentifier = currentApplicationIdentifier;
currentApplicationIdentifier = newBundleIdentifier;
}
}
}
%end
%hook SBHomeHardwareButtonGestureRecognizerConfiguration
%property(retain,nonatomic) UIHBClickGestureRecognizer *singleTapGestureRecognizer;
%property(retain,nonatomic) UILongPressGestureRecognizer *longTapGestureRecognizer;
%property(retain,nonatomic) UILongPressGestureRecognizer *tapAndHoldTapGestureRecognizer;
%property(retain,nonatomic) UILongPressGestureRecognizer *vibrationGestureRecognizer;
-(void)dealloc {
[self.singleTapGestureRecognizer release];
self.singleTapGestureRecognizer = nil;
[self.longTapGestureRecognizer release];
self.longTapGestureRecognizer = nil;
[self.tapAndHoldTapGestureRecognizer release];
self.tapAndHoldTapGestureRecognizer = nil;
[self.vibrationGestureRecognizer release];
self.vibrationGestureRecognizer = nil;
%orig;
}
%end
%hook SBHomeHardwareButton
%new
-(void)performAction:(Action)action {
if (disableActions)
return; // do nothing since we are in middle of authentication
if (action == home || ![[%c(SBBacklightController) sharedInstance] screenIsOn]) {
SpringBoard *_springboard = (SpringBoard *)[UIApplication sharedApplication];
if ([_springboard respondsToSelector:@selector(_simulateHomeButtonPress)])
[(SpringBoard *)[UIApplication sharedApplication] _simulateHomeButtonPress];
else if ([_springboard respondsToSelector:@selector(_simulateHomeButtonPressWithCompletion:)])
[(SpringBoard *)[UIApplication sharedApplication] _simulateHomeButtonPressWithCompletion:nil];
} else if (action == lock) {
[(SpringBoard *)[UIApplication sharedApplication] _simulateLockButtonPress];
} else if (action == switcher) {
id topDisplay = [(SpringBoard *)[UIApplication sharedApplication] _accessibilityTopDisplay];
if (![topDisplay isKindOfClass:%c(SBPowerDownController)] && ![topDisplay isKindOfClass:%c(SBPowerDownViewController)] && ![topDisplay isKindOfClass:%c(SBDashBoardViewController)] && ![topDisplay isKindOfClass:%c(CSCoverSheetViewController)] && (%c(SBCoverSheetPresentationManager) == nil || [[%c(SBCoverSheetPresentationManager) sharedInstance] hasBeenDismissedSinceKeybagLock])) {
SBMainSwitcherViewController *mainSwitcherViewController = [%c(SBMainSwitcherViewController) sharedInstance];
if ([mainSwitcherViewController respondsToSelector:@selector(toggleSwitcherNoninteractively)])
[mainSwitcherViewController toggleSwitcherNoninteractively];
else if ([mainSwitcherViewController respondsToSelector:@selector(toggleSwitcherNoninteractivelyWithSource:)])
[mainSwitcherViewController toggleSwitcherNoninteractivelyWithSource:1];
else if ([mainSwitcherViewController respondsToSelector:@selector(toggleMainSwitcherNoninteractivelyWithSource:animated:)])
[mainSwitcherViewController toggleMainSwitcherNoninteractivelyWithSource:1 animated:YES];
}
} else if (action == reachability) {
[[%c(SBReachabilityManager) sharedInstance] toggleReachability];
} else if (action == siri) {
SBAssistantController *_assistantController = [%c(SBAssistantController) sharedInstance];
if ([%c(SBAssistantController) respondsToSelector:@selector(isAssistantVisible)]) {
if ([%c(SBAssistantController) isAssistantVisible]) {
[_assistantController dismissPluginForEvent:1];
} else {
[_assistantController handleSiriButtonDownEventFromSource:1 activationEvent:1];
[_assistantController handleSiriButtonUpEventFromSource:1];
}
} else if ([%c(SBAssistantController) respondsToSelector:@selector(isVisible)]) {
if ([%c(SBAssistantController) isVisible]) {
[_assistantController dismissAssistantViewIfNecessary];
} else {
SiriPresentationSpringBoardMainScreenViewController *presentation = MSHookIvar<SiriPresentationSpringBoardMainScreenViewController *>(_assistantController, "_mainScreenSiriPresentation");
SiriPresentationOptions *presentationOptions = [[%c(SiriPresentationOptions) alloc] init];
presentationOptions.wakeScreen = YES;
presentationOptions.hideOtherWindowsDuringAppearance = NO;
SASRequestOptions *requestOptions = [[%c(SASRequestOptions) alloc] initWithRequestSource:1 uiPresentationIdentifier:@"com.apple.siri.Siriland"];
requestOptions.useAutomaticEndpointing = YES;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
AFApplicationInfo *applicationInfo = [[%c(AFApplicationInfo) alloc] initWithCoder:nil];
#pragma clang diagnostic pop
applicationInfo.pid = [NSProcessInfo processInfo].processIdentifier;
applicationInfo.identifier = [NSBundle mainBundle].bundleIdentifier;
requestOptions.contextAppInfosForSiriViewController = @[applicationInfo];
[presentation presentationRequestedWithPresentationOptions:presentationOptions requestOptions:requestOptions];
[presentationOptions release];
[requestOptions release];
[applicationInfo release];
}
}
} else if (action == screenshot) {
SpringBoard *_springboard = (SpringBoard *)[UIApplication sharedApplication];
if ([_springboard respondsToSelector:@selector(takeScreenshot)])
[_springboard takeScreenshot];
else
[[_springboard screenshotManager] saveScreenshotsWithCompletion:nil];
} else if (action == cc) {
id topDisplay = [(SpringBoard *)[UIApplication sharedApplication] _accessibilityTopDisplay];
if (![topDisplay isKindOfClass:%c(SBPowerDownController)] && ![topDisplay isKindOfClass:%c(SBPowerDownViewController)]) {
SBControlCenterController *_ccController = [%c(SBControlCenterController) sharedInstance];
if ([_ccController isVisible])
[_ccController dismissAnimated:YES];
else
[_ccController presentAnimated:YES];
}
} else if (action == nc) {
id topDisplay = [(SpringBoard *)[UIApplication sharedApplication] _accessibilityTopDisplay];
if (![topDisplay isKindOfClass:%c(SBPowerDownController)] && ![topDisplay isKindOfClass:%c(SBPowerDownViewController)] && ![topDisplay isKindOfClass:%c(SBDashBoardViewController)] && ![topDisplay isKindOfClass:%c(CSCoverSheetViewController)]) {
if (%c(SBCoverSheetPresentationManager) && [%c(SBCoverSheetPresentationManager) respondsToSelector:@selector(sharedInstance)]) {
SBCoverSheetPresentationManager *_csController = [%c(SBCoverSheetPresentationManager) sharedInstance];
if (_csController != nil && [[%c(SBCoverSheetPresentationManager) sharedInstance] hasBeenDismissedSinceKeybagLock]) {
SBCoverSheetSlidingViewController *currentSlidingViewController = nil;
if ([_csController isInSecureApp] && _csController.secureAppSlidingViewController != nil)
currentSlidingViewController = _csController.secureAppSlidingViewController;
else if (_csController.coverSheetSlidingViewController != nil)
currentSlidingViewController = _csController.coverSheetSlidingViewController;
if (currentSlidingViewController != nil) {
if ([_csController isVisible]) {
[currentSlidingViewController _dismissCoverSheetAnimated:YES withCompletion:nil];
} else {
if ([currentSlidingViewController respondsToSelector:@selector(_presentCoverSheetAnimated:withCompletion:)])
[currentSlidingViewController _presentCoverSheetAnimated:YES withCompletion:nil];
else if ([currentSlidingViewController respondsToSelector:@selector(_presentCoverSheetAnimated:forUserGesture:withCompletion:)])
[currentSlidingViewController _presentCoverSheetAnimated:YES forUserGesture:NO withCompletion:nil];
}
}
}
} else if (%c(SBNotificationCenterController) && [%c(SBNotificationCenterController) respondsToSelector:@selector(sharedInstance)]) {
SBNotificationCenterController *_ncController = [%c(SBNotificationCenterController) sharedInstance];
if (_ncController != nil) {
if ([_ncController isVisible])
[_ncController dismissAnimated:YES];
else
[_ncController presentAnimated:YES];
}
}
}
} else if (action == lastApp) {
id topDisplay = [(SpringBoard *)[UIApplication sharedApplication] _accessibilityTopDisplay];
if (![topDisplay isKindOfClass:%c(SBPowerDownController)] && ![topDisplay isKindOfClass:%c(SBPowerDownViewController)] && ![topDisplay isKindOfClass:%c(SBDashBoardViewController)] && ![topDisplay isKindOfClass:%c(CSCoverSheetViewController)] && (%c(SBCoverSheetPresentationManager) == nil || [[%c(SBCoverSheetPresentationManager) sharedInstance] hasBeenDismissedSinceKeybagLock])) {
// BOOL isApplication = [topDisplay isKindOfClass:%c(SBApplication)];
BOOL isApplication = [(SpringBoard *)[UIApplication sharedApplication] _accessibilityFrontMostApplication] != nil;
SBApplication *toApplication = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:isApplication ? lastApplicationIdentifier : currentApplicationIdentifier];
BOOL isApplicationRunning = [toApplication respondsToSelector:@selector(isRunning)] ? [toApplication isRunning] : toApplication.processState.running;
if (toApplication != nil && isApplicationRunning) {
SBMainWorkspace *workspace = [%c(SBMainWorkspace) sharedInstance];
SBWorkspaceTransitionRequest *request = nil;
if (%c(SBWorkspaceApplication)) {
request = [workspace createRequestForApplicationActivation:[%c(SBWorkspaceApplication) entityForApplication:toApplication] options:0];
} else {
SBDeviceApplicationSceneEntity *deviceApplicationSceneEntity = [[%c(SBDeviceApplicationSceneEntity) alloc] initWithApplicationForMainDisplay:toApplication];
request = [workspace createRequestForApplicationActivation:deviceApplicationSceneEntity options:0];
[deviceApplicationSceneEntity release];
}
[workspace executeTransitionRequest:request];
}
}
} else if (action == rotationLock) {
lockOrUnlockOrientation([(SpringBoard *)[UIApplication sharedApplication] _frontMostAppOrientation]);
} else if (action == rotatePortraitAndLock) {
lockOrUnlockOrientation(UIInterfaceOrientationPortrait);
}
}
-(void)doubleTapUp:(id)arg1 {
if (isEnabled) {
[self performAction:doubleTapAction];
} else {
%orig(arg1);
}
}
%new
-(void)singleTapUp:(id)arg1 {
if (isEnabled) {
[self performAction:singleTapAction];
}
}
%new
-(void)longTap:(UILongPressGestureRecognizer *)arg1 {
if (isEnabled && arg1.state == UIGestureRecognizerStateBegan && !isLongPressGestureActive) {
[self performAction:longHoldAction];
// reset the gesture so home button presses can be detected
ResetGestureRecognizers([self gestureRecognizerConfiguration]);
}
isLongPressGestureActive = YES;
}
%new
-(void)tapAndHold:(UILongPressGestureRecognizer *)arg1 {
if (isEnabled && arg1.state == UIGestureRecognizerStateBegan) {
[self performAction:tapAndHoldAction];
// reset the gesture so home button presses can be detected
ResetGestureRecognizers([self gestureRecognizerConfiguration]);
}
isLongPressGestureActive = YES;
}
%new
-(void)vibrationTap:(UILongPressGestureRecognizer *)arg1 {
// taking advantage of the fact that vibration will be recognzied as soon as finger is on sensor
isLongPressGestureActive = NO;
if (isEnabled && isVibrationEnabled && arg1.state == UIGestureRecognizerStateBegan) {
hapticVibe();
}
}
%new
-(void)createSingleTapGestureRecognizerWithConfiguration:(SBHomeHardwareButtonGestureRecognizerConfiguration *)arg1 {
SBHBDoubleTapUpGestureRecognizer *_doubleTapUpGestureRecognizer = [arg1 doubleTapUpGestureRecognizer];
SBSystemGestureManager *_systemGestureManager = [arg1 systemGestureManager];
SBHBDoubleTapUpGestureRecognizer *_singleTapGestureRecognizer = [[%c(SBHBDoubleTapUpGestureRecognizer) alloc] initWithTarget:self action:@selector(singleTapUp:)];
[_singleTapGestureRecognizer setDelegate:self];
[_singleTapGestureRecognizer requireGestureRecognizerToFail:arg1.longTapGestureRecognizer];
[_singleTapGestureRecognizer requireGestureRecognizerToFail:arg1.tapAndHoldTapGestureRecognizer];
[_singleTapGestureRecognizer requireGestureRecognizerToFail:_doubleTapUpGestureRecognizer];
[_singleTapGestureRecognizer requireGestureRecognizerToFail:arg1.initialButtonDownGestureRecognizer];
[_singleTapGestureRecognizer setAllowedPressTypes:[_doubleTapUpGestureRecognizer allowedPressTypes]];
[_singleTapGestureRecognizer setClickCount:1];
if (%c(FBSystemGestureManager)) {
FBSystemGestureManager *_fbSystemGestureManager = [%c(FBSystemGestureManager) sharedInstance];
if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplayWithIdentity:)])
[_fbSystemGestureManager addGestureRecognizer:_singleTapGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
else if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplay:)])
[_fbSystemGestureManager addGestureRecognizer:_singleTapGestureRecognizer toDisplay:[_systemGestureManager display]];
} else {
[[%c(_UISystemGestureManager) sharedInstance] addGestureRecognizer:_singleTapGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
}
if (arg1.singleTapGestureRecognizer != nil)
[arg1.singleTapGestureRecognizer release];
arg1.singleTapGestureRecognizer = _singleTapGestureRecognizer;
}
%new
-(void)createLongTapGestureRecognizerWithConfiguration:(SBHomeHardwareButtonGestureRecognizerConfiguration *)arg1 {
SBHBDoubleTapUpGestureRecognizer *_doubleTapUpGestureRecognizer = [arg1 doubleTapUpGestureRecognizer];
SBSystemGestureManager *_systemGestureManager = [arg1 systemGestureManager];
UILongPressGestureRecognizer *_longTapGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
[_longTapGestureRecognizer setDelegate:self];
[_longTapGestureRecognizer requireGestureRecognizerToFail:arg1.initialButtonDownGestureRecognizer];
[_longTapGestureRecognizer setNumberOfTapsRequired:0];
[_longTapGestureRecognizer setMinimumPressDuration:0.4];
[_longTapGestureRecognizer setAllowedPressTypes:[_doubleTapUpGestureRecognizer allowedPressTypes]];
if (%c(FBSystemGestureManager)) {
FBSystemGestureManager *_fbSystemGestureManager = [%c(FBSystemGestureManager) sharedInstance];
if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplayWithIdentity:)])
[_fbSystemGestureManager addGestureRecognizer:_longTapGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
else if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplay:)])
[_fbSystemGestureManager addGestureRecognizer:_longTapGestureRecognizer toDisplay:[_systemGestureManager display]];
} else {
[[%c(_UISystemGestureManager) sharedInstance] addGestureRecognizer:_longTapGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
}
if (arg1.longTapGestureRecognizer != nil)
[arg1.longTapGestureRecognizer release];
arg1.longTapGestureRecognizer = _longTapGestureRecognizer;
}
%new
-(void)createTapAndHoldGestureRecognizerWithConfiguration:(SBHomeHardwareButtonGestureRecognizerConfiguration *)arg1 {
SBHBDoubleTapUpGestureRecognizer *_doubleTapUpGestureRecognizer = [arg1 doubleTapUpGestureRecognizer];
SBSystemGestureManager *_systemGestureManager = [arg1 systemGestureManager];
UILongPressGestureRecognizer *_tapAndHoldTapGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tapAndHold:)];
[_tapAndHoldTapGestureRecognizer setDelegate:self];
[_tapAndHoldTapGestureRecognizer requireGestureRecognizerToFail:arg1.initialButtonDownGestureRecognizer];
[_tapAndHoldTapGestureRecognizer setNumberOfTapsRequired:1];
[_tapAndHoldTapGestureRecognizer setMinimumPressDuration:0.4];
[_tapAndHoldTapGestureRecognizer setAllowedPressTypes:[_doubleTapUpGestureRecognizer allowedPressTypes]];
if (%c(FBSystemGestureManager)) {
FBSystemGestureManager *_fbSystemGestureManager = [%c(FBSystemGestureManager) sharedInstance];
if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplayWithIdentity:)])
[_fbSystemGestureManager addGestureRecognizer:_tapAndHoldTapGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
else if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplay:)])
[_fbSystemGestureManager addGestureRecognizer:_tapAndHoldTapGestureRecognizer toDisplay:[_systemGestureManager display]];
} else {
[[%c(_UISystemGestureManager) sharedInstance] addGestureRecognizer:_tapAndHoldTapGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
}
if (arg1.tapAndHoldTapGestureRecognizer != nil)
[arg1.tapAndHoldTapGestureRecognizer release];
arg1.tapAndHoldTapGestureRecognizer = _tapAndHoldTapGestureRecognizer;
}
%new
-(void)createVibrationGestureRecognizerWithConfiguration:(SBHomeHardwareButtonGestureRecognizerConfiguration *)arg1 {
SBHBDoubleTapUpGestureRecognizer *_doubleTapUpGestureRecognizer = [arg1 doubleTapUpGestureRecognizer];
SBSystemGestureManager *_systemGestureManager = [arg1 systemGestureManager];
UILongPressGestureRecognizer *_vibrationGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(vibrationTap:)];
[_vibrationGestureRecognizer setDelegate:self];
[_vibrationGestureRecognizer setNumberOfTapsRequired:0];
[_vibrationGestureRecognizer setMinimumPressDuration:0];
[_vibrationGestureRecognizer setAllowedPressTypes:[_doubleTapUpGestureRecognizer allowedPressTypes]];
if (%c(FBSystemGestureManager)) {
FBSystemGestureManager *_fbSystemGestureManager = [%c(FBSystemGestureManager) sharedInstance];
if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplayWithIdentity:)])
[_fbSystemGestureManager addGestureRecognizer:_vibrationGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
else if ([_fbSystemGestureManager respondsToSelector:@selector(addGestureRecognizer:toDisplay:)])
[_fbSystemGestureManager addGestureRecognizer:_vibrationGestureRecognizer toDisplay:[_systemGestureManager display]];
} else {
[[%c(_UISystemGestureManager) sharedInstance] addGestureRecognizer:_vibrationGestureRecognizer toDisplayWithIdentity:MSHookIvar<id>(_systemGestureManager, "_displayIdentity")];
}
if (arg1.vibrationGestureRecognizer != nil)
[arg1.vibrationGestureRecognizer release];
arg1.vibrationGestureRecognizer = _vibrationGestureRecognizer;
}
-(void)_createGestureRecognizersWithConfiguration:(SBHomeHardwareButtonGestureRecognizerConfiguration *)arg1 {
%orig(arg1);
[self createVibrationGestureRecognizerWithConfiguration:arg1];
[self createTapAndHoldGestureRecognizerWithConfiguration:arg1];
[self createLongTapGestureRecognizerWithConfiguration:arg1];
[self createSingleTapGestureRecognizerWithConfiguration:arg1];
}
-(void)setGestureRecognizerConfiguration:(SBHomeHardwareButtonGestureRecognizerConfiguration *)arg1 {
%orig(arg1);
if (!arg1.vibrationGestureRecognizer) {
[self createVibrationGestureRecognizerWithConfiguration:arg1];
}
if (!arg1.tapAndHoldTapGestureRecognizer) {
[self createTapAndHoldGestureRecognizerWithConfiguration:arg1];
}
if (!arg1.longTapGestureRecognizer) {
[self createLongTapGestureRecognizerWithConfiguration:arg1];
}
if (!arg1.singleTapGestureRecognizer) {
[self createSingleTapGestureRecognizerWithConfiguration:arg1];
}
}
-(BOOL)gestureRecognizerShouldBegin:(id)arg1 {
SBHomeHardwareButtonGestureRecognizerConfiguration *_configuration = [self gestureRecognizerConfiguration];
UIHBClickGestureRecognizer *_singleTapGestureRecognizer = _configuration.singleTapGestureRecognizer;
UILongPressGestureRecognizer *_longTapGestureRecognizer = _configuration.longTapGestureRecognizer;
UILongPressGestureRecognizer *_tapAndHoldTapGestureRecognizer = _configuration.tapAndHoldTapGestureRecognizer;
UILongPressGestureRecognizer *_vibrationGestureRecognizer = _configuration.vibrationGestureRecognizer;
if (disableActionsForScreenOff && (arg1 == _vibrationGestureRecognizer || arg1 == _singleTapGestureRecognizer || arg1 == _longTapGestureRecognizer || arg1 == _tapAndHoldTapGestureRecognizer))
return NO;
return %orig(arg1);
}
-(BOOL)gestureRecognizer:(id)arg1 shouldRecognizeSimultaneouslyWithGestureRecognizer:(id)arg2 {
SBHomeHardwareButtonGestureRecognizerConfiguration *_configuration = [self gestureRecognizerConfiguration];
UIHBClickGestureRecognizer *_singleTapGestureRecognizer = _configuration.singleTapGestureRecognizer;
UILongPressGestureRecognizer *_longTapGestureRecognizer = _configuration.longTapGestureRecognizer;
SBHBDoubleTapUpGestureRecognizer *_doubleTapUpGestureRecognizer = [_configuration doubleTapUpGestureRecognizer];
UILongPressGestureRecognizer *_tapAndHoldTapGestureRecognizer = _configuration.tapAndHoldTapGestureRecognizer;
UILongPressGestureRecognizer *_vibrationGestureRecognizer = _configuration.vibrationGestureRecognizer;
if (arg1 == _vibrationGestureRecognizer || arg2 == _vibrationGestureRecognizer) {
return YES;
} else if ((arg1 == _singleTapGestureRecognizer && arg2 == _longTapGestureRecognizer) || (arg1 == _longTapGestureRecognizer && arg2 == _singleTapGestureRecognizer)) {
return YES;
} else if ((arg1 == _doubleTapUpGestureRecognizer && arg2 == _tapAndHoldTapGestureRecognizer) || (arg1 == _tapAndHoldTapGestureRecognizer && arg2 == _doubleTapUpGestureRecognizer)) {
return YES;
}
return %orig(arg1, arg2);
}
%end
%hook SBReachabilityManager
+(BOOL)reachabilitySupported {
return isEnabled ? YES : %orig();
}
%end
%dtor {
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, kSettingsChangedNotification, NULL);
notify_cancel(notify_token);
}
%ctor {
preferencesChanged();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)preferencesChanged, kSettingsChangedNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
%init();
if (%c(_SBTransientOverlayPresentedEntity)) {
%init(iOS13plus);
}
notify_register_dispatch("com.apple.springboard.hasBlankedScreen", ¬ify_token, dispatch_get_main_queue(), ^(int token) {
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
disableActionsForScreenOff = (state != 0);
});
}