diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0d721385d..3a84a5392 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,14 +9,18 @@ on: jobs: build: - runs-on: macos-13 + runs-on: macos-14 steps: + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + - 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 +97,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 }} 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 }