-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch.x
More file actions
executable file
·49 lines (42 loc) · 1.97 KB
/
Switch.x
File metadata and controls
executable file
·49 lines (42 loc) · 1.97 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
#import "FSSwitchDataSource.h"
#import "FSSwitchPanel.h"
#import <notify.h>
#include <dlfcn.h>
static NSString * const PREF_PATH = @"/var/mobile/Library/Preferences/net.mtvg.BacklightSwitch.plist";
static NSString * const kSwitchKey = @"BacklightIsOn";
@interface BacklightSwitch : NSObject <FSSwitchDataSource>
@end
@implementation BacklightSwitch
- (FSSwitchState)stateForSwitchIdentifier:(NSString *)switchIdentifier
{
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:PREF_PATH];
id existBacklightIsOn = [dict objectForKey:kSwitchKey];
BOOL backlightIsOn = existBacklightIsOn ? [existBacklightIsOn boolValue] : YES;
return backlightIsOn ? FSSwitchStateOn : FSSwitchStateOff;
}
- (void)applyState:(FSSwitchState)newState forSwitchIdentifier:(NSString *)switchIdentifier
{
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:PREF_PATH];
NSMutableDictionary *mutableDict = dict ? [[dict mutableCopy] autorelease] : [NSMutableDictionary dictionary];
int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort");
int port = SBSSpringBoardServerPort();
void (*SBDimScreen)(int _port,BOOL shouldDim) = (void (*)(int _port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen");
void (*BKSDisplayServicesSetScreenBlanked)(BOOL blanked) = (void (*)(BOOL blanked))dlsym(RTLD_DEFAULT, "BKSDisplayServicesSetScreenBlanked");
switch (newState) {
case FSSwitchStateIndeterminate:
return;
case FSSwitchStateOn:
[mutableDict setValue:@YES forKey:kSwitchKey];
BKSDisplayServicesSetScreenBlanked(0);
SBDimScreen(port,NO);
break;
case FSSwitchStateOff:
[mutableDict setValue:@NO forKey:kSwitchKey];
BKSDisplayServicesSetScreenBlanked(1);
SBDimScreen(port,YES);
break;
}
[mutableDict writeToFile:PREF_PATH atomically:YES];
notify_post("net.mtvg.BacklightSwitch.settingschanged");
}
@end