|
|
@ -39,22 +39,32 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
@IBOutlet weak var statusText: NSMenuItem! |
|
|
|
@IBOutlet weak var _updateNow: NSMenuItem! |
|
|
|
@IBOutlet weak var _scheduleUpdates: NSMenuItem! |
|
|
|
@IBOutlet weak var _alwaysShowThisMenu: NSMenuItem! |
|
|
|
|
|
|
|
var statusBarItem: NSStatusItem! |
|
|
|
var statusBarItem: NSStatusItem? = nil |
|
|
|
var connection: NSXPCConnection! |
|
|
|
var service: pEpMacOSAdapterProtocol! |
|
|
|
var nc = NSUserNotificationCenter.default |
|
|
|
var clientListener: NSXPCListener! |
|
|
|
var receiver: pEpNotification! |
|
|
|
|
|
|
|
func setDownloadState(_ text: String, _ product: Dictionary<String, Any>? = nil) { |
|
|
|
@objc func installMenuExtra() { |
|
|
|
if statusBarItem == nil { |
|
|
|
statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength) |
|
|
|
statusBarItem.button?.title = "p≡p" |
|
|
|
statusBarItem.menu = NSApp.menu?.item(at: 0)?.submenu |
|
|
|
statusBarItem?.button?.title = "p≡p" |
|
|
|
statusBarItem?.menu = NSApp.menu?.item(at: 0)?.submenu |
|
|
|
_updateNow.action = #selector(updateNow) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func uninstallMenuExtra() { |
|
|
|
if (statusBarItem != nil && !UserDefaults.standard.bool(forKey: "AlwaysShowThisMenu")) { |
|
|
|
NSStatusBar.system.removeStatusItem(statusBarItem!) |
|
|
|
statusBarItem = nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func setDownloadState(_ text: String, _ product: Dictionary<String, Any>? = nil) { |
|
|
|
if product == nil { |
|
|
|
statusText.title = NSLocalizedString(text, comment: "") |
|
|
|
statusText.isEnabled = false |
|
|
@ -80,7 +90,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@IBAction func alwaysShowThisMenu(_ sender: NSMenuItem) { |
|
|
|
if sender.state == NSControl.StateValue.on { |
|
|
|
sender.state = NSControl.StateValue.off |
|
|
|
UserDefaults.standard.set(false, forKey: "AlwaysShowThisMenu") |
|
|
|
} |
|
|
|
else { |
|
|
|
sender.state = NSControl.StateValue.on |
|
|
|
UserDefaults.standard.set(true, forKey: "AlwaysShowThisMenu") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@IBAction func installNow(_ sender: NSMenuItem) { |
|
|
|
uninstallMenuExtra() |
|
|
|
let product = sender.representedObject as! Dictionary<String, Any> |
|
|
|
let un = product["notification"] as! NSUserNotification |
|
|
|
nc.removeDeliveredNotification(un) |
|
|
@ -97,6 +119,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
case .downloading: |
|
|
|
NSLog("pEpNotifications: downloading") |
|
|
|
setDownloadState("Downloading…") |
|
|
|
self.performSelector(onMainThread: #selector(installMenuExtra), with:nil, waitUntilDone: false) |
|
|
|
|
|
|
|
case .downloadArrived: |
|
|
|
let un = NSUserNotification() |
|
|
@ -133,6 +156,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
|
|
|
|
@objc func userNotificationCenter(_ : NSUserNotificationCenter, didActivate: NSUserNotification) { |
|
|
|
if didActivate.activationType == NSUserNotification.ActivationType.actionButtonClicked { |
|
|
|
uninstallMenuExtra() |
|
|
|
let filename : String = didActivate.userInfo?["filename"] as! String; |
|
|
|
NSLog("pEpNotifications: actionButtonClicked for %@", filename) |
|
|
|
NSWorkspace.shared.openFile(filename) |
|
|
@ -157,8 +181,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) { |
|
|
|
// preference defaults |
|
|
|
|
|
|
|
let appDefaults = ["ScheduleUpdates": true] |
|
|
|
let appDefaults = ["ScheduleUpdates": true, "AlwaysShowThisMenu": false] |
|
|
|
UserDefaults.standard.register(defaults: appDefaults) |
|
|
|
if UserDefaults.standard.bool(forKey: "AlwaysShowThisMenu") { |
|
|
|
_alwaysShowThisMenu.state = NSControl.StateValue.on |
|
|
|
installMenuExtra() |
|
|
|
} |
|
|
|
else { |
|
|
|
_alwaysShowThisMenu.state = NSControl.StateValue.off |
|
|
|
} |
|
|
|
|
|
|
|
setDownloadState("Connecting…") |
|
|
|
|
|
|
|
// connect to XPC service |
|
|
|