Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
- Created Settings directory with core store files - Implemented SettingsStore with UserDefaults/App Group support - Created AppSettings for app-wide configuration - Created UserPreferences for unified preferences access - Added enableAll/disableAll methods to ReadingPreferences - Added enableAll/disableAll methods to NotificationPreferences - Created SettingsMigration framework for version migrations This implements the core settings infrastructure for iOS. Co-Authored-By: Paperclip <noreply@paperclip.ing>
66 lines
1.7 KiB
Swift
66 lines
1.7 KiB
Swift
//
|
|
// AppSettings.swift
|
|
// RSSuper
|
|
//
|
|
// App-wide settings configuration
|
|
//
|
|
|
|
import Foundation
|
|
|
|
struct AppSettings: Codable, Equatable {
|
|
var appVersion: String
|
|
var buildNumber: String
|
|
var lastMigrationVersion: String?
|
|
var firstLaunchAt: Date?
|
|
var lastLaunchAt: Date?
|
|
var launchCount: Int
|
|
|
|
init(
|
|
appVersion: String = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0",
|
|
buildNumber: String = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "1",
|
|
lastMigrationVersion: String? = nil,
|
|
firstLaunchAt: Date? = nil,
|
|
lastLaunchAt: Date? = nil,
|
|
launchCount: Int = 0
|
|
) {
|
|
self.appVersion = appVersion
|
|
self.buildNumber = buildNumber
|
|
self.lastMigrationVersion = lastMigrationVersion
|
|
self.firstLaunchAt = firstLaunchAt
|
|
self.lastLaunchAt = lastLaunchAt
|
|
self.launchCount = launchCount
|
|
}
|
|
|
|
var isFirstLaunch: Bool {
|
|
firstLaunchAt == nil
|
|
}
|
|
|
|
func incrementLaunchCount() -> AppSettings {
|
|
var copy = self
|
|
copy.launchCount += 1
|
|
copy.lastLaunchAt = Date()
|
|
if firstLaunchAt == nil {
|
|
copy.firstLaunchAt = Date()
|
|
}
|
|
return copy
|
|
}
|
|
|
|
func withMigrationComplete(version: String) -> AppSettings {
|
|
var copy = self
|
|
copy.lastMigrationVersion = version
|
|
return copy
|
|
}
|
|
|
|
var debugDescription: String {
|
|
"""
|
|
AppSettings(
|
|
appVersion: \(appVersion),
|
|
buildNumber: \(buildNumber),
|
|
lastMigrationVersion: \(lastMigrationVersion ?? "none"),
|
|
isFirstLaunch: \(isFirstLaunch),
|
|
launchCount: \(launchCount)
|
|
)
|
|
"""
|
|
}
|
|
}
|