Merge branch 'pr/85' into develop

# Conflicts:
#	ShadowsocksX-NG/AppDelegate.swift
This commit is contained in:
Charlie Qiu
2016-10-14 23:39:11 +08:00
20 changed files with 542 additions and 11 deletions

View File

@ -17,6 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
var advPreferencesWinCtrl: AdvPreferencesWindowController!
var proxyPreferencesWinCtrl: ProxyPreferencesController!
var editUserRulesWinCtrl: UserRulesController!
var httpPreferencesWinCtrl : HTTPPreferencesWindowController!
var launchAtLoginController: LaunchAtLoginController = LaunchAtLoginController()
@ -49,7 +50,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
// Prepare ss-local
InstallSSLocal()
InstallPrivoxy()
// Prepare defaults
let defaults = UserDefaults.standard
defaults.register(defaults: [
@ -63,7 +64,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
"LocalSocks5.EnableUDPRelay": NSNumber(value: false as Bool),
"LocalSocks5.EnableVerboseMode": NSNumber(value: false as Bool),
"GFWListURL": "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt",
"AutoConfigureNetworkServices": NSNumber(value: true as Bool)
"AutoConfigureNetworkServices": NSNumber(value: true as Bool),
"LocalHTTP.ListenAddress": "127.0.0.1",
"LocalHTTP.ListenPort": NSNumber(value: 1087 as UInt16),
"LocalHTTPOn": true,
"LocalHTTP.FollowGlobel": true
])
statusItem = NSStatusBar.system().statusItem(withLength: AppDelegate.StatusItemIconWidth)
@ -101,6 +106,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
self.applyConfig()
}
)
notifyCenter.addObserver(forName: NSNotification.Name(rawValue: NOTIFY_HTTP_CONF_CHANGED), object: nil, queue: nil
, using: {
(note) in
SyncPrivoxy()
self.applyConfig()
}
)
notifyCenter.addObserver(forName: NSNotification.Name(rawValue: "NOTIFY_FOUND_SS_URL"), object: nil, queue: nil) {
(note: Notification) in
if let userInfo = (note as NSNotification).userInfo {
@ -158,6 +170,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
StopSSLocal()
StopPrivoxy()
ProxyConfHelper.disableProxy("hi")
let defaults = UserDefaults.standard
defaults.set(false, forKey: "ShadowsocksOn")
@ -171,6 +184,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
if isOn {
StartSSLocal()
StartPrivoxy()
if mode == "auto" {
ProxyConfHelper.enablePACProxy("hi")
} else if mode == "global" {
@ -180,6 +194,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
}
} else {
StopSSLocal()
StopPrivoxy()
ProxyConfHelper.disableProxy("hi")
}
}
@ -294,6 +309,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
ctrl.window?.makeKeyAndOrderFront(self)
}
@IBAction func editHTTPPreferences(_ sender: NSMenuItem) {
if httpPreferencesWinCtrl != nil {
httpPreferencesWinCtrl.close()
}
let ctrl = HTTPPreferencesWindowController(windowNibName: "HTTPPreferencesWindowController")
httpPreferencesWinCtrl = ctrl
ctrl.showWindow(self)
NSApp.activate(ignoringOtherApps: true)
ctrl.window?.makeKeyAndOrderFront(self)
}
@IBAction func editProxyPreferences(_ sender: NSObject) {
if proxyPreferencesWinCtrl != nil {
proxyPreferencesWinCtrl.close()