forked from pNre/Uniformity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
394 lines (245 loc) · 11.9 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
#import <substrate.h>
#import <UIKit/UIKit.h>
#import "Private.h"
enum {
CCGrabberStyleDefault = 0,
CCGrabberStyleNC,
CCGrabberStyleTint,
CCGrabberStyleHidden
};
static BOOL SettingsLoaded = NO;
static BOOL STTweakEnabled = YES;
static BOOL STCCUseNotificationCenterStyle = NO;
static NSUInteger STCCGrabberStyle = CCGrabberStyleNC;
static CGFloat STCCContentNormalAlpha = 0.4;
static CGFloat STCCContentHighlightedAlpha = 0.8;
static CGFloat STCCContentDisabledAlpha = 0.1;
static CGFloat STCCTintAlpha = 0.1;
static UIColor * STCCForegroundColor = nil;
static UIColor * STCCHighlightColor = nil;
static UIColor * STCCTintColor = nil;
static UIColor * STCCGrabberTintColor = nil;
static BOOL STCCThumbColor = YES;
#define kBackdropNCStyle 0x2B2A
#define kBackdropCCStyle 0x080C
extern "C" void _SBControlCenterControlSettingsDidChangeForKey(NSString * key);
extern "C" UIColor * _SBUIControlCenterControlColorForState(int state);
extern "C" NSInteger _SBUIControlCenterControlBlendModeForState(int state);
extern "C" CGFloat _SBUIControlCenterControlAlphaForState(int state);
extern "C" SBControlCenterSettings * _SBControlCenterSettings(void);
static UIColor * (*original__SBUIControlCenterControlColorForState)(int state);
static CGFloat (*original__SBUIControlCenterControlAlphaForState)(int state);
%hook SBControlCenterSettings
- (BOOL)backgroundDarkensCC {
if (!STTweakEnabled)
return %orig;
return NO;
}
%end
%hook SBUIControlCenterSlider
+ (id)_knobImage {
id image = %orig;
if (!STTweakEnabled || (!STCCForegroundColor && STCCThumbColor) || (!STCCHighlightColor && !STCCThumbColor))
return image;
return [image _flatImageWithColor:(STCCThumbColor ? STCCForegroundColor : STCCHighlightColor)];
}
%end
void SBControlCenterContentContainerViewReplaceBackdrop(SBControlCenterContentContainerView * view) {
_UIBackdropView * &_originalBackdrop = MSHookIvar<_UIBackdropView *>(view, "_backdropView");
if (!_originalBackdrop)
return;
BOOL reloadBackdrop = NO;
BOOL _useNCStyle = STCCUseNotificationCenterStyle;
[[_originalBackdrop inputSettings] setColorTint:STCCTintColor];
[[_originalBackdrop inputSettings] setColorTintAlpha:STCCTintAlpha];
if ([_originalBackdrop groupName] && [[_originalBackdrop groupName] isEqualToString:@"PNCustomBackdrop"]) {
if (STTweakEnabled) {
reloadBackdrop = !STCCUseNotificationCenterStyle;
} else {
reloadBackdrop = YES;
_useNCStyle = NO;
}
} else if ([_originalBackdrop groupName] && [[_originalBackdrop groupName] isEqualToString:@"ControlCenter"]) {
reloadBackdrop = STCCUseNotificationCenterStyle && STTweakEnabled;
}
if (reloadBackdrop) {
[_originalBackdrop removeFromSuperview];
[_originalBackdrop release];
if (_useNCStyle) {
_originalBackdrop = [[_UIBackdropView alloc] initWithPrivateStyle:kBackdropNCStyle];
[_originalBackdrop setGroupName:@"PNCustomBackdrop"];
if (STCCTintColor) {
[[_originalBackdrop inputSettings] setColorTint:STCCTintColor];
[[_originalBackdrop inputSettings] setColorTintAlpha:STCCTintAlpha];
}
} else {
_originalBackdrop = [[_UIBackdropView alloc] initWithPrivateStyle:kBackdropCCStyle];
[_originalBackdrop setGroupName:@"ControlCenter"];
}
[_originalBackdrop setAppliesOutputSettingsAnimationDuration:1.0];
[view insertSubview:_originalBackdrop atIndex:0];
}
}
%hook SBControlCenterContentContainerView
- (id)initWithFrame:(CGRect)frame {
self = %orig;
if (self && STTweakEnabled) {
SBControlCenterContentContainerViewReplaceBackdrop(self);
}
return self;
}
%end
%hook SBControlCenterGrabberView
static void SBControlCenterGrabberViewStyle(SBChevronView * chevronView) {
if (!chevronView)
return;
if (STCCGrabberStyle == CCGrabberStyleTint && !STCCGrabberTintColor)
STCCGrabberStyle = CCGrabberStyleDefault;
[chevronView setHidden:NO];
switch (STCCGrabberStyle) {
case CCGrabberStyleNC:
[chevronView setColor:[UIColor colorWithWhite:0.52 alpha:1.]];
[chevronView _setDrawsAsBackdropOverlayWithBlendMode:kCGBlendModeOverlay];
break;
case CCGrabberStyleTint:
[chevronView setColor:STCCGrabberTintColor];
[chevronView _setDrawsAsBackdropOverlayWithBlendMode:kCGBlendModeNormal];
break;
case CCGrabberStyleHidden:
[chevronView setHidden:YES];
break;
default:
[chevronView setColor:_SBUIControlCenterControlColorForState(UIControlStateNormal)];
[chevronView _setDrawsAsBackdropOverlayWithBlendMode:kCGBlendModeNormal];
}
}
- (SBControlCenterGrabberView *)initWithFrame:(CGRect)frame {
self = %orig;
if (self && STTweakEnabled && [self chevronView]) {
SBControlCenterGrabberViewStyle([self chevronView]);
}
return self;
}
%end
CGFloat PN_SBUIControlCenterControlAlphaForState(int state) {
if (!STTweakEnabled || !SettingsLoaded)
return original__SBUIControlCenterControlAlphaForState(state);
if (state == UIControlStateHighlighted)
return STCCContentHighlightedAlpha;
else if (state == UIControlStateDisabled)
return STCCContentDisabledAlpha;
else
return STCCContentNormalAlpha;
}
UIColor * PN_SBUIControlCenterControlColorForState(int state) {
if (!STTweakEnabled || !SettingsLoaded)
return original__SBUIControlCenterControlColorForState(state);
if (state == UIControlStateHighlighted) {
return STCCHighlightColor ?: original__SBUIControlCenterControlColorForState(state);
} else
return STCCForegroundColor ?: original__SBUIControlCenterControlColorForState(state);
}
NSInteger PN_SBUIControlCenterControlBlendModeForState(int state) {
if (STTweakEnabled && SettingsLoaded)
return kCGBlendModeNormal;
if (state == UIControlStateNormal || state == UIControlStateDisabled) {
CGFloat scale = [[UIScreen mainScreen] scale];
if (scale >= 2.) {
return kCGBlendModeMultiply;
}
} else if (state == UIControlStateHighlighted) {
SBControlCenterSettings * settings = _SBControlCenterSettings();
if ([settings highlightUsesPlusL])
return kCGBlendModeScreen;
}
return kCGBlendModeNormal;
}
static void applyChanges() {
// Control center
SBControlCenterController * ccController = [%c(SBControlCenterController) sharedInstanceIfExists];
if (ccController) {
SBControlCenterViewController * _viewController = MSHookIvar<SBControlCenterViewController *>(ccController, "_viewController");
if (_viewController) {
SBControlCenterContainerView * _containerView = MSHookIvar<SBControlCenterContainerView *>(_viewController, "_containerView");
SBControlCenterContentContainerView * contentContainerView = [_containerView contentContainerView];
SBControlCenterContentContainerViewReplaceBackdrop(contentContainerView);
SBControlCenterContentView * _contentView = MSHookIvar<SBControlCenterContentView *>(_viewController, "_contentView");
if (_contentView && [_contentView grabberView])
SBControlCenterGrabberViewStyle([[_contentView grabberView] chevronView]);
}
}
_SBControlCenterControlSettingsDidChangeForKey(@"highlight");
_SBControlCenterControlSettingsDidChangeForKey(@"highlightColor");
_SBControlCenterControlSettingsDidChangeForKey(@"controlAlpha");
}
static void reloadSettings() {
NSDictionary * _settingsPlist = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.pNre.uniformity.plist"];
if ([_settingsPlist objectForKey:@"TweakEnabled"])
STTweakEnabled = [[_settingsPlist objectForKey:@"TweakEnabled"] boolValue];
if ([_settingsPlist objectForKey:@"CCUseNotificationCenterStyle"])
STCCUseNotificationCenterStyle = [[_settingsPlist objectForKey:@"CCUseNotificationCenterStyle"] boolValue];
if ([_settingsPlist objectForKey:@"CCGrabberStyle"])
STCCGrabberStyle = [[_settingsPlist objectForKey:@"CCGrabberStyle"] integerValue];
if ([_settingsPlist objectForKey:@"CCContentNormalAlpha"])
STCCContentNormalAlpha = [[_settingsPlist objectForKey:@"CCContentNormalAlpha"] floatValue];
if ([_settingsPlist objectForKey:@"CCContentHighlightedAlpha"])
STCCContentHighlightedAlpha = [[_settingsPlist objectForKey:@"CCContentHighlightedAlpha"] floatValue];
if ([_settingsPlist objectForKey:@"CCContentDisabledAlpha"])
STCCContentDisabledAlpha = [[_settingsPlist objectForKey:@"CCContentDisabledAlpha"] floatValue];
if ([_settingsPlist objectForKey:@"CCTintAlpha"])
STCCTintAlpha = [[_settingsPlist objectForKey:@"CCTintAlpha"] floatValue];
if ([_settingsPlist objectForKey:@"CCThumbColor"])
STCCThumbColor = [[_settingsPlist objectForKey:@"CCThumbColor"] boolValue];
if ([_settingsPlist objectForKey:@"CCForegroundColor"]) {
if (STCCForegroundColor)
[STCCForegroundColor release];
STCCForegroundColor = [NSKeyedUnarchiver unarchiveObjectWithData:[_settingsPlist objectForKey:@"CCForegroundColor"]];
if ([STCCForegroundColor isKindOfClass:[NSNull class]])
STCCForegroundColor = STTweakEnabled && STCCUseNotificationCenterStyle ? [[UIColor colorWithWhite:0.90 alpha:1.] retain] : nil;
else
[STCCForegroundColor retain];
}
if ([_settingsPlist objectForKey:@"CCHighlightColor"]) {
if (STCCHighlightColor)
[STCCHighlightColor release];
STCCHighlightColor = [NSKeyedUnarchiver unarchiveObjectWithData:[_settingsPlist objectForKey:@"CCHighlightColor"]];
if ([STCCHighlightColor isKindOfClass:[NSNull class]])
STCCHighlightColor = nil;
else
[STCCHighlightColor retain];
}
if ([_settingsPlist objectForKey:@"CCTintColor"]) {
if (STCCTintColor)
[STCCTintColor release];
STCCTintColor = [NSKeyedUnarchiver unarchiveObjectWithData:[_settingsPlist objectForKey:@"CCTintColor"]];
if ([STCCTintColor isKindOfClass:[NSNull class]])
STCCTintColor = nil;
else
[STCCTintColor retain];
}
if ([_settingsPlist objectForKey:@"CCGrabberTintColor"]) {
if (STCCGrabberTintColor)
[STCCGrabberTintColor release];
STCCGrabberTintColor = [NSKeyedUnarchiver unarchiveObjectWithData:[_settingsPlist objectForKey:@"CCGrabberTintColor"]];
if ([STCCGrabberTintColor isKindOfClass:[NSNull class]])
STCCGrabberTintColor = nil;
else
[STCCGrabberTintColor retain];
}
SettingsLoaded = YES;
applyChanges();
}
static void reloadSettingsNotification(CFNotificationCenterRef notificationCenterRef, void * arg1, CFStringRef arg2, const void * arg3, CFDictionaryRef dictionary)
{
reloadSettings();
}
%ctor {
MSHookFunction((void *)_SBUIControlCenterControlBlendModeForState, (void *)PN_SBUIControlCenterControlBlendModeForState, (void **)NULL);
MSHookFunction(_SBUIControlCenterControlColorForState, PN_SBUIControlCenterControlColorForState, &original__SBUIControlCenterControlColorForState);
MSHookFunction(_SBUIControlCenterControlAlphaForState, PN_SBUIControlCenterControlAlphaForState, &original__SBUIControlCenterControlAlphaForState);
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)reloadSettingsNotification, CFSTR("com.pNre.uniformity/settingsupdated"), NULL, CFNotificationSuspensionBehaviorCoalesce);
reloadSettings();
%init;
[pool release];
}