Skip to content

Commit 64e8584

Browse files
committed
misc: flushSystemDnsCache
(cherry picked from commit b27e11f)
1 parent 8b882ff commit 64e8584

7 files changed

Lines changed: 88 additions & 77 deletions

File tree

ClashX/AppDelegate.swift

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -860,28 +860,9 @@ extension AppDelegate {
860860
}
861861
}
862862

863-
@IBAction func flushFakeipCache(_ sender: NSMenuItem) {
864-
let group = DispatchGroup()
865-
866-
var flushFakeipCacheResult = false
867-
var flushDNSCacheResult = false
868-
869-
group.enter()
870-
ApiRequest.flushFakeipCache {
871-
flushFakeipCacheResult = $0
872-
group.leave()
873-
}
874-
875-
group.enter()
876-
ApiRequest.flushDNSCache {
877-
flushDNSCacheResult = $0
878-
group.leave()
879-
}
880-
881-
group.notify(queue: .main) {
882-
let info = (flushFakeipCacheResult && flushDNSCacheResult) ? "Success" : "Failed"
883-
UserNotificationCenter.shared.post(title: NSLocalizedString("Flush dns cache", comment: ""), info: info)
884-
}
863+
@IBAction func flushDNSCache(_ sender: NSMenuItem) {
864+
ApiRequest.flushDNSCache()
865+
PrivilegedHelperManager.shared.helper()?.flushDnsCache()
885866
}
886867

887868
@IBAction func updateSniffing(_ sender: NSMenuItem) {

ClashX/Base.lproj/Main.storyboard

Lines changed: 48 additions & 49 deletions
Large diffs are not rendered by default.

ClashX/Dashboard/Views/ContentTabs/Config/ConfigView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ struct ConfigView: View {
242242

243243
ConfigItemView(name: "FakeIP") {
244244
Button {
245-
ApiRequest.flushFakeipCache()
246-
ApiRequest.flushDNSCache()
245+
AppDelegate.shared.flushDNSCache(NSMenuItem())
247246
} label: {
248247
Text("Flush dns cache")
249248
}

ClashX/General/ApiRequest.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,32 @@ extension ApiRequest {
488488
completeHandler?()
489489
}
490490
}
491+
492+
static func flushDNSCache() {
493+
let group = DispatchGroup()
494+
495+
var flushFakeipCacheResult = false
496+
var flushDNSCacheResult = false
497+
498+
group.enter()
499+
ApiRequest.flushFakeipCache {
500+
flushFakeipCacheResult = $0
501+
group.leave()
502+
}
503+
504+
group.enter()
505+
ApiRequest.flushDNSCache {
506+
flushDNSCacheResult = $0
507+
group.leave()
508+
}
509+
510+
group.notify(queue: .main) {
511+
let info = (flushFakeipCacheResult && flushDNSCacheResult) ? "Success" : "Failed"
512+
UserNotificationCenter.shared.post(title: NSLocalizedString("Flush dns cache", comment: ""), info: info)
513+
}
514+
}
491515

492-
static func flushFakeipCache(completeHandler: ((Bool) -> Void)? = nil) {
516+
private static func flushFakeipCache(completeHandler: ((Bool) -> Void)? = nil) {
493517
Logger.log("FlushFakeipCache")
494518
req("/cache/fakeip/flush",
495519
method: .post).response {
@@ -499,7 +523,7 @@ extension ApiRequest {
499523
}
500524
}
501525

502-
static func flushDNSCache(completeHandler: ((Bool) -> Void)? = nil) {
526+
private static func flushDNSCache(completeHandler: ((Bool) -> Void)? = nil) {
503527
Logger.log("FlushDNSCache")
504528
req("/cache/dns/flush",
505529
method: .post).response {

ProxyConfigHelper/Helper-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<key>CFBundleName</key>
1010
<string>com.metacubex.ClashX.ProxyConfigHelper</string>
1111
<key>CFBundleShortVersionString</key>
12-
<string>1.14</string>
12+
<string>1.15</string>
1313
<key>CFBundleVersion</key>
14-
<string>24</string>
14+
<string>25</string>
1515
<key>SMAuthorizedClients</key>
1616
<array>
1717
<string>anchor apple generic and identifier &quot;com.metacubex.ClashX.ProxyConfigHelper&quot; and (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = MEWHFZ92DY)</string>

ProxyConfigHelper/ProxyConfigHelper.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,11 @@ extension ProxyConfigHelper: ProxyConfigRemoteProcessProtocol {
143143
self.metaDNS.flushDnsCache()
144144
}
145145
}
146+
147+
func flushDnsCache() {
148+
DispatchQueue.main.async {
149+
self.metaDNS.flushDnsCache()
150+
}
151+
}
152+
146153
}

ProxyConfigHelper/ProxyConfigRemoteProcessProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ protocol ProxyConfigRemoteProcessProtocol {
1616
func updateTun(state: Bool, dns: String)
1717
func getUsedPorts(reply: @escaping (String?) -> Void)
1818

19+
func flushDnsCache()
1920

2021
func enableProxy(port: Int, socksPort: Int, pac: String?, filterInterface: Bool, ignoreList: [String], reply: @escaping (String?) -> Void)
2122
func disableProxy(filterInterface: Bool, reply: @escaping (String?) -> Void)

0 commit comments

Comments
 (0)