Skip onboarding migration if no migratable profiles (#1002)

Annoying!
This commit is contained in:
Davide 2024-12-11 22:20:14 +01:00 committed by GitHub
parent c6b3ad5921
commit 81aa3a2714
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 40 additions and 2 deletions

View File

@ -29,6 +29,9 @@ import SwiftUI
struct OnboardingModifier: ViewModifier {
@EnvironmentObject
private var migrationManager: MigrationManager
@Environment(\.isUITesting)
private var isUITesting
@ -87,6 +90,10 @@ private extension OnboardingModifier {
switch step {
case .migrateV3:
guard migrationManager.hasMigratableProfiles else {
advance()
return
}
modalRoute = .migrateProfiles
case .community:
isPresentingCommunity = true

View File

@ -62,6 +62,10 @@ public final class MigrationManager: ObservableObject {
// MARK: - Public interface
extension MigrationManager {
public var hasMigratableProfiles: Bool {
profileStrategy.hasMigratableProfiles
}
public func fetchMigratableProfiles() async throws -> [MigratableProfile] {
try await profileStrategy.fetchMigratableProfiles()
}
@ -173,7 +177,8 @@ private extension MigrationManager {
// MARK: - Dummy
private final class DummyProfileStrategy: ProfileMigrationStrategy {
public init() {
var hasMigratableProfiles: Bool {
false
}
public func fetchMigratableProfiles() async throws -> [MigratableProfile] {

View File

@ -27,6 +27,8 @@ import Foundation
import PassepartoutKit
public protocol ProfileMigrationStrategy {
var hasMigratableProfiles: Bool { get}
func fetchMigratableProfiles() async throws -> [MigratableProfile]
func fetchProfile(withId profileId: UUID) async throws -> Profile?

View File

@ -42,6 +42,22 @@ final class CDProfileRepositoryV2: Sendable {
self.context = context
}
var hasMigratableProfiles: Bool {
do {
return try context.performAndWait { [weak self] in
guard let self else {
return false
}
let entities = try CDProfile.fetchRequest().execute()
return !entities.compactMap {
($0.encryptedJSON ?? $0.json) != nil
}.isEmpty
}
} catch {
return false
}
}
func migratableProfiles() async throws -> [MigratableProfile] {
try await fetchProfiles(
prefetch: {
@ -49,7 +65,7 @@ final class CDProfileRepositoryV2: Sendable {
},
map: {
$0.compactMap {
guard $0.value.encryptedJSON ?? $0.value.json != nil else {
guard ($0.value.encryptedJSON ?? $0.value.json) != nil else {
pp_log(.App.migration, .error, "ProfileV2 \($0.key) is not migratable: missing JSON")
return nil
}

View File

@ -74,6 +74,10 @@ public final class ProfileV2MigrationStrategy: ProfileMigrationStrategy, Sendabl
// MARK: - ProfileMigrationStrategy
extension ProfileV2MigrationStrategy {
public var hasMigratableProfiles: Bool {
profilesRepository.hasMigratableProfiles
}
public func fetchMigratableProfiles() async throws -> [MigratableProfile] {
try await profilesRepository.migratableProfiles()
}

View File

@ -34,6 +34,10 @@ final class MockProfileMigrationStrategy: ProfileMigrationStrategy {
var failedProfiles: Set<UUID> = []
var hasMigratableProfiles: Bool {
!migratedProfiles.isEmpty
}
func fetchMigratableProfiles() async throws -> [MigratableProfile] {
migratableProfiles
}