fix groups config

This commit is contained in:
anlicheng 2026-04-15 14:31:16 +08:00
parent 23d15e3d17
commit 8a3bfc342f
4 changed files with 14 additions and 13 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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()
}
}

View File

@ -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()