Romve show proxy mode as text on status bar.

This commit is contained in:
Qiu Yuzhou
2017-03-25 15:15:53 +08:00
parent 2b8dd02b5f
commit 73396e4ff1
2 changed files with 61 additions and 121 deletions

View File

@ -80,7 +80,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
"Kcptun.LocalHost": "127.0.0.1",
"Kcptun.LocalPort": NSNumber(value: 8388),
"Kcptun.Conn": NSNumber(value: 1),
"ShowRunningModeOnStatusBar": false,
])
statusItem = NSStatusBar.system().statusItem(withLength: AppDelegate.StatusItemIconWidth)
@ -90,14 +89,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
statusItem.menu = statusMenu
_ = defaults.rx.observe(Bool.self, "ShowRunningModeOnStatusBar")
// .distinctUntilChanged()
.subscribe(onNext: { value in
if let enabled = value {
self.updateStatusItemUI(isShownnRunningMode: enabled)
}
})
let notifyCenter = NotificationCenter.default
_ = notifyCenter.rx.notification(NOTIFY_CONF_CHANGED)
@ -410,8 +401,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
globalModeMenuItem.state = 0
manualModeMenuItem.state = 1
}
let isShown = defaults.bool(forKey: "ShowRunningModeOnStatusBar")
updateStatusItemUI(isShownnRunningMode: isShown)
updateStatusMenuImage()
}
@ -436,26 +425,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
}
}
func updateStatusItemUI(isShownnRunningMode: Bool) {
if isShownnRunningMode {
let defaults = UserDefaults.standard
let mode = defaults.string(forKey: "ShadowsocksRunningMode")
if mode == "auto" {
statusItem.title = "A"
} else if mode == "global" {
statusItem.title = "G"
} else if mode == "manual" {
statusItem.title = "M"
}
let titleWidth = statusItem.title!.size(withAttributes: [NSFontAttributeName: statusItem.button!.font!]).width
let imageWidth:CGFloat = AppDelegate.StatusItemIconWidth
statusItem.length = titleWidth + imageWidth + 2
} else {
statusItem.length = AppDelegate.StatusItemIconWidth
}
}
func updateMainMenu() {
let defaults = UserDefaults.standard
let isOn = defaults.bool(forKey: "ShadowsocksOn")