Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support suspend/resume on macOS #24294

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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