Browse Source

install command in menu

works_for_me
Volker Birk 2 years ago
parent
commit
4fd80280eb
5 changed files with 26 additions and 6 deletions
  1. +19
    -3
      pEpNotifications/pEpNotifications/AppDelegate.swift
  2. +6
    -2
      pEpNotifications/pEpNotifications/Base.lproj/Main.storyboard
  3. BIN
      pEpNotifications/pEpNotifications/de.lproj/Localizable.strings
  4. BIN
      pEpNotifications/pEpNotifications/en.lproj/Localizable.strings
  5. +1
    -1
      pEpNotifications/pEpNotifications/pEpNotifications.entitlements

+ 19
- 3
pEpNotifications/pEpNotifications/AppDelegate.swift View File

@ -34,15 +34,21 @@ enum DNType : Int { case ready = 0, downloading, downloadArrived, noDownloadAvai
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate, NSXPCListenerDelegate, pEpNotificationProtocol {
@IBOutlet weak var _updateNow: NSMenuItem!
@IBOutlet weak var statusText: NSMenuItem!
var statusBarItem: NSStatusItem!
var statusText: NSMenuItem!
var connection: NSXPCConnection!
var service: pEpMacOSAdapterProtocol!
var nc = NSUserNotificationCenter.default
var clientListener: NSXPCListener!
var receiver: pEpNotification!
@IBAction func installNow(_ sender: NSMenuItem) {
let product : Dictionary<String, String> = sender.representedObject as! Dictionary<String, String>
NSLog("pEpNotifications: installNow clicked for %@", product["name"]!)
NSWorkspace.shared.openFile(product["filename"]!)
}
func notifyDownload(_ type: Int, withName: NSString, withFilename: NSString)
{
let _type = DNType.init(rawValue: type)
@ -50,11 +56,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
case .downloading:
NSLog("pEpNotifications: downloading")
statusText.title = "Downloading…"
statusText.isEnabled = false
case .downloadArrived:
NSLog("pEpNotifications: download for %@ arrived %@", withName, withFilename)
let _name = withName
statusText.title = String(format: NSLocalizedString("New version of %@ available", comment: ""), _name)
statusText.isEnabled = true
let un = NSUserNotification()
un.title = NSLocalizedString("Update available", comment: "")
un.informativeText = String(format: NSLocalizedString("A new update for %@ is ready to be installed.", comment: ""), _name)
@ -65,15 +73,20 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
let installTitle : String = NSLocalizedString("Install", comment: "")
un.additionalActions = [NSUserNotificationAction(identifier: "install", title: installTitle)]
un.setValue(true, forKey: "_showsButtons")
un.userInfo = ["name": withName, "filename": withFilename]
statusText.representedObject = ["name": withName, "filename": withFilename]
nc.deliver(un)
case .noDownloadAvailable:
NSLog("pEpNotifications: no download available")
statusText.title = "The software is up to date."
statusText.isEnabled = false
case .ready:
NSLog("pEpNotifications: ready.")
statusText.title = NSLocalizedString("Connected.", comment: "")
statusText.isEnabled = false
case .none:
break;
}
@ -85,13 +98,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
@objc func userNotificationCenter(_ : NSUserNotificationCenter, didActivate: NSUserNotification) {
if didActivate.activationType == NSUserNotification.ActivationType.actionButtonClicked {
NSLog("pEpNotifications: actionButtonClicked")
let filename : String = didActivate.userInfo?["filename"] as! String;
NSLog("pEpNotifications: actionButtonClicked for %@", filename)
NSWorkspace.shared.openFile(filename)
}
}
func proxyErrorHandler(err: Error) -> Void {
NSLog("%@", err.localizedDescription)
statusText.title = NSLocalizedString("Connection failed", comment: "")
statusText.isEnabled = false
}
@objc func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
@ -111,7 +127,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.squareLength)
statusBarItem.button?.title = "p≡p"
statusBarItem.menu = NSApp.menu?.item(at: 0)?.submenu
statusText = NSApp.menu?.item(at: 0)?.submenu?.item(at: 0)
_updateNow.action = #selector(updateNow)
// connect to XPC service
@ -122,6 +137,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
connection.resume()
statusText.title = NSLocalizedString("Connecting…", comment: "")
statusText.isEnabled = false
service = connection.remoteObjectProxyWithErrorHandler(proxyErrorHandler) as? pEpMacOSAdapterProtocol
// init client callback service


+ 6
- 2
pEpNotifications/pEpNotifications/Base.lproj/Main.storyboard View File

@ -13,10 +13,13 @@
<items>
<menuItem title="pEpNotifications" id="1Xt-HY-uBw">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="pEpNotifications" systemMenu="apple" id="uQy-DD-JDr">
<menu key="submenu" title="pEpNotifications" systemMenu="apple" autoenablesItems="NO" id="uQy-DD-JDr">
<items>
<menuItem title="Starting…" id="D45-AS-mhG">
<menuItem title="Starting…" enabled="NO" id="D45-AS-mhG">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="installNow:" target="Voe-Tx-rLC" id="ESa-58-lKy"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="vo5-AO-stB"/>
<menuItem title="Update now" id="aUJ-VR-2jH">
@ -40,6 +43,7 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="pEp_updater" customModuleProvider="target">
<connections>
<outlet property="_updateNow" destination="aUJ-VR-2jH" id="34x-R2-L4V"/>
<outlet property="statusText" destination="D45-AS-mhG" id="PNv-G8-o8P"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>


BIN
pEpNotifications/pEpNotifications/de.lproj/Localizable.strings View File


BIN
pEpNotifications/pEpNotifications/en.lproj/Localizable.strings View File


+ 1
- 1
pEpNotifications/pEpNotifications/pEpNotifications.entitlements View File

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<false/>
<key>com.apple.security.temporary-exception.mach-lookup.global-name</key>
<array>
<string>foundation.pEp.adapter.macOS</string>


Loading…
Cancel
Save