-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTweak.xm
61 lines (51 loc) · 2.33 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
#import "shared.h"
#import "ABSManager.h"
#import <Cephei/HBPreferences.h>
HBPreferences* preferences;
BKSLocalDefaults* backboardDefaults = [%c(BKSLocalDefaults) new];
static void didFinishLaunching(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef info) {
preferences = [[HBPreferences alloc] initWithIdentifier:@"com.jschiefner.advancedbrightnesssliderpreferences"];
[preferences registerDefaults:@{@"enabled":@YES, @"threshold":@30.0f}];
if (![preferences boolForKey:@"enabled"]) return;
int iosVersion = [[[%c(UIDevice) currentDevice] systemVersion] intValue];
float threshold = [preferences floatForKey:@"threshold"] / 100.0f;
BOOL modifyAutoBrightness;
if ([preferences objectForKey:@"modifyAutoBrightness"] == nil) {
modifyAutoBrightness = [backboardDefaults isALSEnabled];
[preferences setBool:modifyAutoBrightness forKey:@"modifyAutoBrightness"];
} else {
modifyAutoBrightness = [preferences boolForKey:@"modifyAutoBrightness"];
}
[[ABSManager shared] initWithAutoBrightnessEnabled:modifyAutoBrightness andIosVersion:iosVersion andThreshold:threshold];
[preferences registerPreferenceChangeBlockForKey:@"threshold" block:^(NSString *key, id<NSCopying> _Nullable value){
[[ABSManager shared] setThreshold:[[value copyWithZone:nil] floatValue] / 100.0f];
}];
initNative();
if (%c(PrysmSliderViewController)) initPrysm();
if (%c(SCDisplaySliderModuleViewController)) initBigSurCenter();
}
static void autoBrightnessChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
BOOL enabled = [backboardDefaults isALSEnabled];
[ABSManager shared].modifyAutoBrightness = enabled;
[preferences setBool:enabled forKey:@"modifyAutoBrightness"];
}
%ctor {
// call initializer when Springboard is loaded
CFNotificationCenterAddObserver(
CFNotificationCenterGetLocalCenter(),
NULL,
&didFinishLaunching,
(CFStringRef) UIApplicationDidFinishLaunchingNotification,
NULL,
CFNotificationSuspensionBehaviorDrop
);
// call AutoBrightness handler method when User modifies auto-brightness switch
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
autoBrightnessChanged,
CFSTR("AXSAutoBrightnessChangedNotification"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately
);
}