This repository has been archived by the owner on Nov 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tweak.mm
77 lines (64 loc) · 1.8 KB
/
Tweak.mm
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
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CaptainHook.h>
#import <Activator/libactivator.h>
extern "C" void GSSendAppPreferencesChanged(CFStringRef bundleID, CFStringRef key);
static BOOL showing(void)
{
return [[NSUserDefaults standardUserDefaults]boolForKey:@"SBShowBatteryPercentage"];
}
static void toggle(BOOL showing)
{
[[NSUserDefaults standardUserDefaults]setBool:showing forKey:@"SBShowBatteryPercentage"];
GSSendAppPreferencesChanged(CFSTR("com.apple.springboard"), CFSTR("SBShowBatteryPercentage"));
}
@interface BatteryPeek : NSObject <LAListener>
@property BOOL acceptEvent;
@end
static BatteryPeek *sharedInstance;
@implementation BatteryPeek
- (id)init
{
self = [super init];
if (self) {
_acceptEvent = YES;
}
return self;
}
- (void)showBatteryPercentage
{
toggle(YES);
_acceptEvent = NO;
}
- (void)hideBatteryPercentage
{
toggle(NO);
_acceptEvent = YES;
}
- (void)showOrHideBatteryPercentage
{
if (showing()) {
toggle(NO);
} else {
toggle(YES);
}
}
- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event
{
if (([[UIDevice currentDevice]batteryLevel] <= 0.2) || ([[UIDevice currentDevice]batteryState] == UIDeviceBatteryStateCharging)) {
[self showOrHideBatteryPercentage];
} else {
if (_acceptEvent) {
[self showBatteryPercentage];
[self performSelector:@selector(hideBatteryPercentage) withObject:nil afterDelay:1.5];
}
}
[event setHandled:YES];
}
@end
CHConstructor
{
sharedInstance = [[BatteryPeek alloc]init];
[[NSClassFromString(@"LAActivator")sharedInstance]registerListener:sharedInstance forName:@"me.qusic.BatteryPeek"];
[[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"SBShowBatteryPercentage"];
}