45 lines
1.2 KiB
Swift
45 lines
1.2 KiB
Swift
//
|
|
// SDLTunnelAppEventStore.swift
|
|
// punchnet
|
|
//
|
|
// Created by 安礼成 on 2026/4/15.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
struct SDLTunnelAppEventStore {
|
|
struct Event: Codable, Sendable, Identifiable {
|
|
enum Level: String, Codable, Sendable {
|
|
case info
|
|
case warning
|
|
case error
|
|
case fatal
|
|
}
|
|
|
|
let id: String
|
|
let timestamp: TimeInterval
|
|
let level: Level
|
|
let code: Int?
|
|
let message: String
|
|
}
|
|
|
|
static func loadLatestEvent() -> Event? {
|
|
guard let shared = UserDefaults(suiteName: SDLNotificationCenter.Configuration.appGroupSuiteName),
|
|
let data = shared.data(forKey: SDLNotificationCenter.Configuration.latestEventKey),
|
|
let event = try? JSONDecoder().decode(Event.self, from: data) else {
|
|
return nil
|
|
}
|
|
|
|
return event
|
|
}
|
|
|
|
static func clearLatestEvent() {
|
|
guard let shared = UserDefaults(suiteName: SDLNotificationCenter.Configuration.appGroupSuiteName) else {
|
|
return
|
|
}
|
|
|
|
shared.removeObject(forKey: SDLNotificationCenter.Configuration.latestEventKey)
|
|
shared.synchronize()
|
|
}
|
|
}
|