From 9c24595486e244ebb496ebffad3baa2033530aaa Mon Sep 17 00:00:00 2001 From: bestv Date: Sat, 1 Oct 2016 12:45:42 +0800 Subject: [PATCH] show running mode on status bar --- ShadowsocksX-NG/AppDelegate.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 4f2f90f..b855491 100644 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -349,6 +349,22 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele globalModeMenuItem.state = 0 manualModeMenuItem.state = 1 } + updateStatusItemUI() + } + + func updateStatusItemUI() { + let defaults = NSUserDefaults.standardUserDefaults() + let mode = defaults.stringForKey("ShadowsocksRunningMode") + if mode == "auto" { + statusItem.title = "Auto".localized + } else if mode == "global" { + statusItem.title = "Global".localized + } else if mode == "manual" { + statusItem.title = "Manual".localized + } + let titleWidth = statusItem.title!.sizeWithAttributes([NSFontAttributeName: statusItem.button!.font!]).width + let imageWidth:CGFloat = 22 + statusItem.length = titleWidth + imageWidth } func updateMainMenu() {