2019-07-26 20:38:19 -06:00
|
|
|
//
|
|
|
|
// AppDelegate.swift
|
|
|
|
// dotBeatBar_old
|
|
|
|
//
|
|
|
|
// Created by Aaron Bieber on 7/26/19.
|
|
|
|
// Copyright © 2019 Aaron Bieber. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2019-07-26 21:44:43 -06:00
|
|
|
import Beat
|
2019-07-27 08:49:55 -06:00
|
|
|
import Cocoa
|
2019-07-26 21:44:43 -06:00
|
|
|
import Foundation
|
2019-07-26 20:38:19 -06:00
|
|
|
|
|
|
|
@NSApplicationMain
|
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
2021-01-01 15:56:01 -07:00
|
|
|
let dnc = DistributedNotificationCenter.default()
|
2019-07-26 21:44:43 -06:00
|
|
|
var timer = Timer()
|
2021-01-01 15:56:01 -07:00
|
|
|
|
2019-07-26 21:44:43 -06:00
|
|
|
let si = NSStatusBar.system.statusItem(withLength:NSStatusItem.variableLength)
|
2021-01-01 15:56:01 -07:00
|
|
|
|
2019-07-26 21:44:43 -06:00
|
|
|
@objc func updateStatBar(_ sender: Any?) {
|
|
|
|
if let button = si.button {
|
2019-08-08 16:35:10 -06:00
|
|
|
button.title = "@\(Beat().text())"
|
2019-07-26 21:44:43 -06:00
|
|
|
}
|
|
|
|
}
|
2021-01-01 15:56:01 -07:00
|
|
|
|
2019-07-26 20:38:19 -06:00
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
2019-07-26 21:44:43 -06:00
|
|
|
updateStatBar(self)
|
2019-08-08 16:35:10 -06:00
|
|
|
timer = Timer.scheduledTimer(timeInterval: 1,
|
2019-07-27 08:49:55 -06:00
|
|
|
target: self,
|
|
|
|
selector: #selector(updateStatBar),
|
|
|
|
userInfo: nil,
|
|
|
|
repeats: true)
|
2019-07-26 21:44:43 -06:00
|
|
|
|
|
|
|
let menu = NSMenu()
|
2021-01-01 15:56:01 -07:00
|
|
|
|
2019-07-26 21:44:43 -06:00
|
|
|
menu.addItem(NSMenuItem(title: "Quit", action:
|
|
|
|
#selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
|
|
|
|
|
|
|
|
si.menu = menu
|
2021-01-01 15:56:01 -07:00
|
|
|
|
|
|
|
_ = dnc.addObserver(forName: .init("com.apple.screenIsLocked"),
|
|
|
|
object: nil, queue: .main) { _ in
|
|
|
|
NSLog("Screen Locked. Removing ssh-agent keys.")
|
|
|
|
let task = Process()
|
|
|
|
let pipe = Pipe()
|
|
|
|
|
|
|
|
task.executableURL = URL(fileURLWithPath: "/usr/bin/ssh-add")
|
|
|
|
task.arguments = ["-D"]
|
|
|
|
task.standardOutput = pipe
|
|
|
|
task.launch()
|
|
|
|
|
|
|
|
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
|
|
|
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
|
|
|
|
|
|
|
|
NSLog(output! as String)
|
|
|
|
}
|
2019-07-26 20:38:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func applicationWillTerminate(_ aNotification: Notification) {
|
2019-07-26 21:44:43 -06:00
|
|
|
timer.invalidate()
|
2019-07-26 20:38:19 -06:00
|
|
|
}
|
|
|
|
}
|