fix: user-did-{resign|become}-active
events on macOS (#41506)
fix: user-did-{resign|become}-active events on macOS
This commit is contained in:
parent
62a897b75b
commit
a7d664e3a3
1 changed files with 29 additions and 25 deletions
|
@ -22,38 +22,42 @@
|
|||
|
||||
- (id)init {
|
||||
if ((self = [super init])) {
|
||||
NSDistributedNotificationCenter* distCenter =
|
||||
NSDistributedNotificationCenter* distributed_center =
|
||||
[NSDistributedNotificationCenter defaultCenter];
|
||||
// A notification that the screen was locked.
|
||||
[distCenter addObserver:self
|
||||
[distributed_center addObserver:self
|
||||
selector:@selector(onScreenLocked:)
|
||||
name:@"com.apple.screenIsLocked"
|
||||
object:nil];
|
||||
// A notification that the screen was unlocked by the user.
|
||||
[distCenter addObserver:self
|
||||
[distributed_center 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
|
||||
[distributed_center addObserver:self
|
||||
selector:@selector(isSuspending:)
|
||||
name:NSWorkspaceWillSleepNotification
|
||||
object:nil];
|
||||
// A notification that the workspace posts when the machine wakes from
|
||||
// sleep.
|
||||
[distCenter addObserver:self
|
||||
[distributed_center addObserver:self
|
||||
selector:@selector(isResuming:)
|
||||
name:NSWorkspaceDidWakeNotification
|
||||
object:nil];
|
||||
|
||||
NSNotificationCenter* shared_center =
|
||||
[[NSWorkspace sharedWorkspace] notificationCenter];
|
||||
|
||||
// A notification that the workspace posts when the user session becomes
|
||||
// active.
|
||||
[distCenter addObserver:self
|
||||
[shared_center addObserver:self
|
||||
selector:@selector(onUserDidBecomeActive:)
|
||||
name:NSWorkspaceSessionDidBecomeActiveNotification
|
||||
object:nil];
|
||||
// A notification that the workspace posts when the user session becomes
|
||||
// inactive.
|
||||
[distCenter addObserver:self
|
||||
[shared_center addObserver:self
|
||||
selector:@selector(onUserDidResignActive:)
|
||||
name:NSWorkspaceSessionDidResignActiveNotification
|
||||
object:nil];
|
||||
|
|
Loading…
Reference in a new issue