-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
71 lines (57 loc) · 1.94 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
#import "Headers.h"
#define kIdentifier CFSTR("com.fortysixandtwo.kissmypass")
static NSDictionary *validIdentifiers = @{
@"com.microsoft.Office.Outlook" : @"DeleteActionIdentifier",
@"com.apple.mobilemail" : @"MFMailBBDeleteActionIdentifier",
@"com.google.Gmail" : @"2", // 2? Really, Google? *2*?!
@"com.CloudMagic.Mail" : @"emailDeleteAction"
};
static void logActionToFile(NSString *bundle, NSString *action)
{
CFStringRef actionIdentifier = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@-latestaction"), kIdentifier);
CFPreferencesSetAppValue(CFSTR("bundle"), bundle, actionIdentifier);
CFPreferencesSetAppValue(CFSTR("action"), action, actionIdentifier);
CFPreferencesAppSynchronize(actionIdentifier);
}
static void loadSettings()
{
NSLog(@"[KMP] Settings loaded.");
CFPreferencesAppSynchronize(kIdentifier);
return;
}
static BOOL debug()
{
id _debug = (id)CFPreferencesCopyAppValue(CFSTR("debug"), kIdentifier);
return _debug ? [_debug boolValue] : NO;
}
%hook SBLockScreenActionContext
- (_Bool)requiresAuthentication
{
BOOL _requiresAuthentication = %orig;
if(_requiresAuthentication)
{
NSString *bulletinSection = [[self bulletin] section];
NSString *actionIdentifier = [self identifier];
if(bulletinSection && actionIdentifier)
{
if(debug())
{
NSLog(@"[KMP/Debug]: %@ : %@", bulletinSection, actionIdentifier);
logActionToFile(bulletinSection, actionIdentifier);
}
if([actionIdentifier isEqualToString:[validIdentifiers valueForKey:bulletinSection]])
{
if(debug())
NSLog(@"[KMP/Action]: Stripping authentication requirement for %@.", bulletinSection);
return NO;
}
}
}
return %orig;
}
%end
%ctor
{
loadSettings();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadSettings, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/settingschanged"), kIdentifier), NULL, CFNotificationSuspensionBehaviorCoalesce);
}