Skip to content

Commit

Permalink
Merge branch 'meta-dev' into meta
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFq1 committed Oct 4, 2024
2 parents 1a62405 + 509ed01 commit e9a8e7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ClashX/Dashboard/Views/ClashApiDatasStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class ClashApiDatasStorage: NSObject, ObservableObject {
@Published var connsStorage = ClashConnsStorage()

func resetStreamApi() {
ApiRequest.shared.delegate = self
ApiRequest.shared.resetStreamApis()
ApiRequest.shared.dashboardDelegate = self
if ApiRequest.shared.delegate == nil {
ApiRequest.shared.resetStreamApis()
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions ClashX/General/ApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ApiRequest {
}

weak var delegate: ApiRequestStreamDelegate?
weak var dashboardDelegate: ApiRequestStreamDelegate?

private var trafficWebSocket: WebSocket?
private var loggingWebSocket: WebSocket?
Expand Down Expand Up @@ -640,6 +641,7 @@ extension ApiRequest: WebSocketDelegate {

ConfigManager.shared.isRunning = true
delegate?.streamStatusChanged()
dashboardDelegate?.streamStatusChanged()
case loggingWebSocket:
loggingWebSocketRetryDelay = 1
Logger.log("loggingWebSocket did Connect", level: .debug)
Expand All @@ -656,6 +658,7 @@ extension ApiRequest: WebSocketDelegate {
if (socket as? WebSocket) == trafficWebSocket {
ConfigManager.shared.isRunning = false
delegate?.streamStatusChanged()
dashboardDelegate?.streamStatusChanged()
}

guard let err = error else {
Expand Down Expand Up @@ -711,10 +714,13 @@ extension ApiRequest: WebSocketDelegate {
switch webSocket {
case trafficWebSocket:
delegate?.didUpdateTraffic(up: json["up"].intValue, down: json["down"].intValue)
dashboardDelegate?.didUpdateTraffic(up: json["up"].intValue, down: json["down"].intValue)
case loggingWebSocket:
delegate?.didGetLog(log: json["payload"].stringValue, level: json["type"].string ?? "info")
dashboardDelegate?.didGetLog(log: json["payload"].stringValue, level: json["type"].string ?? "info")
case memoryWebSocket:
delegate?.didUpdateMemory(memory: json["inuse"].int64Value)
dashboardDelegate?.didUpdateMemory(memory: json["inuse"].int64Value)
default:
return
}
Expand Down

0 comments on commit e9a8e7e

Please sign in to comment.