-
Notifications
You must be signed in to change notification settings - Fork 4
/
Tweak.xm
executable file
·84 lines (65 loc) · 2.38 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
#import <SpringBoard/SBUIController.h>
#import "Common.h"
static BOOL enabled;
static long long duration;
static BOOL chargeMode;
static long long chargingDuration;
static void reloadPrefs() {
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
[defaults addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:kPrefPath]];
enabled = [defaults[@"enabled"] boolValue];
duration = [defaults[@"duration"] integerValue];
chargeMode = [defaults[@"chargeMode"] boolValue];
chargingDuration = [defaults[@"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];
return %orig((chargeMode && charging) ? chargingDuration : duration);
}
%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
@interface CSBehavior : NSObject
@end
@interface SBDashBoardBehavior : NSObject
@end
%ctor {
reloadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &updateSettings, CFSTR(kPrefsChangedNotification), NULL, 0);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &updateSettings, CFSTR(kFlipswitchNotification), NULL, 0);
Class behaviorClass = %c(CSBehavior) ? : %c(SBDashBoardBehavior);
%init(BehaviorClass = behaviorClass);
if (%c(SBDashBoardIdleTimerEventPublisher))
%init(iOS10);
else if (%c(SBDashBoardIdleTimerProvider))
%init(iOS11)
}