feat: support suspend/resume on macOS (#24254)
This commit is contained in:
parent
1429a8961c
commit
4290555a0d
2 changed files with 31 additions and 4 deletions
|
@ -8,11 +8,11 @@ Process: [Main](../glossary.md#main-process)
|
||||||
|
|
||||||
The `powerMonitor` module emits the following events:
|
The `powerMonitor` module emits the following events:
|
||||||
|
|
||||||
### Event: 'suspend' _Linux_ _Windows_
|
### Event: 'suspend'
|
||||||
|
|
||||||
Emitted when the system is suspending.
|
Emitted when the system is suspending.
|
||||||
|
|
||||||
### Event: 'resume' _Linux_ _Windows_
|
### Event: 'resume'
|
||||||
|
|
||||||
Emitted when system is resuming.
|
Emitted when system is resuming.
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,21 @@
|
||||||
selector:@selector(onScreenUnlocked:)
|
selector:@selector(onScreenUnlocked:)
|
||||||
name:@"com.apple.screenIsUnlocked"
|
name:@"com.apple.screenIsUnlocked"
|
||||||
object:nil];
|
object:nil];
|
||||||
|
|
||||||
|
// A notification that the workspace posts before the machine goes to sleep.
|
||||||
|
[[[NSWorkspace sharedWorkspace] notificationCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(isSuspending:)
|
||||||
|
name:NSWorkspaceWillSleepNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
|
// A notification that the workspace posts when the machine wakes from
|
||||||
|
// sleep.
|
||||||
|
[[[NSWorkspace sharedWorkspace] notificationCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(isResuming:)
|
||||||
|
name:NSWorkspaceDidWakeNotification
|
||||||
|
object:nil];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -45,14 +60,26 @@
|
||||||
self->emitters.push_back(monitor_);
|
self->emitters.push_back(monitor_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)isSuspending:(NSNotification*)notify {
|
||||||
|
for (auto* emitter : self->emitters) {
|
||||||
|
emitter->Emit("suspend");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)isResuming:(NSNotification*)notify {
|
||||||
|
for (auto* emitter : self->emitters) {
|
||||||
|
emitter->Emit("resume");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)onScreenLocked:(NSNotification*)notification {
|
- (void)onScreenLocked:(NSNotification*)notification {
|
||||||
for (auto*& emitter : self->emitters) {
|
for (auto* emitter : self->emitters) {
|
||||||
emitter->Emit("lock-screen");
|
emitter->Emit("lock-screen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onScreenUnlocked:(NSNotification*)notification {
|
- (void)onScreenUnlocked:(NSNotification*)notification {
|
||||||
for (auto*& emitter : self->emitters) {
|
for (auto* emitter : self->emitters) {
|
||||||
emitter->Emit("unlock-screen");
|
emitter->Emit("unlock-screen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue