Feature: add description alert for getting privileges

This commit is contained in:
yicheng 2018-08-19 21:07:50 +08:00
parent 2e01a30612
commit 5393270a52

View File

@ -1,5 +1,7 @@
import Foundation
import AppKit
class ProxyConfigManager {
static let kProxyConfigFolder = (NSHomeDirectory() as NSString).appendingPathComponent("/.config/clash")
static let kVersion = "0.1.1"
@ -30,6 +32,10 @@ class ProxyConfigManager {
if !vaildHelper() {
if (!showInstallHelperAlert()) {
exit(0)
}
if (FileManager.default.fileExists(atPath: targetPath)) {
try? FileManager.default.removeItem(atPath: targetPath)
}
@ -38,6 +44,7 @@ class ProxyConfigManager {
let scriptPath = "\(Bundle.main.resourcePath!)/install_proxy_helper.sh"
let appleScriptStr = "do shell script \"bash \(scriptPath) \(kProxyConfigFolder) \" with administrator privileges"
let appleScript = NSAppleScript(source: appleScriptStr)
var dict: NSDictionary?
if let _ = appleScript?.executeAndReturnError(&dict) {
return true
@ -82,4 +89,18 @@ class ProxyConfigManager {
}
return true
}
static func showInstallHelperAlert() -> Bool{
let alert = NSAlert()
alert.messageText = """
ClashX needs to install a small tool to ~/.config/clash with administrator privileges to set system proxy quickly.
Otherwise you need to type in the administrator password every time you change system proxy through ClashX.
"""
alert.alertStyle = .warning
alert.addButton(withTitle: "Install")
alert.addButton(withTitle: "Quit")
return alert.runModal() == .alertFirstButtonReturn
}
}