chore: allow mutilple clashx running

This commit is contained in:
yicheng 2020-12-18 20:16:53 +08:00
parent d3bde38343
commit e5080ee5b4
No known key found for this signature in database
GPG Key ID: 7CF411A6623B1C0A
3 changed files with 11 additions and 15 deletions

View File

@ -61,7 +61,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillFinishLaunching(_ notification: Notification) {
signal(SIGPIPE, SIG_IGN)
checkOnlyOneClashX()
// crash recorder
failLaunchProtect()
registCrashLogger()
@ -286,6 +285,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
PrivilegedHelperManager.shared.isHelperCheckFinished
.filter({$0})
.take(1)
.observeOn(MainScheduler.instance)
.subscribe { [weak self] _ in
guard let self = self else { return }
self.proxySettingMenuItem.target = self
@ -293,15 +293,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}
func checkOnlyOneClashX() {
let runningCount = NSRunningApplication.runningApplications(withBundleIdentifier: Bundle.main.bundleIdentifier ?? "").count
if runningCount > 1 {
Logger.log("running count => \(runningCount), exit")
assertionFailure()
NSApp.terminate(nil)
}
}
func setupNetworkNotifier() {
NetworkChangeNotifier.start()

View File

@ -19,11 +19,14 @@ class ClashStatusTool {
alert.informativeText = NSLocalizedString("Ports Open Fail, Please try to restart ClashX", comment: "")
alert.addButton(withTitle: NSLocalizedString("Quit", comment: ""))
alert.addButton(withTitle: "Edit Config")
let ret = alert.runModal()
if ret == .alertSecondButtonReturn {
NSWorkspace.shared.openFile(Paths.localConfigPath(for: "config"))
DispatchQueue.main.async {
let ret = alert.runModal()
if ret == .alertSecondButtonReturn {
NSWorkspace.shared.openFile(Paths.localConfigPath(for: "config"))
}
NSApp.terminate(nil)
}
NSApp.terminate(nil)
}
}
}

View File

@ -82,7 +82,9 @@ class NetworkChangeNotifier {
let (http, https, socks) = NetworkChangeNotifier.currentSystemProxySetting()
let currentPort = ConfigManager.shared.currentConfig?.usedHttpPort ?? 0
let currentSocks = ConfigManager.shared.currentConfig?.usedSocksPort ?? 0
if currentPort == currentSocks, currentPort == 0 {
return false
}
if looser {
return http == currentPort || https == currentPort || socks == currentSocks
} else {