record method
Upsert by key (keeps firstSeen, bumps attachCount), re-sort, cap, write.
Implementation
void record(AttachRecord incoming) {
try {
final list = load();
final idx = list.indexWhere((r) => r.key == incoming.key);
if (idx >= 0) {
final prev = list.removeAt(idx);
incoming = AttachRecord(
appKey: incoming.appKey,
displayName: incoming.displayName ?? prev.displayName,
bundleId: incoming.bundleId ?? prev.bundleId,
deviceId: incoming.deviceId,
platform: incoming.platform,
deviceName: incoming.deviceName ?? prev.deviceName,
osVersion: incoming.osVersion ?? prev.osVersion,
projectDir: incoming.projectDir ?? prev.projectDir,
firstSeen: prev.firstSeen,
lastSeen: incoming.lastSeen,
attachCount: prev.attachCount + 1,
);
}
list.insert(0, incoming);
list.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
_write(list.take(maxRecords).toList());
} on Object {
// best-effort — history is a convenience, never a hard dependency
}
}