mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix: added additional cooldown before sending device information to the Remote
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user