fix: added additional cooldown before sending device information to the Remote

This commit is contained in:
Serhiy Mytrovtsiy
2025-08-31 17:50:30 +02:00
parent 16efe9dda8
commit 5a333c1f07
2 changed files with 24 additions and 6 deletions

View File

@@ -55,6 +55,7 @@ public class Remote {
private var isConnecting = false
private var lastSleepTime: Date?
private var lastRegisterTime: Date?
struct Details: Codable {
let client: Client
@@ -169,6 +170,14 @@ public class Remote {
}
private func registerDevice() {
let oneHour: TimeInterval = 3600
let now = Date()
if let lastTime = self.lastRegisterTime, now.timeIntervalSince(lastTime) < oneHour {
debug("Device registration skipped: cooldown period not met", log: self.log)
return
}
self.lastRegisterTime = now
guard let url = URL(string: "\(Remote.host)/remote/device") else { return }
var request = URLRequest(url: url)
@@ -758,13 +767,18 @@ class MQTTManager: NSObject {
guard !self.isConnected else { return }
Remote.shared.auth.isAuthorized { [weak self] status in
guard status, let self else { return }
guard let self else { return }
self.webSocket = self.session?.webSocketTask(with: Remote.brokerHost, protocols: ["mqtt"])
self.webSocket?.resume()
self.receiveMessage()
self.isDisconnected = false
debug("MQTT WebSocket connecting...", log: self.log)
if status {
self.webSocket = self.session?.webSocketTask(with: Remote.brokerHost, protocols: ["mqtt"])
self.webSocket?.resume()
self.receiveMessage()
self.isDisconnected = false
debug("MQTT WebSocket connecting...", log: self.log)
} else {
debug("Authorization failed, retrying connection...", log: self.log)
self.reconnect()
}
}
}

View File

@@ -126,6 +126,7 @@ public struct ram_s: Codable {
}
public struct gpu_s: Codable {
public var id: String? = nil
public var name: String? = nil
public var vendor: String? = nil
public var vram: String? = nil
@@ -380,11 +381,13 @@ public class SystemKit {
}
var list: [gpu_s] = []
var i = 0
do {
if let json = try JSONSerialization.jsonObject(with: Data(res.utf8), options: []) as? [String: Any] {
if let arr = json["SPDisplaysDataType"] as? [[String: Any]] {
for obj in arr {
var gpu: gpu_s = gpu_s()
gpu.id = "\(i)"
gpu.name = obj["sppci_model"] as? String
gpu.vendor = obj["spdisplays_vendor"] as? String
@@ -397,6 +400,7 @@ public class SystemKit {
}
list.append(gpu)
i += 1
}
}
}