-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTweak.x
51 lines (44 loc) · 1.55 KB
/
Tweak.x
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
#import "Tweak.h"
#import "CantReachMe/WDFReachabilityController.h"
static bool wdfTweakEnabled;
static NSString *wdfAction;
BOOL performAction = YES;
WDFReachabilityController *wdfReachabilityController;
%group CantReachMe
%hook SBReachabilityManager
-(void)_activateReachability:(id)arg1 {
NSLog(@"_activateReachability");
if(wdfTweakEnabled) {
if(performAction)
[self wdfPerformReachabilityAction];
performAction = !performAction;
} else {
%orig;
}
}
-(void)toggleReachability {
NSLog(@"toggleReachability");
if(wdfTweakEnabled)
[self wdfPerformReachabilityAction];
else
%orig;
}
%new
-(void)wdfPerformReachabilityAction {
NSLog(@"wdfPerformReachabilityAction");
[wdfReachabilityController runStrategyForAction:wdfAction];
}
%end
%end // group CantReachMe
void wdfReloadPrefs() {
NSDictionary *bundleDefaults = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"0xcc.woodfairy.cantreachme"];
id isEnabled = [bundleDefaults valueForKey:@"Enabled"];
wdfTweakEnabled = isEnabled ? [isEnabled boolValue] : YES;
wdfAction = [bundleDefaults valueForKey:@"crm_action"] ?: @"coversheet";
}
%ctor {
wdfReachabilityController = [[WDFReachabilityController alloc] init];
wdfReloadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, wdfReloadPrefs, CFSTR("0xcc.woodfairy.cantreachme/ReloadPrefs"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(CantReachMe)
}