mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-07 09:25:33 +00:00
Keep track of migrations that are performed
This commit is contained in:
parent
8ba393e034
commit
3b2e1153ca
3 changed files with 22 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ public enum Key {
|
|||
static let engineVersion = "KeymanEngineVersion"
|
||||
static let keyboardPickerDisplayed = "KeyboardPickerDisplayed"
|
||||
static let synchronizeSWKeyboard = "KeymanSynchronizeSWKeyboard"
|
||||
static let migrationLevel = "KeymanEngineMigrationLevel"
|
||||
|
||||
// JSON keys for language REST calls
|
||||
static let options = "options"
|
||||
|
|
|
|||
|
|
@ -84,4 +84,14 @@ public extension UserDefaults {
|
|||
public func userKeyboard(withID keyboardID: String, languageID: String) -> InstallableKeyboard? {
|
||||
return userKeyboards?.first { $0.id == keyboardID && $0.languageID == languageID }
|
||||
}
|
||||
|
||||
var migrationLevel: Int {
|
||||
get {
|
||||
return integer(forKey: Key.migrationLevel)
|
||||
}
|
||||
|
||||
set(level) {
|
||||
set(level, forKey: Key.migrationLevel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,17 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
fileprivate enum MigrationLevel {
|
||||
static let initial = 0
|
||||
static let migratedForKMP = 10
|
||||
}
|
||||
|
||||
enum Migrations {
|
||||
static func migrateForKMP(storage: Storage) {
|
||||
guard storage.userDefaults.migrationLevel < MigrationLevel.migratedForKMP else {
|
||||
return
|
||||
}
|
||||
|
||||
let languageDir = storage.baseDir.appendingPathComponent("languages")
|
||||
let fontDir = storage.baseDir.appendingPathComponent("fonts")
|
||||
|
||||
|
|
@ -80,6 +89,8 @@ enum Migrations {
|
|||
// Remove keyboards that were not copied successfully
|
||||
let filteredUserKeyboards = userKeyboards.filter { successfulKeyboards.contains($0.id) }
|
||||
storage.userDefaults.userKeyboards = filteredUserKeyboards
|
||||
storage.userDefaults.migrationLevel = MigrationLevel.migratedForKMP
|
||||
storage.userDefaults.synchronize()
|
||||
|
||||
// TODO: Remove old directory
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue