From e27ad7e2ef4b75ac0a420dbbe2f47aa97639a8a1 Mon Sep 17 00:00:00 2001 From: jahorton Date: Thu, 13 Feb 2020 10:54:01 +0700 Subject: [PATCH] fix(ios): initial-install check within Migrations --- ios/engine/KMEI/KeymanEngine/Classes/Migrations.swift | 7 ++++++- ios/engine/KMEI/KeymanEngine/Classes/Model/Version.swift | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Migrations.swift b/ios/engine/KMEI/KeymanEngine/Classes/Migrations.swift index b7ba94c99c..6ae03a82e1 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Migrations.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Migrations.swift @@ -116,6 +116,11 @@ public enum Migrations { // Detect possible version matches. let userResources = Storage.active.userDefaults.userResources ?? [] + + // If there are no pre-existing resources and we need to detect a version, this is a fresh install. + if userResources.count == 0 { + return [Version.freshInstall] + } let possibleMatches: [Version] = resourceHistory.compactMap { set in if set.version < Version("12.0")! { // Are all of the version's default resources present? @@ -183,7 +188,7 @@ public enum Migrations { } } - if lastVersion != nil { + if lastVersion != nil && lastVersion != Version.freshInstall { // Time to deinstall the old version's resources. // First, find the most recent version with a listed history. let possibleHistories: [VersionResourceSet] = resourceHistory.compactMap { set in diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Model/Version.swift b/ios/engine/KMEI/KeymanEngine/Classes/Model/Version.swift index 8936def380..b457dbd1bb 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Model/Version.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Model/Version.swift @@ -14,6 +14,7 @@ public struct Version: Comparable { public static let current = Version("13.0.65")! // The Engine first started tracking the 'last loaded version' in 12.0. + public static let freshInstall = Version("0.0")! public static let firstTracked = Version("12.0")! // The Keyman App's file browser was first added in 13.0 alpha;