From 5393270a52b6ceefb57e3dc0af1fb54cf7d258c2 Mon Sep 17 00:00:00 2001 From: yicheng Date: Sun, 19 Aug 2018 21:07:50 +0800 Subject: [PATCH] Feature: add description alert for getting privileges --- ClashX/Managers/ProxyConfigManager.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ClashX/Managers/ProxyConfigManager.swift b/ClashX/Managers/ProxyConfigManager.swift index fa2c120..88baace 100644 --- a/ClashX/Managers/ProxyConfigManager.swift +++ b/ClashX/Managers/ProxyConfigManager.swift @@ -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 + } + }