feat: add remote reboot support
This commit is contained in:
@@ -3,8 +3,19 @@ import UserNotifications
|
||||
|
||||
enum PingService {
|
||||
private static var previousPingStates: [String: Bool] = [:]
|
||||
private static var suppressedUntil: [String: Date] = [:]
|
||||
|
||||
static func suppressChecks(for hostname: String, duration: TimeInterval) {
|
||||
suppressedUntil[hostname] = Date().addingTimeInterval(duration)
|
||||
}
|
||||
|
||||
static func ping(hostname: String, apiKey: String, notificationsEnabled: Bool = true) async -> Bool {
|
||||
if let suppressedUntil = suppressedUntil[hostname], suppressedUntil > Date() {
|
||||
return false
|
||||
} else {
|
||||
suppressedUntil.removeValue(forKey: hostname)
|
||||
}
|
||||
|
||||
guard let url = URL(string: "https://\(hostname)/api/v2/ping") else {
|
||||
print("❌ [PingService] Invalid URL for \(hostname)")
|
||||
return false
|
||||
@@ -18,9 +29,6 @@ enum PingService {
|
||||
do {
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode != 200 {
|
||||
if let responseString = String(data: data, encoding: .utf8) {
|
||||
print("❌ [PingService] HTTP \(httpResponse.statusCode): \(responseString)")
|
||||
}
|
||||
handlePingFailure(for: hostname, notificationsEnabled: notificationsEnabled)
|
||||
return false
|
||||
}
|
||||
@@ -33,7 +41,6 @@ enum PingService {
|
||||
return false
|
||||
}
|
||||
} catch {
|
||||
print("❌ [PingService] Error pinging \(hostname): \(error)")
|
||||
handlePingFailure(for: hostname, notificationsEnabled: notificationsEnabled)
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user