forked from Nosskirneh/CustomLockscreenDuration
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTweak.xm
More file actions
executable file
·76 lines (59 loc) · 2.54 KB
/
Tweak.xm
File metadata and controls
executable file
·76 lines (59 loc) · 2.54 KB
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
#import <SpringBoard/SBUIController.h>
#define prefPath [NSString stringWithFormat:@"%@/Library/Preferences/%@", NSHomeDirectory(),@"se.nosskirneh.customlockduration.plist"]
BOOL enabled;
long long duration;
BOOL chargeMode;
long long chargingDuration;
static void reloadPrefs() {
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
[defaults addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:prefPath]];
enabled = [[defaults objectForKey:@"enabled"] boolValue];
duration = [[defaults objectForKey:@"duration"] integerValue];
chargeMode = [[defaults objectForKey:@"chargeMode"] boolValue];
chargingDuration = [[defaults objectForKey:@"chargingDuration"] integerValue];
}
void updateSettings(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo) {
reloadPrefs();
}
%hook BehaviorClass
- (void)setIdleTimerDuration:(long long)arg {
if (enabled) {
BOOL charging = [[%c(SBUIController) sharedInstance] isBatteryCharging];
%orig((chargeMode && charging) ? chargingDuration : duration);
return;
}
%orig(arg);
}
%end
%group iOS10
%hook SBDashBoardIdleTimerEventPublisher
- (BOOL)isEnabled {
BOOL charging = [[%c(SBUIController) sharedInstance] isBatteryCharging];
BOOL infite = ((chargeMode && charging && chargingDuration == 0) || (!chargeMode && duration == 0));
return (enabled && infite) ? NO : %orig;
}
%end
%end
%group iOS11
%hook SBDashBoardIdleTimerProvider
- (BOOL)isIdleTimerEnabled {
BOOL charging = [[%c(SBUIController) sharedInstance] isBatteryCharging];
BOOL infite = ((chargeMode && charging && chargingDuration == 0) || (!chargeMode && duration == 0));
return (enabled && infite) ? NO : %orig;
}
%end
%end
%ctor {
reloadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &updateSettings, CFSTR("se.nosskirneh.customlockscreenduration/preferencesChanged"), NULL, 0);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &updateSettings, CFSTR("se.nosskirneh.customlockscreenduration.FSchanged"), NULL, 0);
%init(BehaviorClass = objc_getClass([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){13,0,0}] ? "CSBehavior" : "SBDashBoardBehavior"));
if (%c(SBDashBoardIdleTimerEventPublisher))
%init(iOS10);
else if (%c(SBDashBoardIdleTimerProvider))
%init(iOS11)
}