-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggle.m
63 lines (50 loc) · 1.31 KB
/
Toggle.m
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
#include <objc/runtime.h>
@interface BBSettingsGateway : NSObject
- (void)setBehaviorOverrideStatus:(BOOL)enabled;
- (void)setActiveBehaviorOverrideTypesChangeHandler:(void (^)(BOOL))block;
@end
@interface SBStatusBarDataManager : NSObject
+ (id)sharedDataManager;
- (void)setStatusBarItem:(int)arg1 enabled:(BOOL)arg2;
@end
static BBSettingsGateway *bbGateway;
static SBStatusBarDataManager *manager;
static BOOL isDND = NO;
BOOL isCapable() {
return YES;
}
BOOL isEnabled() {
return isDND;
}
void setState(BOOL enabled) {
[bbGateway setBehaviorOverrideStatus:enabled];
/**
* ugly fix for when toggle is inside NotificationCenter
* somehow the icon disappears when NC is closed
* so reset the icon (must disable then enable)
* magical number 1 corresponds to "quiet" icon
*/
if (enabled) {
[manager setStatusBarItem:1 enabled:NO];
[manager setStatusBarItem:1 enabled:YES];
}
}
#ifdef NC_SETTINGS
NSString *localizedName() {
return @"Do Not Disturb";
}
#else
BOOL getStateFast() {
return isDND;
}
float getDelayTime() {
return .0f;
}
#endif
__attribute__((constructor)) static void init() {
bbGateway = [[BBSettingsGateway alloc] init];
[bbGateway setActiveBehaviorOverrideTypesChangeHandler:^(BOOL enabled) {
isDND = enabled;
}];
manager = [objc_getClass("SBStatusBarDataManager") sharedDataManager];
}