mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
* chore: bump chromium in DEPS to 117.0.5921.0 * chore: update chromium patches * 4721409: Remove redundant ARC configuration in /components | https://chromium-review.googlesource.com/c/chromium/src/+/4721409 * 4643750: Add V8_LOW_PRIORITY_TQ for main thread | https://chromium-review.googlesource.com/c/chromium/src/+/4643750 * 4022621: Re-register status item when owner of status watcher is changed | https://chromium-review.googlesource.com/c/chromium/src/+/4022621 * chore: update V8/boringssl patches * fixup! 4643750: Add V8_LOW_PRIORITY_TQ for main thread | https://chromium-review.googlesource.com/c/chromium/src/+/4643750 * chore: bump chromium in DEPS to 117.0.5923.0 * build [debug]: remove assert 4722125: Update enterprise content analysis buildflags usage | https://chromium-review.googlesource.com/c/chromium/src/+/4722125 * chore: manually rollback to 117.0.5921.0 * build [arc]: ARC conversion in auto_updater * build [arc]: ARC conversion in browser/api * build [arc]: ARC conversion in notifications/mac * build [arc]: ARC conversion in in_app_purchase * build [arc]: ARC conversion in browser/ui * build [arc]: ARC conversion in ui/cocoa * build [arc]: ARC conversion in shell/common * build [arc]: ARC conversion in OSR * build [arc]: ARC conversion in login_helper * build [arc]: ARC conversion in app_mas * build [arc]: fix up ARC syntax (thanks @codebytere!) * 4726946: [Extensions] Work around dangling BrowserContext pointer. | https://chromium-review.googlesource.com/c/chromium/src/+/4726946 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
121 lines
3.5 KiB
Plaintext
121 lines
3.5 KiB
Plaintext
// Copyright (c) 2013 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/api/electron_api_power_monitor.h"
|
|
|
|
#include <vector>
|
|
|
|
#import <ApplicationServices/ApplicationServices.h>
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
@interface MacLockMonitor : NSObject {
|
|
@private
|
|
std::vector<electron::api::PowerMonitor*> emitters;
|
|
}
|
|
|
|
- (void)addEmitter:(electron::api::PowerMonitor*)monitor_;
|
|
|
|
@end
|
|
|
|
@implementation MacLockMonitor
|
|
|
|
- (id)init {
|
|
if ((self = [super init])) {
|
|
NSDistributedNotificationCenter* distCenter =
|
|
[NSDistributedNotificationCenter defaultCenter];
|
|
// A notification that the screen was locked.
|
|
[distCenter addObserver:self
|
|
selector:@selector(onScreenLocked:)
|
|
name:@"com.apple.screenIsLocked"
|
|
object:nil];
|
|
// A notification that the screen was unlocked by the user.
|
|
[distCenter addObserver:self
|
|
selector:@selector(onScreenUnlocked:)
|
|
name:@"com.apple.screenIsUnlocked"
|
|
object:nil];
|
|
// A notification that the workspace posts before the machine goes to sleep.
|
|
[distCenter addObserver:self
|
|
selector:@selector(isSuspending:)
|
|
name:NSWorkspaceWillSleepNotification
|
|
object:nil];
|
|
// A notification that the workspace posts when the machine wakes from
|
|
// sleep.
|
|
[distCenter addObserver:self
|
|
selector:@selector(isResuming:)
|
|
name:NSWorkspaceDidWakeNotification
|
|
object:nil];
|
|
// A notification that the workspace posts when the user session becomes
|
|
// active.
|
|
[distCenter addObserver:self
|
|
selector:@selector(onUserDidBecomeActive:)
|
|
name:NSWorkspaceSessionDidBecomeActiveNotification
|
|
object:nil];
|
|
// A notification that the workspace posts when the user session becomes
|
|
// inactive.
|
|
[distCenter addObserver:self
|
|
selector:@selector(onUserDidResignActive:)
|
|
name:NSWorkspaceSessionDidResignActiveNotification
|
|
object:nil];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)dealloc {
|
|
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
|
|
}
|
|
|
|
- (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) {
|
|
emitter->Emit("lock-screen");
|
|
}
|
|
}
|
|
|
|
- (void)onScreenUnlocked:(NSNotification*)notification {
|
|
for (auto* emitter : self->emitters) {
|
|
emitter->Emit("unlock-screen");
|
|
}
|
|
}
|
|
|
|
- (void)onUserDidBecomeActive:(NSNotification*)notification {
|
|
for (auto* emitter : self->emitters) {
|
|
emitter->Emit("user-did-become-active");
|
|
}
|
|
}
|
|
|
|
- (void)onUserDidResignActive:(NSNotification*)notification {
|
|
for (auto* emitter : self->emitters) {
|
|
emitter->Emit("user-did-resign-active");
|
|
}
|
|
}
|
|
|
|
@end
|
|
|
|
namespace electron::api {
|
|
|
|
static MacLockMonitor* g_lock_monitor = nil;
|
|
|
|
void PowerMonitor::InitPlatformSpecificMonitors() {
|
|
if (!g_lock_monitor)
|
|
g_lock_monitor = [[MacLockMonitor alloc] init];
|
|
[g_lock_monitor addEmitter:this];
|
|
}
|
|
|
|
} // namespace electron::api
|