-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPSGizmoStateObserver.mm
55 lines (46 loc) · 1.95 KB
/
PSGizmoStateObserver.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
// Copyright (c) 2021 udevs
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#import "PSGizmoStateObserver.h"
@implementation PSGizmoStateObserver
+(instancetype)sharedInstance{
static PSGizmoStateObserver *sharedInstance = nil;
static dispatch_once_t token = 0;
dispatch_once(&token, ^{
sharedInstance = [self new];
});
return sharedInstance;
}
-(instancetype)init{
if (self = [super init]){
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wristStateChanged:) name:WRIST_STATE_CHANGED_NN object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockStateChanged:) name:LOCK_STATE_CHANGED_NN object:nil];
}
return self;
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:WRIST_STATE_CHANGED_NN object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:LOCK_STATE_CHANGED_NN object:nil];
}
-(void)postNotification{
CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)GIZMO_STATE_CHANGED_NN, NULL, NULL, kCFNotificationDeliverImmediately);
}
-(void)wristStateChanged:(NSNotification *)notification{
HBLogDebug(@"wristStateChanged");
[self postNotification];
}
-(void)lockStateChanged:(NSNotification *)notification{
HBLogDebug(@"lockStateChanged");
[self postNotification];
}
@end