Browse Source

don't always show this menu

works_for_me
Volker Birk 2 years ago
parent
commit
ac62cf52e3
3 changed files with 47 additions and 7 deletions
  1. +38
    -6
      pEpNotifications/pEpNotifications/AppDelegate.swift
  2. +8
    -1
      pEpNotifications/pEpNotifications/Base.lproj/Main.storyboard
  3. +1
    -0
      pEpNotifications/pEpNotifications/de.lproj/Main.strings

+ 38
- 6
pEpNotifications/pEpNotifications/AppDelegate.swift View File

@ -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


+ 8
- 1
pEpNotifications/pEpNotifications/Base.lproj/Main.storyboard View File

@ -25,12 +25,18 @@
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="vo5-AO-stB"/>
<menuItem title="Item" id="y9Y-ru-Qxs" userLabel="Schedule updates">
<menuItem title="Schedule updates" id="y9Y-ru-Qxs" userLabel="Schedule updates">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="scheduleUpdates:" target="Voe-Tx-rLC" id="H5q-dk-4ys"/>
</connections>
</menuItem>
<menuItem title="Always show this menu" id="u5e-3R-3lT">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="alwaysShowThisMenu:" target="Voe-Tx-rLC" id="fty-fL-gSf"/>
</connections>
</menuItem>
<menuItem title="Quit p≡p" hidden="YES" id="4sb-4s-VLi" userLabel="Quit p≡p">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
@ -48,6 +54,7 @@
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="pEp_updater" customModuleProvider="target">
<connections>
<outlet property="_alwaysShowThisMenu" destination="u5e-3R-3lT" id="cw9-oL-BVd"/>
<outlet property="_scheduleUpdates" destination="y9Y-ru-Qxs" id="JEY-Hx-pbv"/>
<outlet property="_updateNow" destination="aUJ-VR-2jH" id="34x-R2-L4V"/>
<outlet property="pEpMenu" destination="uQy-DD-JDr" id="SSj-Qs-zAq"/>


+ 1
- 0
pEpNotifications/pEpNotifications/de.lproj/Main.strings View File

@ -19,3 +19,4 @@
"2ca-qV-RUD.title" = "Dieses Menü ausblenden falls kein Update vorhanden";
"y9Y-ru-Qxs.title" = "Automatische Updates";
"u5e-3R-3lT.title" = "Dieses Menü immer anzeigen";

Loading…
Cancel
Save