New Update to Pair

This commit is contained in:
diyaa
2026-07-27 23:41:27 +02:00
parent 9cbf88d3a0
commit 4e0dcbe873
5 changed files with 230 additions and 7 deletions
@@ -241,9 +241,9 @@ actor WSClient {
}
private func reconnect(using token: String, id: UUID) async {
let delays: [UInt64] = [2, 4, 8, 16, 32]
var delay: UInt64 = 2
for delay in delays {
while !Task.isCancelled {
do {
try await Task.sleep(nanoseconds: delay * 1_000_000_000)
} catch {
@@ -262,14 +262,10 @@ actor WSClient {
}
return
} catch {
delay = min(delay * 2, 60)
continue
}
}
if reconnectID == id {
reconnectID = nil
reconnectTask = nil
}
}
private func closeFailedConnection(_ task: URLSessionWebSocketTask) {
@@ -115,6 +115,10 @@ final class AppSession: ObservableObject {
func unpair() {
incomingMessagesTask?.cancel()
incomingMessagesTask = nil
messages = []
Task {
try? await messageStore.deleteAll()
}
KeychainStore.clearAll()
let webSocket = webSocket
Task {
@@ -55,6 +55,13 @@ actor MessageStore {
try write(messages)
}
func deleteAll() throws {
let url = try messagesURL()
if fileManager.fileExists(atPath: url.path) {
try fileManager.removeItem(at: url)
}
}
var unreadCount: Int {
get async {
(try? loadAll().filter { !$0.isRead }.count) ?? 0