forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceUpdateMigrator.swift
More file actions
33 lines (27 loc) · 992 Bytes
/
ServiceUpdateMigrator.swift
File metadata and controls
33 lines (27 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Configs
import Foundation
import Preferences
extension UserDefaultPreferenceKeys {
struct OldMigrationVersion: UserDefaultPreferenceKey {
var defaultValue: String = "0"
let key = "OldMigrationVersion"
}
var oldMigrationVersion: OldMigrationVersion { .init() }
}
public struct ServiceUpdateMigrator {
public init() {}
public func migrate() async throws {
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "0"
try await migrate(from: UserDefaults.shared.value(for: \.oldMigrationVersion), to: version)
UserDefaults.shared.set(version, for: \.oldMigrationVersion)
}
func migrate(from oldVersion: String, to currentVersion: String) async throws {
guard let old = Int(oldVersion), old != 0 else { return }
if old <= 135 {
try migrateFromLowerThanOrEqualToVersion135()
}
if old < 240 {
try migrateTo240()
}
}
}