PropertyPersistentFlags.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // PropertyPersistentFlags.swift
  3. // Trio
  4. //
  5. // Created by Cengiz Deniz on 06.05.25.
  6. //
  7. import Foundation
  8. /// Centralized store for app-wide persistent flags backed by property list (.plist) files.
  9. ///
  10. /// This class uses the `@PersistedProperty` wrapper to store simple state flags such as
  11. /// onboarding completion, diagnostics sharing preference, and the last cleanup timestamp.
  12. ///
  13. /// All values are persisted independently in the app’s documents directory as `.plist` files,
  14. /// and survive app restarts and reinstallations (unless the sandbox is cleared).
  15. ///
  16. /// Accessed as a singleton via `PropertyPersistentFlags.shared`.
  17. final class PropertyPersistentFlags {
  18. static let shared = PropertyPersistentFlags()
  19. @PersistedProperty(key: "onboardingCompleted") var onboardingCompleted: Bool?
  20. @PersistedProperty(key: "diagnosticsSharing") var diagnosticsSharingEnabled: Bool?
  21. @PersistedProperty(key: "lastCleanupDate") var lastCleanupDate: Date?
  22. // TODO: This flag can be deleted in March 2027. Check the commit for other places to cleanup.
  23. @PersistedProperty(key: "hasSeenFatProteinOrderChange") var hasSeenFatProteinOrderChange: Bool?
  24. // MARK: - Telemetry
  25. //
  26. // See Trio/Sources/Services/Telemetry/TelemetryClient.swift.
  27. // `telemetryEnabled` gates the anonymous-usage POST. `diagnosticsSharingEnabled`
  28. // remains the Crashlytics gate. Both flags `nil` means the user has not yet
  29. // chosen — used to surface the one-time migration sheet to existing users.
  30. @PersistedProperty(key: "telemetryEnabled") var telemetryEnabled: Bool?
  31. @PersistedProperty(key: "telemetryConsentDecisionMade") var telemetryConsentDecisionMade: Bool?
  32. @PersistedProperty(key: "telemetryLastSentAt") var telemetryLastSentAt: Date?
  33. @PersistedProperty(key: "telemetryLastSentSha") var telemetryLastSentSha: String?
  34. // Sliding 7-day window of cold-launch timestamps; count is sent as `coldLaunches7d`.
  35. @PersistedProperty(key: "telemetryColdLaunchTimes") var telemetryColdLaunchTimes: [Date]?
  36. // Stable per-install UUID. IDFV resets when the user removes all Trio-team apps;
  37. // this survives independently and is wiped only by deleting Trio itself.
  38. @PersistedProperty(key: "telemetryInstallId") var telemetryInstallId: String?
  39. // App Attest "give up" signal — set on a 403 from /api/attest/register, meaning
  40. // the server has rejected this app_id and there's no point retrying.
  41. @PersistedProperty(key: "telemetryAttestForbidden") var telemetryAttestForbidden: Bool?
  42. // Debug override for the telemetry server base URL. Empty/unset → use the
  43. // production constant in TelemetryClient. Surfaced as a hidden field in
  44. // App Diagnostics for local testing against a dev server.
  45. @PersistedProperty(key: "telemetryDebugServerURL") var telemetryDebugServerURL: String?
  46. }