|
|
@ -47,6 +47,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
var nc = NSUserNotificationCenter.default |
|
|
|
lazy var clientListener: NSXPCListener = NSXPCListener.anonymous() |
|
|
|
var receiver: pEpNotification! |
|
|
|
lazy var downloadStateNotifier = DownloadStateNotifier(at: statusText) |
|
|
|
|
|
|
|
@objc func installMenuExtra() { |
|
|
|
guard statusBarItem == nil else { |
|
|
@ -70,19 +71,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
statusBarItem = nil |
|
|
|
} |
|
|
|
|
|
|
|
func setDownloadState(_ text: String, _ product: Dictionary<String, Any>? = nil) { |
|
|
|
if product == nil { |
|
|
|
statusText.title = NSLocalizedString(text, comment: "") |
|
|
|
statusText.isEnabled = false |
|
|
|
} else { |
|
|
|
let name = product?["name"] as! String |
|
|
|
statusText.title = String.localizedStringWithFormat(NSLocalizedString(text, comment: ""), name) |
|
|
|
statusText.isEnabled = true |
|
|
|
} |
|
|
|
|
|
|
|
statusText.representedObject = product |
|
|
|
} |
|
|
|
|
|
|
|
@IBAction func scheduleUpdates(_ sender: NSMenuItem) { |
|
|
|
if sender.state == NSControl.StateValue.on { |
|
|
|
sender.state = NSControl.StateValue.off |
|
|
@ -116,7 +104,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
NSLog("pEpNotifications: installNow clicked for %@", product["name"] as! String) |
|
|
|
NSWorkspace.shared.openFile(product["filename"] as! String) |
|
|
|
sender.representedObject = nil |
|
|
|
setDownloadState("Connected.") |
|
|
|
downloadStateNotifier.notify(.Connected) |
|
|
|
} |
|
|
|
|
|
|
|
func notifyDownload(_ type: Int, withName: NSString, withFilename: NSString) { |
|
|
@ -124,7 +112,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
switch _type { |
|
|
|
case .downloading: |
|
|
|
NSLog("pEpNotifications: downloading") |
|
|
|
setDownloadState(String(format: NSLocalizedString("Downloading update for %@…", comment: ""), withName)) |
|
|
|
downloadStateNotifier.notify(.Downloading(String(withName))) |
|
|
|
self.performSelector(onMainThread: #selector(installMenuExtra), with:nil, waitUntilDone: false) |
|
|
|
|
|
|
|
case .downloadArrived: |
|
|
@ -142,15 +130,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
un.setValue(true, forKey: "_showsButtons") |
|
|
|
un.userInfo = ["name": withName, "filename": withFilename] |
|
|
|
nc.deliver(un) |
|
|
|
setDownloadState("New version of %@ available", ["name": withName, "filename": withFilename, "notification": un]) |
|
|
|
let product = ["name": withName, "filename": withFilename, "notification": un] |
|
|
|
downloadStateNotifier.notify(.NewVersionAvailable(String(withName)), with: product) |
|
|
|
|
|
|
|
case .noDownloadAvailable: |
|
|
|
NSLog("pEpNotifications: no download available") |
|
|
|
setDownloadState("The software is up to date.") |
|
|
|
downloadStateNotifier.notify(.UpToDate) |
|
|
|
|
|
|
|
case .ready: |
|
|
|
NSLog("pEpNotifications: ready.") |
|
|
|
setDownloadState("Connected.") |
|
|
|
downloadStateNotifier.notify(.Connected) |
|
|
|
|
|
|
|
case .none: |
|
|
|
break |
|
|
@ -189,12 +178,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
let filename : String = didActivate.userInfo?["filename"] as! String |
|
|
|
NSLog("pEpNotifications: actionButtonClicked for %@", filename) |
|
|
|
NSWorkspace.shared.openFile(filename) |
|
|
|
setDownloadState("Connected.") |
|
|
|
downloadStateNotifier.notify(.Connected) |
|
|
|
} |
|
|
|
|
|
|
|
func proxyErrorHandler(err: Error) -> Void { |
|
|
|
NSLog("%@", err.localizedDescription) |
|
|
|
setDownloadState("Connection failed") |
|
|
|
downloadStateNotifier.notify(.ConnectionFailed) |
|
|
|
} |
|
|
|
|
|
|
|
@objc func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool { |
|
|
@ -211,7 +200,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
// preference defaults |
|
|
|
setupAppDefaults() |
|
|
|
|
|
|
|
setDownloadState("Connecting…") |
|
|
|
downloadStateNotifier.notify(.Connecting) |
|
|
|
|
|
|
|
// connect to XPC service |
|
|
|
initXPCConnection() |
|
|
|