cards-native/Sources/Core/Sync/WidgetSnapshot.swift
Till JS 4dfb32ba25 chore: Rebrand auf ev.mana.cardecky
Apple-Developer-Portal-App-ID lautet ev.mana.cardecky (analog zur
Domain cardecky.mana.how). Alle Bundle-IDs, App-Group, Keychain-
Group, OSLog-Subsysteme, URL-Schemes, Widget-Kind, App-Intent-Phrases,
Marketing-Texte und Doku nachgezogen.

Bundle-IDs neu:
- Main: ev.mana.cardecky
- Widget: ev.mana.cardecky.widget
- Share: ev.mana.cardecky.share
- Tests: ev.mana.cardecky.tests / .uitests

App-Group: group.ev.mana.cardecky
Keychain-Access-Group: $(AppIdentifierPrefix)ev.mana.cardecky
OSLog-Subsystem: ev.mana.cardecky

AASA gleichzeitig in cards-Repo angepasst (Commit 21ec535) und
auf mana-server redeployed — Probe liefert appID
"QP3GLU8PH3.ev.mana.cardecky".

Plus: ShareExtension/Resources/Info.plist + entitlements werden
jetzt analog zu Widget-Resources gitignored (sind XcodeGen-generated).

35 Unit-Tests + 1 UI-Test grün, alle drei Targets bauen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 13:29:04 +02:00

48 lines
1.7 KiB
Swift

import Foundation
/// Datei-Format für die WidgetKit-Extension. Wird vom Haupt-Target nach
/// jedem erfolgreichen `DeckListStore.refresh()` in den shared App-Group-
/// Container geschrieben; das Widget liest es im TimelineProvider.
///
/// Wire ist bewusst stabil + schmal nur was das Widget rendert.
/// Neue Felder dürfen additiv dazukommen, alte Felder bleiben.
struct WidgetSnapshot: Codable, Sendable {
let updatedAt: Date
let totalDueCount: Int
let topDecks: [Entry]
struct Entry: Codable, Sendable, Identifiable {
let id: String // deck-id
let name: String
let dueCount: Int
let colorHex: String?
}
}
/// Liest und schreibt WidgetSnapshot in den shared App-Group-Container.
enum WidgetSnapshotStore {
/// App-Group-ID muss exakt mit dem Entitlement-Eintrag matchen.
static let appGroupID = "group.ev.mana.cardecky"
static let snapshotFilename = "widget-snapshot.json"
static var snapshotURL: URL? {
FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)?
.appendingPathComponent(snapshotFilename)
}
static func write(_ snapshot: WidgetSnapshot) {
guard let url = snapshotURL else { return }
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .iso8601
guard let data = try? encoder.encode(snapshot) else { return }
try? data.write(to: url, options: .atomic)
}
static func read() -> WidgetSnapshot? {
guard let url = snapshotURL, let data = try? Data(contentsOf: url) else { return nil }
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
return try? decoder.decode(WidgetSnapshot.self, from: data)
}
}