|
|
@ -33,8 +33,10 @@ enum DNType : Int { case ready = 0, downloading, downloadArrived, noDownloadAvai |
|
|
|
|
|
|
|
@NSApplicationMain |
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate, NSXPCListenerDelegate, pEpNotificationProtocol { |
|
|
|
@IBOutlet weak var pEpMenu: NSMenu! |
|
|
|
@IBOutlet weak var _updateNow: NSMenuItem! |
|
|
|
@IBOutlet weak var statusText: NSMenuItem! |
|
|
|
@IBOutlet weak var _hideMenu: NSMenuItem! |
|
|
|
|
|
|
|
var statusBarItem: NSStatusItem! |
|
|
|
var connection: NSXPCConnection! |
|
|
@ -43,6 +45,20 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
var clientListener: NSXPCListener! |
|
|
|
var receiver: pEpNotification! |
|
|
|
|
|
|
|
@IBAction func hideMenu(_ sender: NSMenuItem) { |
|
|
|
if sender.state == NSControl.StateValue.on { |
|
|
|
sender.state = NSControl.StateValue.off |
|
|
|
UserDefaults.standard.set(false, forKey: "HideWithoutUpdate") |
|
|
|
} |
|
|
|
else { |
|
|
|
sender.state = NSControl.StateValue.on |
|
|
|
UserDefaults.standard.set(true, forKey: "HideWithoutUpdate") |
|
|
|
if statusText.representedObject == nil { |
|
|
|
NSStatusBar.system.removeStatusItem(statusBarItem) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@IBAction func installNow(_ sender: NSMenuItem) { |
|
|
|
let product : Dictionary<String, String> = sender.representedObject as! Dictionary<String, String> |
|
|
|
NSLog("pEpNotifications: installNow clicked for %@", product["name"]!) |
|
|
@ -93,6 +109,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
} |
|
|
|
|
|
|
|
@objc func updateNow() { |
|
|
|
nc.removeAllDeliveredNotifications() |
|
|
|
service.updateNow() |
|
|
|
} |
|
|
|
|
|
|
@ -122,6 +139,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) { |
|
|
|
let statusBar = NSStatusBar.system |
|
|
|
|
|
|
|
// preference defaults |
|
|
|
|
|
|
|
let appDefaults = ["HideWithoutUpdate": true] |
|
|
|
UserDefaults.standard.register(defaults: appDefaults) |
|
|
|
|
|
|
|
// configure Menu Item Extra |
|
|
|
|
|
|
|
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.squareLength) |
|
|
@ -129,6 +151,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
statusBarItem.menu = NSApp.menu?.item(at: 0)?.submenu |
|
|
|
_updateNow.action = #selector(updateNow) |
|
|
|
|
|
|
|
// initialize statusText |
|
|
|
|
|
|
|
if UserDefaults.standard.bool(forKey: "HideWithoutUpdate") { |
|
|
|
_hideMenu.state = NSControl.StateValue.on |
|
|
|
} |
|
|
|
else { |
|
|
|
_hideMenu.state = NSControl.StateValue.off |
|
|
|
} |
|
|
|
|
|
|
|
// connect to XPC service |
|
|
|
|
|
|
|
connection = NSXPCConnection.init(machServiceName: "foundation.pEp.adapter.macOS") |
|
|
|