parent
c6b3ad5921
commit
81aa3a2714
|
@ -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
|
||||
|
|
|
@ -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] {
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -34,6 +34,10 @@ final class MockProfileMigrationStrategy: ProfileMigrationStrategy {
|
|||
|
||||
var failedProfiles: Set<UUID> = []
|
||||
|
||||
var hasMigratableProfiles: Bool {
|
||||
!migratedProfiles.isEmpty
|
||||
}
|
||||
|
||||
func fetchMigratableProfiles() async throws -> [MigratableProfile] {
|
||||
migratableProfiles
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue