// // 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 let appGroupSuiteName = "group.com.jihe.punchnetmac" static let latestEventKey = "tunnel.latestEvent" static func loadLatestEvent() -> Event? { guard let shared = UserDefaults(suiteName: self.appGroupSuiteName), let data = shared.data(forKey: self.latestEventKey), let event = try? JSONDecoder().decode(Event.self, from: data) else { return nil } return event } static func clearLatestEvent() { guard let shared = UserDefaults(suiteName: self.appGroupSuiteName) else { return } shared.removeObject(forKey: self.latestEventKey) shared.synchronize() } }