From 43c1e8bfddb5191c01e53a4cca4f76518bef610d Mon Sep 17 00:00:00 2001 From: yicheng <11733500+yichengchen@users.noreply.github.com> Date: Sat, 22 Feb 2020 11:59:52 +0800 Subject: [PATCH] chore(menu):add disableRestoreProxy experiment menu item --- ClashX/AppDelegate.swift | 3 ++- .../General/Managers/SystemProxyManager.swift | 18 ++++++++++++++++++ .../Support Files/en.lproj/Localizable.strings | 3 +++ .../zh-Hans.lproj/Localizable.strings | 3 +++ README.md | 6 ------ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ClashX/AppDelegate.swift b/ClashX/AppDelegate.swift index 55ce96c..894d196 100644 --- a/ClashX/AppDelegate.swift +++ b/ClashX/AppDelegate.swift @@ -216,7 +216,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { guard NetworkChangeNotifier.getPrimaryInterface() != nil else { return } let proxySetted = NetworkChangeNotifier.isCurrentSystemSetToClash() ConfigManager.shared.isProxySetByOtherVariable.accept(!proxySetted) - if !proxySetted { + if !proxySetted && ConfigManager.shared.proxyPortAutoSet { let proxiesSetting = NetworkChangeNotifier.getRawProxySetting() Logger.log("Proxy changed by other process!, current:\(proxiesSetting)", level: .warning) } @@ -366,6 +366,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { AutoUpgardeManager.shared.setup() AutoUpgardeManager.shared.addChanelMenuItem(&experimentalMenu) ClashResourceManager.addUpdateMMDBMenuItem(&experimentalMenu) + SystemProxyManager.shared.addDisableRestoreProxyMenuItem(&experimentalMenu) if WebPortalManager.hasWebProtal { WebPortalManager.shared.addWebProtalMenuItem(&statusMenu) } diff --git a/ClashX/General/Managers/SystemProxyManager.swift b/ClashX/General/Managers/SystemProxyManager.swift index b82f7ca..abe597a 100644 --- a/ClashX/General/Managers/SystemProxyManager.swift +++ b/ClashX/General/Managers/SystemProxyManager.swift @@ -112,6 +112,24 @@ class SystemProxyManager: NSObject { }) } + // MARK: - Expriment Menu Items + + func addDisableRestoreProxyMenuItem(_ menu: inout NSMenu) { + let item = NSMenuItem(title: NSLocalizedString("Disable Restore Proxy Setting", comment: ""), action: #selector(optionMenuItemTap(sender:)), keyEquivalent: "") + item.target = self + menu.addItem(item) + updateMenuItemStatus(item) + } + + func updateMenuItemStatus(_ item: NSMenuItem) { + item.state = disableRestoreProxy ? .on : .off + } + + @objc func optionMenuItemTap(sender: NSMenuItem) { + disableRestoreProxy = !disableRestoreProxy + updateMenuItemStatus(sender) + } + // MARK: - Private private func initAuthorizationRef() { diff --git a/ClashX/Support Files/en.lproj/Localizable.strings b/ClashX/Support Files/en.lproj/Localizable.strings index ff85d74..834cc75 100644 --- a/ClashX/Support Files/en.lproj/Localizable.strings +++ b/ClashX/Support Files/en.lproj/Localizable.strings @@ -41,6 +41,9 @@ /* No comment provided by engineer. */ "Direct" = "Direct"; +/* No comment provided by engineer. */ +"Disable Restore Proxy Setting" = "Disable Restore Proxy Setting"; + /* No comment provided by engineer. */ "Download fail" = "Download fail"; diff --git a/ClashX/Support Files/zh-Hans.lproj/Localizable.strings b/ClashX/Support Files/zh-Hans.lproj/Localizable.strings index c35cf12..91e3755 100644 --- a/ClashX/Support Files/zh-Hans.lproj/Localizable.strings +++ b/ClashX/Support Files/zh-Hans.lproj/Localizable.strings @@ -41,6 +41,9 @@ /* No comment provided by engineer. */ "Direct" = "直连"; +/* No comment provided by engineer. */ +"Disable Restore Proxy Setting" = "关闭自动还原之前代理"; + /* No comment provided by engineer. */ "Download fail" = "下载失败"; diff --git a/README.md b/README.md index 664e7b7..f91f7f6 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,6 @@ Checkout [Clash](https://github.com/Dreamacro/clash) or [SS-Rule-Snippet for Cla Place your icon file in the `~/.config/clash/menuImage.png` then restart ClashX -### Disable auto restore proxy setting. - - ``` - defaults write com.west2online.ClashX kDisableRestoreProxy -bool true - ``` - ### Change default system ignore list. - Download sample plist in the [Here](proxyIgnoreList.plist) and place in the