fix: user-did-{resign|become}-active events on macOS (#41528)

fix: user-did-{resign|become}-active events on macOS

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2024-03-06 17:09:56 +01:00 committed by GitHub
parent e7300ad4c8
commit 333ee6d51a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,41 +22,45 @@
- (id)init { - (id)init {
if ((self = [super init])) { if ((self = [super init])) {
NSDistributedNotificationCenter* distCenter = NSDistributedNotificationCenter* distributed_center =
[NSDistributedNotificationCenter defaultCenter]; [NSDistributedNotificationCenter defaultCenter];
// A notification that the screen was locked. // A notification that the screen was locked.
[distCenter addObserver:self [distributed_center addObserver:self
selector:@selector(onScreenLocked:) selector:@selector(onScreenLocked:)
name:@"com.apple.screenIsLocked" name:@"com.apple.screenIsLocked"
object:nil]; object:nil];
// A notification that the screen was unlocked by the user. // A notification that the screen was unlocked by the user.
[distCenter addObserver:self [distributed_center addObserver:self
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. // A notification that the workspace posts before the machine goes to sleep.
[distCenter addObserver:self [distributed_center addObserver:self
selector:@selector(isSuspending:) selector:@selector(isSuspending:)
name:NSWorkspaceWillSleepNotification name:NSWorkspaceWillSleepNotification
object:nil]; object:nil];
// A notification that the workspace posts when the machine wakes from // A notification that the workspace posts when the machine wakes from
// sleep. // sleep.
[distCenter addObserver:self [distributed_center addObserver:self
selector:@selector(isResuming:) selector:@selector(isResuming:)
name:NSWorkspaceDidWakeNotification name:NSWorkspaceDidWakeNotification
object:nil]; object:nil];
NSNotificationCenter* shared_center =
[[NSWorkspace sharedWorkspace] notificationCenter];
// A notification that the workspace posts when the user session becomes // A notification that the workspace posts when the user session becomes
// active. // active.
[distCenter addObserver:self [shared_center addObserver:self
selector:@selector(onUserDidBecomeActive:) selector:@selector(onUserDidBecomeActive:)
name:NSWorkspaceSessionDidBecomeActiveNotification name:NSWorkspaceSessionDidBecomeActiveNotification
object:nil]; object:nil];
// A notification that the workspace posts when the user session becomes // A notification that the workspace posts when the user session becomes
// inactive. // inactive.
[distCenter addObserver:self [shared_center addObserver:self
selector:@selector(onUserDidResignActive:) selector:@selector(onUserDidResignActive:)
name:NSWorkspaceSessionDidResignActiveNotification name:NSWorkspaceSessionDidResignActiveNotification
object:nil]; object:nil];
} }
return self; return self;
} }