Refactor launch agent utils.
This commit is contained in:
@ -201,8 +201,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
|
||||
ProxyConfHelper.install()
|
||||
ProxyConfHelper.startMonitorPAC()
|
||||
applyConfig()
|
||||
SyncSSLocal()
|
||||
applyConfig()
|
||||
|
||||
// Register global hotkey
|
||||
registerHotkey()
|
||||
@ -211,6 +211,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
// Insert code here to tear down your application
|
||||
StopSSLocal()
|
||||
StopKcptun()
|
||||
StopPrivoxy()
|
||||
ProxyConfHelper.disableProxy()
|
||||
if let ref = hotKeyRef { UnregisterEventHotKey(ref) }
|
||||
@ -223,6 +224,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
|
||||
if isOn {
|
||||
StartSSLocal()
|
||||
StartKcptun()
|
||||
StartPrivoxy()
|
||||
if mode == "auto" {
|
||||
ProxyConfHelper.enablePACProxy()
|
||||
@ -233,6 +235,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
}
|
||||
} else {
|
||||
StopSSLocal()
|
||||
StopKcptun()
|
||||
StopPrivoxy()
|
||||
ProxyConfHelper.disableProxy()
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<string>2</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
@ -75,18 +75,6 @@ func generateSSLocalLauchAgentPlist() -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
func ReloadConfSSLocal() {
|
||||
let bundle = Bundle.main
|
||||
let installerPath = bundle.path(forResource: "reload_conf_ss_local.sh", ofType: nil)
|
||||
let task = Process.launchedProcess(launchPath: installerPath!, arguments: [""])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("Start ss-local succeeded.")
|
||||
} else {
|
||||
NSLog("Start ss-local failed.")
|
||||
}
|
||||
}
|
||||
|
||||
func StartSSLocal() {
|
||||
let bundle = Bundle.main
|
||||
let installerPath = bundle.path(forResource: "start_ss_local.sh", ofType: nil)
|
||||
@ -168,8 +156,8 @@ func SyncSSLocal() {
|
||||
|
||||
let on = UserDefaults.standard.bool(forKey: "ShadowsocksOn")
|
||||
if on {
|
||||
StopSSLocal()
|
||||
StartSSLocal()
|
||||
ReloadConfSSLocal()
|
||||
}
|
||||
} else {
|
||||
removeSSLocalConfFile()
|
||||
@ -217,19 +205,6 @@ func generatePrivoxyLauchAgentPlist() -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func ReloadConfPrivoxy() {
|
||||
let bundle = Bundle.main
|
||||
let installerPath = bundle.path(forResource: "reload_conf_privoxy.sh", ofType: nil)
|
||||
let task = Process.launchedProcess(launchPath: installerPath!, arguments: [""])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("reload privoxy succeeded.")
|
||||
} else {
|
||||
NSLog("reload privoxy failed.")
|
||||
}
|
||||
}
|
||||
|
||||
func StartPrivoxy() {
|
||||
let bundle = Bundle.main
|
||||
let installerPath = bundle.path(forResource: "start_privoxy.sh", ofType: nil)
|
||||
@ -316,8 +291,8 @@ func SyncPrivoxy() {
|
||||
|
||||
let on = UserDefaults.standard.bool(forKey: "LocalHTTPOn")
|
||||
if on {
|
||||
// StartPrivoxy()
|
||||
ReloadConfPrivoxy()
|
||||
StopPrivoxy()
|
||||
StartPrivoxy()
|
||||
}
|
||||
else {
|
||||
removePrivoxyConfFile()
|
||||
@ -401,6 +376,14 @@ func writeKcptunConfFile(_ conf:[String:AnyObject]) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func isEnabledKcptun() -> Bool {
|
||||
let mgr = ServerProfileManager.instance
|
||||
if let profile = mgr.getActiveProfile() {
|
||||
return profile.enabledKcptun
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func removeKcptunConfFile() {
|
||||
do {
|
||||
let filepath = NSHomeDirectory() + APP_SUPPORT_DIR + "kcptun-config.json"
|
||||
@ -410,28 +393,17 @@ func removeKcptunConfFile() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func ReloadConfKcptun() {
|
||||
let bundle = Bundle.main
|
||||
let installerPath = bundle.path(forResource: "reload_conf_kcptun.sh", ofType: nil)
|
||||
let task = Process.launchedProcess(launchPath: installerPath!, arguments: [""])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("Start kcptun succeeded.")
|
||||
} else {
|
||||
NSLog("Start kcptun failed.")
|
||||
}
|
||||
}
|
||||
|
||||
func StartKcptun() {
|
||||
let bundle = Bundle.main
|
||||
let installerPath = bundle.path(forResource: "start_kcptun.sh", ofType: nil)
|
||||
let task = Process.launchedProcess(launchPath: installerPath!, arguments: [""])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("Start kcptun succeeded.")
|
||||
} else {
|
||||
NSLog("Start kcptun failed.")
|
||||
if isEnabledKcptun() {
|
||||
let bundle = Bundle.main
|
||||
let installerPath = bundle.path(forResource: "start_kcptun.sh", ofType: nil)
|
||||
let task = Process.launchedProcess(launchPath: installerPath!, arguments: [""])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("Start kcptun succeeded.")
|
||||
} else {
|
||||
NSLog("Start kcptun failed.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,8 +429,8 @@ func SyncKcptun() {
|
||||
|
||||
let on = UserDefaults.standard.bool(forKey: "ShadowsocksOn")
|
||||
if on {
|
||||
StopKcptun()
|
||||
StartKcptun()
|
||||
ReloadConfKcptun()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# reload_conf_kcptun.sh
|
||||
# ShadowsocksX-NG
|
||||
#
|
||||
# Created by 邱宇舟 on 2017/1/11.
|
||||
# Copyright © 2017年 qiuyuzhou. All rights reserved.
|
||||
|
||||
launchctl unload "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.kcptun.plist"
|
||||
launchctl load "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.kcptun.plist"
|
@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# reload_privoxy.sh
|
||||
# ShadowsocksX-NG
|
||||
#
|
||||
# Created by 王晨 on 16/10/7.
|
||||
# Copyright © 2016年 zhfish. All rights reserved.
|
||||
|
||||
#launchctl kill SIGHUP "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.http.plist"
|
||||
|
||||
launchctl unload "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.http.plist"
|
||||
launchctl load "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.http.plist"
|
@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# reload_conf_ss_local.sh
|
||||
# ShadowsocksX-NG
|
||||
#
|
||||
# Created by 邱宇舟 on 16/6/6.
|
||||
# Copyright © 2016年 qiuyuzhou. All rights reserved.
|
||||
|
||||
#launchctl kill SIGHUP "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.local.plist"
|
||||
|
||||
launchctl unload "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.local.plist"
|
||||
launchctl load "$HOME/Library/LaunchAgents/com.qiuyuzhou.shadowsocksX-NG.local.plist"
|
Reference in New Issue
Block a user