feat: support remove helper
This commit is contained in:
parent
d4a5c58a1b
commit
08f2b1120c
@ -55,12 +55,8 @@ extension PrivilegedHelperManager {
|
||||
return bash
|
||||
}
|
||||
|
||||
func legacyInstallHelper() {
|
||||
defer {
|
||||
resetConnection()
|
||||
Thread.sleep(forTimeInterval: 1)
|
||||
}
|
||||
let script = getInstallScript()
|
||||
|
||||
func runScriptWithRootPermission(script: String) {
|
||||
let tmpPath = FileManager.default.temporaryDirectory.appendingPathComponent(NSUUID().uuidString).appendingPathExtension("sh")
|
||||
do {
|
||||
try script.write(to: tmpPath, atomically: true, encoding: .utf8)
|
||||
@ -77,4 +73,26 @@ extension PrivilegedHelperManager {
|
||||
}
|
||||
try? FileManager.default.removeItem(at: tmpPath)
|
||||
}
|
||||
|
||||
func legacyInstallHelper() {
|
||||
defer {
|
||||
resetConnection()
|
||||
Thread.sleep(forTimeInterval: 1)
|
||||
}
|
||||
let script = getInstallScript()
|
||||
runScriptWithRootPermission(script: script)
|
||||
}
|
||||
|
||||
|
||||
func removeInstallHelper() {
|
||||
defer {
|
||||
resetConnection()
|
||||
Thread.sleep(forTimeInterval: 1)
|
||||
}
|
||||
let script = """
|
||||
rm -rf /Library/LaunchDaemons/\(PrivilegedHelperManager.machServiceName).plist
|
||||
rm -rf /Library/PrivilegedHelperTools/\(PrivilegedHelperManager.machServiceName)
|
||||
"""
|
||||
runScriptWithRootPermission(script: script)
|
||||
}
|
||||
}
|
||||
|
@ -36,10 +36,16 @@ class PrivilegedHelperManager {
|
||||
let status = SMAppService.statusForLegacyPlist(at: url)
|
||||
if status == .requiresApproval {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = NSLocalizedString("ClashX use a daemon helper to setup your system proxy. Please enable ClashX in the Login Items under the Allow in the Background section and relaunch the app", comment: "")
|
||||
let notice = NSLocalizedString("ClashX use a daemon helper to setup your system proxy. Please enable ClashX in the Login Items under the Allow in the Background section and relaunch the app", comment: "")
|
||||
let addition = NSLocalizedString("If you can not find ClashX in the settings, you can try reset daemon", comment: "")
|
||||
alert.messageText = notice + "\n" + addition
|
||||
alert.addButton(withTitle: NSLocalizedString("Open System Login Item Setting", comment: ""))
|
||||
alert.runModal()
|
||||
alert.addButton(withTitle: NSLocalizedString("Reset Daemon", comment: ""))
|
||||
if alert.runModal() == .alertFirstButtonReturn {
|
||||
SMAppService.openSystemSettingsLoginItems()
|
||||
} else {
|
||||
removeInstallHelper()
|
||||
}
|
||||
}
|
||||
}
|
||||
getHelperStatus { [weak self] status in
|
||||
|
@ -76,6 +76,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"hours" = "hours";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"If you can not find ClashX in the settings, you can try reset daemon" = "If you can not find ClashX in the settings, you can try reset daemon";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Install" = "Install";
|
||||
|
||||
@ -135,6 +138,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"Remote Config Update Fail" = "Remote Config Update Fail";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Reset Daemon" = "Reset Daemon";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"ReTest" = "ReTest";
|
||||
|
||||
|
@ -76,6 +76,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"hours" = "小时";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"If you can not find ClashX in the settings, you can try reset daemon" = "如果在设置里没找到ClashX,可以尝试重置守护程序";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Install" = "安装";
|
||||
|
||||
@ -135,6 +138,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"Remote Config Update Fail" = "托管配置文件更新失败";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Reset Daemon" = "重置守护程序";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"ReTest" = "重新测速";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user