Skip to content

Commit

Permalink
feat: support suspend/resume on macOS (#24294)
Browse files Browse the repository at this point in the history
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Jun 29, 2020
1 parent 7607227 commit f6ce6ca
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions shell/browser/api/electron_api_power_monitor_mac.mm
Expand Up @@ -32,6 +32,21 @@ - (id)init {
selector:@selector(onScreenUnlocked:)
name:@"com.apple.screenIsUnlocked"
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;
}
Expand All @@ -45,14 +60,26 @@ - (void)addEmitter:(electron::api::PowerMonitor*)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 {
for (auto*& emitter : self->emitters) {
for (auto* emitter : self->emitters) {
emitter->Emit("lock-screen");
}
}

- (void)onScreenUnlocked:(NSNotification*)notification {
for (auto*& emitter : self->emitters) {
for (auto* emitter : self->emitters) {
emitter->Emit("unlock-screen");
}
}
Expand Down

0 comments on commit f6ce6ca

Please sign in to comment.