From 8a3bfc342fc79f1b07f446e1740577f81d9b662a Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 15 Apr 2026 14:31:16 +0800 Subject: [PATCH] fix groups config --- Tun/Punchnet/SDLTunnelAppNotifier.swift | 7 ++----- punchnet/AppEventCenter/SDLNotificationCenter.swift | 7 +++++++ punchnet/AppEventCenter/SDLTunnelAppEventStore.swift | 11 ++++------- punchnet/punchnetApp.swift | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Tun/Punchnet/SDLTunnelAppNotifier.swift b/Tun/Punchnet/SDLTunnelAppNotifier.swift index 6ab56fa..6945bbf 100644 --- a/Tun/Punchnet/SDLTunnelAppNotifier.swift +++ b/Tun/Punchnet/SDLTunnelAppNotifier.swift @@ -25,14 +25,11 @@ final class SDLTunnelAppNotifier { static let shared = SDLTunnelAppNotifier() - static let appGroupSuiteName = "group.com.jihe.punchnetmac" - static let latestEventKey = "tunnel.latestEvent" - private let suiteName: String private let eventKey: String - init(suiteName: String = SDLTunnelAppNotifier.appGroupSuiteName, - eventKey: String = SDLTunnelAppNotifier.latestEventKey) { + init(suiteName: String = SDLNotificationCenter.Configuration.appGroupSuiteName, + eventKey: String = SDLNotificationCenter.Configuration.latestEventKey) { self.suiteName = suiteName self.eventKey = eventKey } diff --git a/punchnet/AppEventCenter/SDLNotificationCenter.swift b/punchnet/AppEventCenter/SDLNotificationCenter.swift index 46c412d..0b3baac 100644 --- a/punchnet/AppEventCenter/SDLNotificationCenter.swift +++ b/punchnet/AppEventCenter/SDLNotificationCenter.swift @@ -20,6 +20,13 @@ extension DarwinNotificationName { static let tunnelEventChanged = DarwinNotificationName(rawValue: "com.jihe.punchnetmac.tunnelEventChanged") } +extension SDLNotificationCenter { + enum Configuration { + static let appGroupSuiteName = "group.com.jihe.punchnetmac" + static let latestEventKey = "tunnel.latestEvent" + } +} + // MARK: - Manager public final class SDLNotificationCenter { diff --git a/punchnet/AppEventCenter/SDLTunnelAppEventStore.swift b/punchnet/AppEventCenter/SDLTunnelAppEventStore.swift index dc1b4f3..cda85cf 100644 --- a/punchnet/AppEventCenter/SDLTunnelAppEventStore.swift +++ b/punchnet/AppEventCenter/SDLTunnelAppEventStore.swift @@ -23,12 +23,9 @@ struct SDLTunnelAppEventStore { 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), + 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 } @@ -37,11 +34,11 @@ struct SDLTunnelAppEventStore { } static func clearLatestEvent() { - guard let shared = UserDefaults(suiteName: self.appGroupSuiteName) else { + guard let shared = UserDefaults(suiteName: SDLNotificationCenter.Configuration.appGroupSuiteName) else { return } - shared.removeObject(forKey: self.latestEventKey) + shared.removeObject(forKey: SDLNotificationCenter.Configuration.latestEventKey) shared.synchronize() } } diff --git a/punchnet/punchnetApp.swift b/punchnet/punchnetApp.swift index e52d6a3..5addf40 100644 --- a/punchnet/punchnetApp.swift +++ b/punchnet/punchnetApp.swift @@ -86,7 +86,7 @@ struct punchnetApp: App { class AppDelegate: NSObject, NSApplicationDelegate { func applicationWillFinishLaunching(_ notification: Notification) { - let shared = UserDefaults(suiteName: "group.com.jihe.punchnetmac") + let shared = UserDefaults(suiteName: SDLNotificationCenter.Configuration.appGroupSuiteName) shared?.set("App says hello", forKey: "test_msg") shared?.synchronize()