fix(presence): dedupe instances via stable instanceId
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
import Foundation
|
||||
|
||||
enum InstanceIdentity {
|
||||
private static let suiteName = "com.steipete.clawdis.shared"
|
||||
private static let instanceIdKey = "instanceId"
|
||||
|
||||
private static let defaults: UserDefaults = {
|
||||
UserDefaults(suiteName: suiteName) ?? .standard
|
||||
}()
|
||||
|
||||
static let instanceId: String = {
|
||||
if let name = Host.current().localizedName?.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
!name.isEmpty
|
||||
if let existing = defaults.string(forKey: instanceIdKey)?
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
!existing.isEmpty
|
||||
{
|
||||
return name
|
||||
return existing
|
||||
}
|
||||
return UUID().uuidString
|
||||
|
||||
let id = UUID().uuidString.lowercased()
|
||||
defaults.set(id, forKey: instanceIdKey)
|
||||
return id
|
||||
}()
|
||||
|
||||
static let displayName: String = {
|
||||
@@ -19,4 +30,3 @@ enum InstanceIdentity {
|
||||
return "clawdis-mac"
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user