|
|
@ -11,16 +11,27 @@ import Cocoa |
|
|
|
import SwiftUI |
|
|
|
|
|
|
|
@objc enum DNType : Int { case downloading, downloadArrived, noDownloadAvailable } |
|
|
|
typealias DownloadNotification = (_: DNType, NSString, NSString) -> Void |
|
|
|
|
|
|
|
@objc(pEpNotificationProtocol) protocol pEpNotificationProtocol { |
|
|
|
func notifyDownload(type: DNType, name: NSString, filename: NSString) |
|
|
|
} |
|
|
|
|
|
|
|
@objc(pEpMacOSAdapterProtocol) protocol pEpMacOSAdapterProtocol { |
|
|
|
func subscribeForUpdate(downloadNotification: @escaping DownloadNotification) |
|
|
|
func subscribeForUpdate() |
|
|
|
func unsubscribeForUpdate() |
|
|
|
func updateNow() |
|
|
|
} |
|
|
|
|
|
|
|
@objc class pEpNotification : NSObject, pEpNotificationProtocol { |
|
|
|
var delegate: pEpNotificationProtocol! |
|
|
|
|
|
|
|
func notifyDownload(type: DNType, name: NSString, filename: NSString) { |
|
|
|
delegate?.notifyDownload(type: type, name: name, filename: filename) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@NSApplicationMain |
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate { |
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate, pEpNotificationProtocol { |
|
|
|
@IBOutlet weak var _updateNow: NSMenuItem! |
|
|
|
|
|
|
|
var statusBarItem: NSStatusItem! |
|
|
@ -28,16 +39,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
var connection: NSXPCConnection! |
|
|
|
var service: pEpMacOSAdapterProtocol! |
|
|
|
var nc = NSUserNotificationCenter.default |
|
|
|
var receiver: pEpNotification! |
|
|
|
|
|
|
|
func notifyDownload(notification: DNType, name: NSString, download: NSString) |
|
|
|
func notifyDownload(type: DNType, name: NSString, filename: NSString) |
|
|
|
{ |
|
|
|
switch notification { |
|
|
|
switch type { |
|
|
|
case .downloading: |
|
|
|
NSLog("pEpNotifications: downloading") |
|
|
|
statusText.title = "Downloading…" |
|
|
|
|
|
|
|
case .downloadArrived: |
|
|
|
NSLog("pEpNotifications: download for %@ arrived %@", name, download) |
|
|
|
NSLog("pEpNotifications: download for %@ arrived %@", name, filename) |
|
|
|
let _name : String = name as String |
|
|
|
statusText.title = String(format: NSLocalizedString("New version of %@ available", comment: ""), _name) |
|
|
|
let un = NSUserNotification() |
|
|
@ -74,7 +86,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
statusText.title = NSLocalizedString("Connection failed", comment: "") |
|
|
|
} |
|
|
|
|
|
|
|
internal func applicationDidFinishLaunching(_ aNotification: Notification) { |
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) { |
|
|
|
let statusBar = NSStatusBar.system |
|
|
|
|
|
|
|
// configure Menu Item Extra |
|
|
@ -97,7 +109,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
statusText.title = NSLocalizedString("Connecting…", comment: "") |
|
|
|
service = connection.remoteObjectProxyWithErrorHandler(proxyErrorHandler) as? pEpMacOSAdapterProtocol |
|
|
|
|
|
|
|
service.subscribeForUpdate(downloadNotification: notifyDownload) |
|
|
|
receiver = pEpNotification() |
|
|
|
receiver.delegate = self |
|
|
|
connection.exportedObject = receiver |
|
|
|
connection.exportedInterface = NSXPCInterface.init(with: pEpNotificationProtocol.self) |
|
|
|
service.subscribeForUpdate() |
|
|
|
|
|
|
|
statusText.title = NSLocalizedString("Connected.", comment: "") |
|
|
|
} |
|
|
|
else { |
|
|
@ -108,7 +125,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele |
|
|
|
nc.delegate = self |
|
|
|
} |
|
|
|
|
|
|
|
internal func applicationWillTerminate(_ aNotification: Notification) { |
|
|
|
func applicationWillTerminate(_ aNotification: Notification) { |
|
|
|
service.unsubscribeForUpdate() |
|
|
|
connection?.invalidate() |
|
|
|
} |
|
|
|