fix groups config
This commit is contained in:
parent
23d15e3d17
commit
8a3bfc342f
@ -25,14 +25,11 @@ final class SDLTunnelAppNotifier {
|
|||||||
|
|
||||||
static let shared = SDLTunnelAppNotifier()
|
static let shared = SDLTunnelAppNotifier()
|
||||||
|
|
||||||
static let appGroupSuiteName = "group.com.jihe.punchnetmac"
|
|
||||||
static let latestEventKey = "tunnel.latestEvent"
|
|
||||||
|
|
||||||
private let suiteName: String
|
private let suiteName: String
|
||||||
private let eventKey: String
|
private let eventKey: String
|
||||||
|
|
||||||
init(suiteName: String = SDLTunnelAppNotifier.appGroupSuiteName,
|
init(suiteName: String = SDLNotificationCenter.Configuration.appGroupSuiteName,
|
||||||
eventKey: String = SDLTunnelAppNotifier.latestEventKey) {
|
eventKey: String = SDLNotificationCenter.Configuration.latestEventKey) {
|
||||||
self.suiteName = suiteName
|
self.suiteName = suiteName
|
||||||
self.eventKey = eventKey
|
self.eventKey = eventKey
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,13 @@ extension DarwinNotificationName {
|
|||||||
static let tunnelEventChanged = DarwinNotificationName(rawValue: "com.jihe.punchnetmac.tunnelEventChanged")
|
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
|
// MARK: - Manager
|
||||||
public final class SDLNotificationCenter {
|
public final class SDLNotificationCenter {
|
||||||
|
|||||||
@ -23,12 +23,9 @@ struct SDLTunnelAppEventStore {
|
|||||||
let message: String
|
let message: String
|
||||||
}
|
}
|
||||||
|
|
||||||
static let appGroupSuiteName = "group.com.jihe.punchnetmac"
|
|
||||||
static let latestEventKey = "tunnel.latestEvent"
|
|
||||||
|
|
||||||
static func loadLatestEvent() -> Event? {
|
static func loadLatestEvent() -> Event? {
|
||||||
guard let shared = UserDefaults(suiteName: self.appGroupSuiteName),
|
guard let shared = UserDefaults(suiteName: SDLNotificationCenter.Configuration.appGroupSuiteName),
|
||||||
let data = shared.data(forKey: self.latestEventKey),
|
let data = shared.data(forKey: SDLNotificationCenter.Configuration.latestEventKey),
|
||||||
let event = try? JSONDecoder().decode(Event.self, from: data) else {
|
let event = try? JSONDecoder().decode(Event.self, from: data) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -37,11 +34,11 @@ struct SDLTunnelAppEventStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func clearLatestEvent() {
|
static func clearLatestEvent() {
|
||||||
guard let shared = UserDefaults(suiteName: self.appGroupSuiteName) else {
|
guard let shared = UserDefaults(suiteName: SDLNotificationCenter.Configuration.appGroupSuiteName) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
shared.removeObject(forKey: self.latestEventKey)
|
shared.removeObject(forKey: SDLNotificationCenter.Configuration.latestEventKey)
|
||||||
shared.synchronize()
|
shared.synchronize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,7 +86,7 @@ struct punchnetApp: App {
|
|||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
func applicationWillFinishLaunching(_ notification: Notification) {
|
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?.set("App says hello", forKey: "test_msg")
|
||||||
shared?.synchronize()
|
shared?.synchronize()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user