@@ -32,6 +32,21 @@ - (id)init {
32
32
selector: @selector (onScreenUnlocked: )
33
33
name: @" com.apple.screenIsUnlocked"
34
34
object: nil ];
35
+
36
+ // A notification that the workspace posts before the machine goes to sleep.
37
+ [[[NSWorkspace sharedWorkspace ] notificationCenter ]
38
+ addObserver: self
39
+ selector: @selector (isSuspending: )
40
+ name: NSWorkspaceWillSleepNotification
41
+ object: nil ];
42
+
43
+ // A notification that the workspace posts when the machine wakes from
44
+ // sleep.
45
+ [[[NSWorkspace sharedWorkspace ] notificationCenter ]
46
+ addObserver: self
47
+ selector: @selector (isResuming: )
48
+ name: NSWorkspaceDidWakeNotification
49
+ object: nil ];
35
50
}
36
51
return self;
37
52
}
@@ -45,14 +60,26 @@ - (void)addEmitter:(electron::api::PowerMonitor*)monitor_ {
45
60
self->emitters .push_back (monitor_);
46
61
}
47
62
63
+ - (void )isSuspending : (NSNotification *)notify {
64
+ for (auto * emitter : self->emitters ) {
65
+ emitter->Emit (" suspend" );
66
+ }
67
+ }
68
+
69
+ - (void )isResuming : (NSNotification *)notify {
70
+ for (auto * emitter : self->emitters ) {
71
+ emitter->Emit (" resume" );
72
+ }
73
+ }
74
+
48
75
- (void )onScreenLocked : (NSNotification *)notification {
49
- for (auto *& emitter : self->emitters ) {
76
+ for (auto * emitter : self->emitters ) {
50
77
emitter->Emit (" lock-screen" );
51
78
}
52
79
}
53
80
54
81
- (void )onScreenUnlocked : (NSNotification *)notification {
55
- for (auto *& emitter : self->emitters ) {
82
+ for (auto * emitter : self->emitters ) {
56
83
emitter->Emit (" unlock-screen" );
57
84
}
58
85
}
0 commit comments