代理菜单内增加状态栏文本显示开关
This commit is contained in:
71
ShadowsocksX-NG/AppDelegate.swift
Normal file → Executable file
71
ShadowsocksX-NG/AppDelegate.swift
Normal file → Executable file
@ -17,7 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
var advPreferencesWinCtrl: AdvPreferencesWindowController!
|
||||
var proxyPreferencesWinCtrl: ProxyPreferencesController!
|
||||
var editUserRulesWinCtrl: UserRulesController!
|
||||
|
||||
|
||||
var launchAtLoginController: LaunchAtLoginController = LaunchAtLoginController()
|
||||
|
||||
@IBOutlet weak var window: NSWindow!
|
||||
@ -29,6 +29,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
@IBOutlet weak var autoModeMenuItem: NSMenuItem!
|
||||
@IBOutlet weak var globalModeMenuItem: NSMenuItem!
|
||||
@IBOutlet weak var manualModeMenuItem: NSMenuItem!
|
||||
@IBOutlet weak var showRunningModeMenuItem: NSMenuItem!
|
||||
|
||||
@IBOutlet weak var serversMenuItem: NSMenuItem!
|
||||
@IBOutlet var showQRCodeMenuItem: NSMenuItem!
|
||||
@ -39,6 +40,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
|
||||
var statusItem: NSStatusItem!
|
||||
|
||||
static let StatusItemIconWidth:CGFloat = 20
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
// Insert code here to initialize your application
|
||||
|
||||
@ -61,9 +64,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
"LocalSocks5.EnableVerboseMode": NSNumber(value: false as Bool),
|
||||
"GFWListURL": "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt",
|
||||
"AutoConfigureNetworkServices": NSNumber(value: true as Bool)
|
||||
])
|
||||
])
|
||||
|
||||
statusItem = NSStatusBar.system().statusItem(withLength: 20)
|
||||
statusItem = NSStatusBar.system().statusItem(withLength: AppDelegate.StatusItemIconWidth)
|
||||
let image = NSImage(named: "menu_icon")
|
||||
image?.isTemplate = true
|
||||
statusItem.image = image
|
||||
@ -73,13 +76,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
let notifyCenter = NotificationCenter.default
|
||||
notifyCenter.addObserver(forName: NSNotification.Name(rawValue: NOTIFY_ADV_PROXY_CONF_CHANGED), object: nil, queue: nil
|
||||
, using: {
|
||||
(note) in
|
||||
(note) in
|
||||
self.applyConfig()
|
||||
}
|
||||
)
|
||||
notifyCenter.addObserver(forName: NSNotification.Name(rawValue: NOTIFY_SERVER_PROFILES_CHANGED), object: nil, queue: nil
|
||||
, using: {
|
||||
(note) in
|
||||
(note) in
|
||||
let profileMgr = ServerProfileManager.instance
|
||||
if profileMgr.activeProfileId == nil &&
|
||||
profileMgr.profiles.count > 0{
|
||||
@ -93,7 +96,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
)
|
||||
notifyCenter.addObserver(forName: NSNotification.Name(rawValue: NOTIFY_ADV_CONF_CHANGED), object: nil, queue: nil
|
||||
, using: {
|
||||
(note) in
|
||||
(note) in
|
||||
SyncSSLocal()
|
||||
self.applyConfig()
|
||||
}
|
||||
@ -151,7 +154,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
applyConfig()
|
||||
SyncSSLocal()
|
||||
}
|
||||
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
// Insert code here to tear down your application
|
||||
StopSSLocal()
|
||||
@ -191,7 +194,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
|
||||
applyConfig()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func updateGFWList(_ sender: NSMenuItem) {
|
||||
UpdatePACFromGFWList()
|
||||
}
|
||||
@ -202,7 +205,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
}
|
||||
let ctrl = UserRulesController(windowNibName: "UserRulesController")
|
||||
editUserRulesWinCtrl = ctrl
|
||||
|
||||
|
||||
ctrl.showWindow(self)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
ctrl.window?.makeKeyAndOrderFront(self)
|
||||
@ -240,7 +243,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
@IBAction func scanQRCodeFromScreen(_ sender: NSMenuItem) {
|
||||
ScanQRCodeOnScreen()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func toggleLaunghAtLogin(_ sender: NSMenuItem) {
|
||||
launchAtLoginController.launchAtLogin = !launchAtLoginController.launchAtLogin;
|
||||
updateLaunchAtLoginMenu()
|
||||
@ -331,6 +334,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
|
||||
@IBAction func showRunningMode(_ sender: NSMenuItem) {
|
||||
sender.state = sender.state == 1 ? 0 : 1
|
||||
let defaults = UserDefaults.standard
|
||||
let isShown = (sender.state == 1)
|
||||
defaults.set(isShown, forKey: "ShowRunningModeOnStatusBar")
|
||||
updateStatusItemUI(isShownnRunningMode: isShown)
|
||||
}
|
||||
|
||||
func updateLaunchAtLoginMenu() {
|
||||
if launchAtLoginController.launchAtLogin {
|
||||
lanchAtLoginMenuItem.state = 1
|
||||
@ -342,7 +353,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
func updateRunningModeMenu() {
|
||||
let defaults = UserDefaults.standard
|
||||
let mode = defaults.string(forKey: "ShadowsocksRunningMode")
|
||||
|
||||
|
||||
showRunningModeMenuItem.title = "Show Running Mode On Status Bar".localized
|
||||
showRunningModeMenuItem.state = defaults.bool(forKey: "ShowRunningModeOnStatusBar") ? 1 : 0
|
||||
|
||||
var serverMenuText = "Servers".localized
|
||||
for v in defaults.array(forKey: "ServerProfiles")! {
|
||||
let profile = v as! [String:Any]
|
||||
@ -357,7 +371,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
}
|
||||
}
|
||||
serversMenuItem.title = serverMenuText
|
||||
|
||||
|
||||
if mode == "auto" {
|
||||
proxyMenuItem.title = "Proxy - Auto By PAC".localized
|
||||
autoModeMenuItem.state = 1
|
||||
@ -374,22 +388,27 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
globalModeMenuItem.state = 0
|
||||
manualModeMenuItem.state = 1
|
||||
}
|
||||
updateStatusItemUI()
|
||||
let isShown = defaults.bool(forKey: "ShowRunningModeOnStatusBar")
|
||||
updateStatusItemUI(isShownnRunningMode: isShown)
|
||||
}
|
||||
|
||||
func updateStatusItemUI() {
|
||||
let defaults = UserDefaults.standard
|
||||
let mode = defaults.string(forKey: "ShadowsocksRunningMode")
|
||||
if mode == "auto" {
|
||||
statusItem.title = "Auto".localized
|
||||
} else if mode == "global" {
|
||||
statusItem.title = "Global".localized
|
||||
} else if mode == "manual" {
|
||||
statusItem.title = "Manual".localized
|
||||
func updateStatusItemUI(isShownnRunningMode: Bool) {
|
||||
if isShownnRunningMode {
|
||||
let defaults = UserDefaults.standard
|
||||
let mode = defaults.string(forKey: "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!.size(withAttributes: [NSFontAttributeName: statusItem.button!.font!]).width
|
||||
let imageWidth:CGFloat = AppDelegate.StatusItemIconWidth
|
||||
statusItem.length = titleWidth + imageWidth + 2
|
||||
} else {
|
||||
statusItem.length = AppDelegate.StatusItemIconWidth
|
||||
}
|
||||
let titleWidth = statusItem.title!.size(withAttributes: [NSFontAttributeName: statusItem.button!.font!]).width
|
||||
let imageWidth:CGFloat = 22
|
||||
statusItem.length = titleWidth + imageWidth
|
||||
}
|
||||
|
||||
func updateMainMenu() {
|
||||
@ -452,7 +471,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
, userInfo: [
|
||||
"ruls": [url],
|
||||
"source": "url",
|
||||
])
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
ShadowsocksX-NG/Base.lproj/Localizable.strings
Normal file → Executable file
8
ShadowsocksX-NG/Base.lproj/Localizable.strings
Normal file → Executable file
@ -47,3 +47,11 @@
|
||||
"Proxy - Manual" = "Proxy - Manual";
|
||||
|
||||
"Servers" = "Servers";
|
||||
|
||||
"Auto" = "PAC";
|
||||
|
||||
"Global" = "Global";
|
||||
|
||||
"Manual" = "Manual";
|
||||
|
||||
"Show Running Mode On Status Bar" = "Show Running Mode On Status Bar";
|
||||
|
15
ShadowsocksX-NG/Base.lproj/MainMenu.xib
Normal file → Executable file
15
ShadowsocksX-NG/Base.lproj/MainMenu.xib
Normal file → Executable file
@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
@ -24,6 +25,7 @@
|
||||
<outlet property="serversMenuItem" destination="u5M-hQ-VSc" id="8gp-SY-Y4U"/>
|
||||
<outlet property="serversPreferencesMenuItem" destination="M5r-E7-44f" id="voe-SX-k6a"/>
|
||||
<outlet property="showQRCodeMenuItem" destination="R6A-96-Zcb" id="XHz-pz-nCz"/>
|
||||
<outlet property="showRunningModeMenuItem" destination="CCV-hX-fVA" id="AU2-hH-w8F"/>
|
||||
<outlet property="statusMenu" destination="Hob-KD-bx9" id="clA-ZW-0pT"/>
|
||||
<outlet property="toggleRunningMenuItem" destination="GSu-Tf-StS" id="XHw-pU-nCa"/>
|
||||
</connections>
|
||||
@ -77,6 +79,12 @@
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="bMX-qn-Qwi"/>
|
||||
<menuItem title="Show Running Mode On Status Bar" id="CCV-hX-fVA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="showRunningMode:" target="Voe-Tx-rLC" id="PxO-ut-PEx"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Advance Proxy Preference..." id="sbx-yz-3lO">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
@ -150,6 +158,7 @@
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
<point key="canvasLocation" x="22" y="89"/>
|
||||
</menu>
|
||||
</objects>
|
||||
</document>
|
||||
|
8
ShadowsocksX-NG/zh-Hans.lproj/Localizable.strings
Normal file → Executable file
8
ShadowsocksX-NG/zh-Hans.lproj/Localizable.strings
Normal file → Executable file
@ -51,3 +51,11 @@
|
||||
"Proxy - Manual" = "代理 - 手动";
|
||||
|
||||
"Servers" = "服务器";
|
||||
|
||||
"Auto" = "自动";
|
||||
|
||||
"Global" = "全局";
|
||||
|
||||
"Manual" = "手动";
|
||||
|
||||
"Show Running Mode On Status Bar" = "在状态栏显示运行模式";
|
||||
|
Reference in New Issue
Block a user