From a4f051ab6715c38e645ab2771a732d56cf3c8e84 Mon Sep 17 00:00:00 2001 From: mrFq1 <1xxbx0il0@mozmail.com> Date: Tue, 23 Apr 2024 15:48:06 +0800 Subject: [PATCH 1/3] chore: ci --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0d721385d..dd8bd9a5e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,14 +9,14 @@ on: jobs: build: - runs-on: macos-13 + runs-on: macos-14 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: download meta core - uses: robinraju/release-downloader@v1.9 + uses: robinraju/release-downloader@v1.10 with: repository: 'MetaCubeX/mihomo' tag: "v1.18.3" @@ -93,7 +93,7 @@ jobs: path: "*.zip" - name: upload build to github - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a55f1c328ef2b0795358cb303a00e28b3512360b Mon Sep 17 00:00:00 2001 From: mrFq1 <1xxbx0il0@mozmail.com> Date: Tue, 23 Apr 2024 16:02:18 +0800 Subject: [PATCH 2/3] chore: ci xcode --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd8bd9a5e..3a84a5392 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,6 +11,10 @@ jobs: build: runs-on: macos-14 steps: + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + - uses: actions/checkout@v4 with: fetch-depth: 0 From 988c0cf70dcbd5cb5a85c799847116a9423c5776 Mon Sep 17 00:00:00 2001 From: mrFq1 <1xxbx0il0@mozmail.com> Date: Tue, 23 Apr 2024 21:22:29 +0800 Subject: [PATCH 3/3] feat: restore proxy --- ClashX/Actions/TerminalCleanUpAction.swift | 7 ++++- ClashX/AppDelegate.swift | 31 ++++++++++----------- ClashX/General/Managers/ConfigManager.swift | 18 ++++++++++++ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/ClashX/Actions/TerminalCleanUpAction.swift b/ClashX/Actions/TerminalCleanUpAction.swift index 6f71ba450..8ffefba91 100644 --- a/ClashX/Actions/TerminalCleanUpAction.swift +++ b/ClashX/Actions/TerminalCleanUpAction.swift @@ -17,6 +17,8 @@ enum TerminalConfirmAction { } let group = DispatchGroup() var shouldWait = false + + ConfigManager.shared.restoreTunProxy = ConfigManager.shared.isTunModeVariable.value PrivilegedHelperManager.shared.helper()?.stopMeta() PrivilegedHelperManager.shared.helper()?.updateTun(state: false) @@ -27,13 +29,16 @@ enum TerminalConfirmAction { if ConfigManager.shared.proxyPortAutoSet && !ConfigManager.shared.isProxySetByOtherVariable.value || NetworkChangeNotifier.isCurrentSystemSetToClash(looser: true) || NetworkChangeNotifier.hasInterfaceProxySetToClash() { Logger.log("ClashX quit need clean proxy setting") + ConfigManager.shared.restoreSystemProxy = true shouldWait = true group.enter() SystemProxyManager.shared.disableProxy(forceDisable: ConfigManager.shared.isProxySetByOtherVariable.value) { group.leave() } - } + } else { + ConfigManager.shared.restoreSystemProxy = false + } if !shouldWait { Logger.log("ClashX quit without clean waiting") diff --git a/ClashX/AppDelegate.swift b/ClashX/AppDelegate.swift index 515bab19e..91b77571c 100644 --- a/ClashX/AppDelegate.swift +++ b/ClashX/AppDelegate.swift @@ -205,7 +205,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func setupData() { - SSIDSuspendTool.shared.setup() ConfigManager.shared .showNetSpeedIndicatorObservable.skip(1) .bind { @@ -308,21 +307,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { startProxyCore() } - - if !PrivilegedHelperManager.shared.isHelperCheckFinished.value && - ConfigManager.shared.proxyPortAutoSet { - PrivilegedHelperManager.shared.isHelperCheckFinished - .filter { $0 } - .take(1) - .take(while: { _ in ConfigManager.shared.proxyPortAutoSet }) - .observe(on: MainScheduler.instance) - .bind(onNext: { _ in - SystemProxyManager.shared.enableProxy() - }).disposed(by: disposeBag) - } else if ConfigManager.shared.proxyPortAutoSet { - SystemProxyManager.shared.enableProxy() - } - LaunchAtLogin.shared .isEnableVirable .asObservable() @@ -588,7 +572,20 @@ extension AppDelegate: ClashProcessDelegate { } func clashConfigUpdated() { - syncConfigWithTun(true) + if ConfigManager.shared.restoreSystemProxy { + SystemProxyManager.shared.enableProxy() + } + + if ConfigManager.shared.restoreTunProxy { + ApiRequest.updateTun(enable: true) { + PrivilegedHelperManager.shared.helper()?.updateTun(state: true) + } + } else { + syncConfigWithTun(true) + } + + SSIDSuspendTool.shared.setup() + resetStreamApi() runAfterConfigReload?() runAfterConfigReload = nil diff --git a/ClashX/General/Managers/ConfigManager.swift b/ClashX/General/Managers/ConfigManager.swift index 64d738f98..a4f6217ab 100644 --- a/ClashX/General/Managers/ConfigManager.swift +++ b/ClashX/General/Managers/ConfigManager.swift @@ -74,6 +74,24 @@ class ConfigManager { UserDefaults.standard.set(newValue, forKey: "proxyPortAutoSet") } } + + var restoreSystemProxy: Bool { + get { + return UserDefaults.standard.bool(forKey: "restoreSystemProxy") + } + set { + UserDefaults.standard.set(newValue, forKey: "restoreSystemProxy") + } + } + + var restoreTunProxy: Bool { + get { + return UserDefaults.standard.bool(forKey: "restoreTunProxy") + } + set { + UserDefaults.standard.set(newValue, forKey: "restoreTunProxy") + } + } let proxyPortAutoSetObservable = UserDefaults.standard.rx.observe(Bool.self, "proxyPortAutoSet").map { $0 ?? false }