@@ -94,6 +94,17 @@ class ApiRequest {
9494 private var trafficWebSocketRetryTimer : Timer ?
9595 private var loggingWebSocketRetryTimer : Timer ?
9696 private var memoryWebSocketRetryTimer : Timer ?
97+
98+ private var logRateLimiter = LogRateLimiter {
99+ let alert = NSAlert ( )
100+ alert. messageText = NSLocalizedString ( " Log system crashed. " , comment: " " )
101+ alert. addButton ( withTitle: NSLocalizedString ( " Quit " , comment: " " ) )
102+ alert. addButton ( withTitle: NSLocalizedString ( " OK " , comment: " " ) )
103+ let response = alert. runModal ( )
104+ if response == . alertFirstButtonReturn {
105+ NSApplication . shared. terminate ( nil )
106+ }
107+ }
97108
98109 private var alamoFireManager : Session
99110
@@ -488,8 +499,32 @@ extension ApiRequest {
488499 completeHandler ? ( )
489500 }
490501 }
502+
503+ static func flushDNSCache( ) {
504+ let group = DispatchGroup ( )
505+
506+ var flushFakeipCacheResult = false
507+ var flushDNSCacheResult = false
508+
509+ group. enter ( )
510+ ApiRequest . flushFakeipCache {
511+ flushFakeipCacheResult = $0
512+ group. leave ( )
513+ }
514+
515+ group. enter ( )
516+ ApiRequest . flushDNSCache {
517+ flushDNSCacheResult = $0
518+ group. leave ( )
519+ }
520+
521+ group. notify ( queue: . main) {
522+ let info = ( flushFakeipCacheResult && flushDNSCacheResult) ? " Success " : " Failed "
523+ UserNotificationCenter . shared. post ( title: NSLocalizedString ( " Flush dns cache " , comment: " " ) , info: info)
524+ }
525+ }
491526
492- static func flushFakeipCache( completeHandler: ( ( Bool ) -> Void ) ? = nil ) {
527+ private static func flushFakeipCache( completeHandler: ( ( Bool ) -> Void ) ? = nil ) {
493528 Logger . log ( " FlushFakeipCache " )
494529 req ( " /cache/fakeip/flush " ,
495530 method: . post) . response {
@@ -499,7 +534,7 @@ extension ApiRequest {
499534 }
500535 }
501536
502- static func flushDNSCache( completeHandler: ( ( Bool ) -> Void ) ? = nil ) {
537+ private static func flushDNSCache( completeHandler: ( ( Bool ) -> Void ) ? = nil ) {
503538 Logger . log ( " FlushDNSCache " )
504539 req ( " /cache/dns/flush " ,
505540 method: . post) . response {
@@ -745,6 +780,7 @@ extension ApiRequest: WebSocketDelegate {
745780 delegate? . didUpdateTraffic ( up: json [ " up " ] . intValue, down: json [ " down " ] . intValue)
746781 dashboardDelegate? . didUpdateTraffic ( up: json [ " up " ] . intValue, down: json [ " down " ] . intValue)
747782 case loggingWebSocket:
783+ guard logRateLimiter. processLog ( ) else { return }
748784 delegate? . didGetLog ( log: json [ " payload " ] . stringValue, level: json [ " type " ] . string ?? " info " )
749785 dashboardDelegate? . didGetLog ( log: json [ " payload " ] . stringValue, level: json [ " type " ] . string ?? " info " )
750786 case memoryWebSocket:
0 commit comments