-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tweak.xm
123 lines (96 loc) · 4.04 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
#import "Tweak.h"
BOOL enabled;
BOOL disableVibration;
NSInteger knobBlurStyle;
HBPreferences *preferences;
//Color dictionary
NSMutableDictionary *colorDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nahtedetihw.blurswitchcolours.plist"];
%group BlurSwitch
%hook UISwitchModernVisualElement
-(void)tintColorDidChange {
%orig;
// Remove the existing knob image
UIImageView *knobView = MSHookIvar<UIImageView *>(self, "_knobView");
knobView.image = nil;
// Set the blur
UIBlurEffect *blurSwitchEffect;
switch (knobBlurStyle) {
case 0:
blurSwitchEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterial];
break;
case 1:
blurSwitchEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialLight];
break;
case 2:
blurSwitchEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialDark];
break;
default:
blurSwitchEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterial];
break;
}
// Add the blur to the view and set the frame of the view
UIVisualEffectView *blurSwitchEffectView = [[UIVisualEffectView alloc] initWithEffect:blurSwitchEffect];
blurSwitchEffectView.frame = CGRectMake(5, 2, 34, 34);
blurSwitchEffectView.layer.cornerRadius = 17;
blurSwitchEffectView.layer.masksToBounds = YES;
// Add the blur view to the original knobview
[knobView insertSubview:blurSwitchEffectView atIndex:0];
[self setNeedsDisplay];
}
// Remove the existing knob image when it is transitioning
-(id)_effectiveThumbImage {
return nil;
}
// Set the background color of the switch in the on position
-(id)_effectiveOnTintColor {
return [SparkColourPickerUtils colourWithString:[colorDictionary objectForKey:@"onColorKey"] withFallback:@"#30D158"];
[self setNeedsDisplay];
}
// Set the background color of the switch in the off position
-(id)_effectiveTintColor {
return [SparkColourPickerUtils colourWithString:[colorDictionary objectForKey:@"offColorKey"] withFallback:@"#8B8A8E"];
[self setNeedsDisplay];
}
// Disable vibrations
-(BOOL)_feedbackEnabled {
if (disableVibration) {
return NO;
}
return %orig;
}
%end
%end
%ctor {
BOOL shouldLoad = NO;
NSArray *args = [[NSClassFromString(@"NSProcessInfo") processInfo] arguments];
NSUInteger count = args.count;
if (count != 0) {
NSString *executablePath = args[0];
if (executablePath) {
NSString *processName = [executablePath lastPathComponent];
BOOL isSpringBoard = [processName isEqualToString:@"SpringBoard"];
BOOL isPreferences = [processName isEqualToString:@"Preferences"];
BOOL isApplication = [executablePath rangeOfString:@"/Application/"].location != NSNotFound || [executablePath rangeOfString:@"/Applications/"].location != NSNotFound;
BOOL isFileProvider = [[processName lowercaseString] rangeOfString:@"fileprovider"].location != NSNotFound;
BOOL skip = [processName isEqualToString:@"AdSheet"]
|| [processName isEqualToString:@"CoreAuthUI"]
|| [processName isEqualToString:@"InCallService"]
|| [processName isEqualToString:@"MessagesNotificationViewService"]
|| [executablePath rangeOfString:@".appex/"].location != NSNotFound;
if (!isFileProvider && (isSpringBoard || isApplication || isPreferences) && !skip) {
shouldLoad = YES;
}
}
}
if (shouldLoad) {
preferences = [[HBPreferences alloc] initWithIdentifier:@"com.nahtedetihw.blurswitchprefs"];
[preferences registerBool:&enabled default:NO forKey:@"enabled"];
[preferences registerInteger:&knobBlurStyle default:0 forKey:@"knobBlurStyle"];
[preferences registerBool:&disableVibration default:NO forKey:@"disableVibration"];
if (enabled) {
%init(BlurSwitch);
return;
}
return;
}
}