Skip to content

Commit

Permalink
add ability to reset to default behaviour on sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
ktgeek committed Apr 11, 2018
1 parent be7c7ec commit 8940886
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions supreSSHion/LockingSupervisor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// SOFTWARE.

import Foundation
import AppKit

class LockingSupervisor : NSObject {
var supressionState: SupresshionState
Expand All @@ -29,9 +30,18 @@ class LockingSupervisor : NSObject {
supressionState = state
super.init();

// I have searched both the net and apple docs, and can't find
// this documented other than net posters catching all
// notifications and determining "com.apple.screenIsLocked" is
// the event we want here. I'd love to use something properly
// defined and documented.
DistributedNotificationCenter.default().addObserver(
self, selector: #selector(self.screenLockedReceived),
name: NSNotification.Name(rawValue: "com.apple.screenIsLocked"), object: nil)

NSWorkspace.shared().notificationCenter.addObserver(
self, selector: #selector(self.workplaceWillSleepReceived),
name: NSNotification.Name.NSWorkspaceWillSleep, object: nil)
}

func screenLockedReceived() {
Expand All @@ -41,13 +51,23 @@ class LockingSupervisor : NSObject {
}
}

// sleeping automatically resumes the key removal behavior. When
// OS X sleeps it issues a sleep notification and then a screen
// lock notification so we only reset the supressionState on the
// sleep notification.
func workplaceWillSleepReceived() {
NSLog("Received sleeping notification")
supressionState.resume()
}

func removeKeysNow() {
let sshAgentCommicator = SSHAgentCommunicator();
sshAgentCommicator.removeKeys()
}

deinit {
DistributedNotificationCenter.default().removeObserver(self);
NSWorkspace.shared().notificationCenter.removeObserver(self);
}
}

Expand Down

0 comments on commit 8940886

Please sign in to comment.