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