-
Notifications
You must be signed in to change notification settings - Fork 7
/
Tweak.xm
271 lines (238 loc) · 9.81 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
#import "Forcy.h"
static void loadPreferences() {
preferences = [[NSUserDefaults alloc] initWithSuiteName:@"com.strayadevteam.forcyprefs"];
[preferences registerDefaults:@{
@"enabled": @YES,
@"hapticFeedbackIsEnabled": @YES,
@"removeBackgroundBlur": @NO,
@"preferForceTouch": @NO,
@"shortHoldTime": [NSNumber numberWithFloat:0.325],
@"vibrationTime": [NSNumber numberWithFloat:50],
@"invokeMethods": [NSNumber numberWithInteger:0],
@"menuEnabled": @YES,
@"peekAndPopSens": [NSNumber numberWithInteger:45],
@"peekAndPopEnabled": @YES
}];
enabled = [preferences boolForKey:@"enabled"];
hapticFeedbackIsEnabled = [preferences boolForKey:@"hapticFeedbackIsEnabled"];
removeBackgroundBlur = [preferences boolForKey:@"removeBackgroundBlur"];
preferForceTouch = [preferences boolForKey:@"preferForceTouch"];
shortHoldTime = [preferences floatForKey:@"shortHoldTime"];
vibrationTime = [preferences floatForKey:@"vibrationTime"];
invokeMethods = [preferences integerForKey:@"invokeMethods"];
menuEnabled = [preferences boolForKey:@"menuEnabled"];
peekAndPopSens = [preferences integerForKey:@"peekAndPopSens"];
peekAndPopEnabled = [preferences boolForKey:@"peekAndPopEnabled"];
[preferences relees];
}
static void hapticFeedback(){
if(hapticFeedbackIsEnabled){
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array];
[arr addObject:[NSNumber numberWithBool:YES]];
[arr addObject:[NSNumber numberWithInt:vibrationTime]]; //vibrate for 50ms
[dict setObject:arr forKey:@"VibePattern"];
[dict setObject:[NSNumber numberWithInt:1] forKey:@"Intensity"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict);
}
}
/*UIImage *getLatestPhoto() {
PHImageManager *imgManager = [PHImageManager defaultManager];
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.synchronous = TRUE;
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.sortDescriptors = [[NSArray alloc] initWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending: TRUE], nil];
__block UIImage *finalImage = nil;
if ([PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions]) {
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
if (fetchResult.count > 0) {
[imgManager requestImageForAsset:[fetchResult objectAtIndex:(fetchResult.count-1)] targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFill options:requestOptions resultHandler:^(UIImage *result, NSDictionary *info){
finalImage = result;
}];
}
}
return finalImage;
}
*/
SBIconView *currentlyHighlightedIcon;
%group SpringBoardHooks
%hook SBIconView
UISwipeGestureRecognizer *swipeUp;
UITapGestureRecognizer *doubleTap;
- (void)setLocation:(id)arg1 {
//im trying mum - i did it you proud?
//HBLogInfo(@"setLoaction:arg1 = %@", arg1);
[self removeGestureRecognizer:swipeUp];
[self removeGestureRecognizer:doubleTap];
if(enabled && menuEnabled){
if(invokeMethods == 0){
/*UILongPressGestureRecognizer *shortcutMenuPeekGesture = MSHookIvar<UILongPressGestureRecognizer *>(self, "_shortcutMenuPeekGesture");
shortcutMenuPeekGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:[%c(SBIconController) sharedInstance] action:@selector(_handleShortcutMenuPeek:)];
shortcutMenuPeekGesture.minimumPressDuration = shortHoldTime;*/
UILongPressGestureRecognizer *shortcutPeekGesture = MSHookIvar<UILongPressGestureRecognizer *>(self, "_shortcutMenuPeekGesture");
shortcutPeekGesture = [[UILongPressGestureRecognizer alloc] initWithTarget: [%c(SBIconController) sharedInstance] action:@selector(_handleShortcutMenuPeek:)];
shortcutPeekGesture.minimumPressDuration = shortHoldTime;
[self addGestureRecognizer:shortcutPeekGesture];
swipeUp = [[%c(UISwipeGestureRecognizer) alloc] initWithTarget:self action:@selector(fc_swiped:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
swipeUp.delegate = (id <UIGestureRecognizerDelegate>)self;
[self addGestureRecognizer:swipeUp];
[swipeUp release];
} else if(invokeMethods == 1){
//NSLog(@"invokeMethods == 1");
swipeUp = [[%c(UISwipeGestureRecognizer) alloc] initWithTarget:self action:@selector(fc_swiped:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
swipeUp.delegate = (id <UIGestureRecognizerDelegate>)self;
[self addGestureRecognizer:swipeUp];
[swipeUp release];
} else if(invokeMethods == 2){
doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fc_handleDoubleTapGesture:)];
doubleTap.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTap];
[doubleTap release];
}
}
%orig;
}
%new -(void)fc_handleDoubleTapGesture:(UITapGestureRecognizer *)gesture{
if(gesture.state == UIGestureRecognizerStateRecognized){
[[%c(SBIconController) sharedInstance] _revealMenuForIconView:self presentImmediately:true];
[self cancelLongPressTimer];
}
}
%new - (void)fc_swiped:(UISwipeGestureRecognizer *)gesture {
if(invokeMethods == 0){
[[%c(SBIconController) sharedInstance] setIsEditing:YES];
[self _handleSecondHalfLongPressTimer:nil];
} else if (invokeMethods == 1){
[[%c(SBIconController) sharedInstance] _revealMenuForIconView:self presentImmediately:true];
[self cancelLongPressTimer];
}
}
%new - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([gestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]]
&& ![[%c(SBIconController) sharedInstance] _canRevealShortcutMenu])
return NO;
return YES;
}
- (void)_handleFirstHalfLongPressTimer:(id)timer{
if(enabled && menuEnabled && [[%c(SBIconController) sharedInstance] _canRevealShortcutMenu] && timer != nil){
if(invokeMethods == 0){
[[%c(SBIconController) sharedInstance] _revealMenuForIconView:self presentImmediately:true];
[self cancelLongPressTimer];
} else if (invokeMethods == 1){
[[%c(SBIconController) sharedInstance] setIsEditing:YES];
[self _handleSecondHalfLongPressTimer:nil];
}
}
%orig;
}
- (void)setHighlighted:(BOOL)highlighted {
%orig;
currentlyHighlightedIcon = highlighted ? self : nil;
}
%end
%hook SBApplicationShortcutMenu
-(void)_setupViews{
%orig;
if(enabled && menuEnabled && removeBackgroundBlur){
_UIBackdropView *_blurView = MSHookIvar<_UIBackdropView*>(self, "_blurView");
[_blurView setHidden:true];
}
}
%end
%hook SBIconController
- (void)_revealMenuForIconView:(SBIconView *)iconView presentImmediately:(BOOL)imm {
if(hapticFeedbackIsEnabled && !self.isEditing){
hapticFeedback();
}
%orig(iconView, YES);
}
%end
%end
%hook UIScreen
- (int)_forceTouchCapability {
return 2;
}
%end
%hook UITraitCollection
- (int)forceTouchCapability {
return 2;
}
%end
%hook UIDevice
- (BOOL)_supportsForceTouch {
return TRUE;
}
%end
%hook _UITouchForceMessage
- (void)setUnclampedTouchForce:(CGFloat)touchForce {
if(peekAndPopEnabled){
if (HardPress) {
%orig((int) 200);
//hapticFeedback();
} else {
%orig((int) 20);
//hapticFeedback();
}
}
}
%end
%hook UITouch/*
- (void)setMajorRadiusTolerance:(float)arg1 {
if (!FirstPress) {
lightPress = peekAndPopSens;
if (lightPress >= 15) {
FirstPress = YES;
NSLog(@"FIRST PRESS FUCK");
//hapticFeedback();
}
}
if ([self _pathMajorRadius] > lightPress) {
HardPress = YES;
NSLog(@"HARD PRESS FUCK");
//hapticFeedback();
}
else {
HardPress = NO;
NSLog(@"NO HARD PRESS FUCK");
}
%orig;
}*/
- (void)setMajorRadius:(float)arg1 {
if(peekAndPopEnabled){
// NSLog(@"View: %@", self.view.gestureRecognizers);
//if (![self.view isKindOfClass:[NSClassFromString(@"SBIconView") class]]) {
if (!FirstPress) {
lightPress = peekAndPopSens;
if (lightPress >= 15) {
FirstPress = YES;
}
}
if ([self _pathMajorRadius] > lightPress) {
HardPress = 2;
}
if ([self _pathMajorRadius] > lightPress + lightPress /2) {
HardPress = 3;
}
if ([self _pathMajorRadius] < lightPress) {
HardPress = 1;
}
//}
}
%orig;
}
%end
%ctor{
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
(CFNotificationCallback)loadPreferences,
CFSTR("com.strayadevteam.forcyprefs/prefsChanged"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
loadPreferences();
if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.springboard"]) {
%init(SpringBoardHooks);
}
%init;
}