Skip to content

Commit

Permalink
remove unnecessary code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
mstarke committed Oct 7, 2022
1 parent a162c19 commit 24164d5
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions MacPass/MPLockDaemon.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void)setLockOnLogout:(BOOL)lockOnLogout {
if(_lockOnLogout != lockOnLogout) {
_lockOnLogout = lockOnLogout;
if(_lockOnLogout) {
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_willLogOutNotification:) name:NSWorkspaceSessionDidResignActiveNotification object:nil];
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_lockDocumentsForNotification:) name:NSWorkspaceSessionDidResignActiveNotification object:nil];
}
else {
[NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:@"" object:nil];
Expand All @@ -89,7 +89,7 @@ - (void)setLockOnSleep:(BOOL)lockOnSleep {
if(_lockOnSleep != lockOnSleep) {
_lockOnSleep = lockOnSleep;
if(_lockOnSleep) {
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_willSleepNotification:) name:NSWorkspaceWillSleepNotification object:nil];
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_lockDocumentsForNotification:) name:NSWorkspaceWillSleepNotification object:nil];
}
else {
[NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceWillSleepNotification object:nil];
Expand All @@ -101,7 +101,7 @@ - (void)setLockOnScreenSleep:(BOOL)lockOnScreenSleep {
if(_lockOnScreenSleep != lockOnScreenSleep) {
_lockOnScreenSleep = lockOnScreenSleep;
if(_lockOnScreenSleep) {
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_willScreenSleepNotification:) name:NSWorkspaceScreensDidSleepNotification object:nil];
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_lockDocumentsForNotification:) name:NSWorkspaceScreensDidSleepNotification object:nil];
}
else {
[NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceScreensDidSleepNotification object:nil];
Expand All @@ -120,14 +120,7 @@ - (void)setIdleLockTime:(NSUInteger)idleLockTime {
}
}
}

- (void)_willLogOutNotification:(NSNotification *)notification {
[((MPAppDelegate *)NSApp.delegate) lockAllDocuments];
}
- (void)_willSleepNotification:(NSNotification *)notification {
[((MPAppDelegate *)NSApp.delegate) lockAllDocuments];
}
- (void)_willScreenSleepNotification:(NSNotification *)notification {
- (void)_lockDocumentsForNotification:(NSNotification *)notification {
[((MPAppDelegate *)NSApp.delegate) lockAllDocuments];
}

Expand Down

0 comments on commit 24164d5

Please sign in to comment.