diff --git a/ClashX/General/Utils/ClashStatusTool.swift b/ClashX/General/Utils/ClashStatusTool.swift index fb73a96..e651f38 100644 --- a/ClashX/General/Utils/ClashStatusTool.swift +++ b/ClashX/General/Utils/ClashStatusTool.swift @@ -11,8 +11,8 @@ import Cocoa class ClashStatusTool { static func checkPortConfig(cfg: ClashConfig?) { guard let cfg = cfg else { return } - Logger.log("checkPortConfig: \(cfg.port) \(cfg.socketPort)", level: .debug) if cfg.port == 0 || cfg.socketPort == 0 { + Logger.log("checkPortConfig: \(cfg.port) \(cfg.socketPort)", level: .error) let alert = NSAlert() alert.messageText = NSLocalizedString("ClashX Start Error!", comment: "") alert.informativeText = NSLocalizedString("Ports Open Fail, Please try to restart ClashX", comment: "") diff --git a/ClashX/General/Utils/NetworkChangeNotifier.swift b/ClashX/General/Utils/NetworkChangeNotifier.swift index 2f4d6a4..a6a92ff 100644 --- a/ClashX/General/Utils/NetworkChangeNotifier.swift +++ b/ClashX/General/Utils/NetworkChangeNotifier.swift @@ -59,6 +59,7 @@ class NetworkChangeNotifier { } @objc static func onWakeNote(note: NSNotification) { + NotificationCenter.default.post(name: .systemNetworkStatusIPUpdate, object: nil) DispatchQueue.main.asyncAfter(deadline: .now() + 1) { @@ -88,19 +89,26 @@ class NetworkChangeNotifier { } static func getPrimaryInterface() -> String? { - let key: CFString - let store: SCDynamicStore? - let dict: [String: String]? - - store = SCDynamicStoreCreate(nil, "ClashX" as CFString, nil, nil) + let store = SCDynamicStoreCreate(nil, "ClashX" as CFString, nil, nil) if store == nil { return nil } - key = SCDynamicStoreKeyCreateNetworkGlobalEntity(nil, kSCDynamicStoreDomainState, kSCEntNetIPv4) - dict = SCDynamicStoreCopyValue(store, key) as? [String: String] + let key = SCDynamicStoreKeyCreateNetworkGlobalEntity(nil, kSCDynamicStoreDomainState, kSCEntNetIPv4) + let dict = SCDynamicStoreCopyValue(store, key) as? [String: String] return dict?[kSCDynamicStorePropNetPrimaryInterface as String] } + + static func getCurrentDns() -> [String] { + let store = SCDynamicStoreCreate(nil, "ClashX" as CFString, nil, nil) + if store == nil { + return [] + } + + let key = SCDynamicStoreKeyCreateNetworkGlobalEntity(nil, kSCDynamicStoreDomainState, kSCEntNetDNS) + let dnsArr = SCDynamicStoreCopyValue(store, key) as? [String:[String]] + return dnsArr?[kSCPropNetDNSServerAddresses as String] ?? [] + } static func getPrimaryIPAddress(allowIPV6: Bool = false) -> String? { guard let primary = getPrimaryInterface() else {