Skip to content

Commit

Permalink
Merge branch 'feature/iCloudSyncV2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeMatt committed Dec 27, 2024
2 parents f578c85 + cce13a5 commit e65f02c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import PVPrimitives
@objc
public final class PVEmulatorConfiguration: NSObject {

@objc
public static let availableSystemIdentifiers: [String] = {
systems.map({ (system) -> String in
system.identifier
public static let availableSystemIdentifiers: [SystemIdentifier] = {
systems.map({ (system) -> SystemIdentifier in
system.systemIdentifier
})
}()

Expand Down Expand Up @@ -82,10 +81,9 @@ public final class PVEmulatorConfiguration: NSObject {
return systems.first { $0.openvgDatabaseID == databaseID }?.identifier
}

@objc
public class func systemIdentifiers(forFileExtension fileExtension: String) -> [String]? {
return systems(forFileExtension: fileExtension)?.compactMap({ (system) -> String? in
system.identifier
public class func systemIdentifiers(forFileExtension fileExtension: String) -> [SystemIdentifier]? {
return systems(forFileExtension: fileExtension)?.compactMap({ (system) -> SystemIdentifier? in
system.systemIdentifier
})
}

Expand Down Expand Up @@ -191,19 +189,6 @@ public extension PVEmulatorConfiguration {

public extension PVEmulatorConfiguration {


@objc
class func system(forDatabaseID databaseID : Int) -> PVSystem? {
guard let systemID = systemID(forDatabaseID: databaseID) else { return nil }
let system = RomDatabase.sharedInstance.object(ofType: PVSystem.self, wherePrimaryKeyEquals: systemID)
return system
}

class func system(forDatabaseID databaseID : Int) -> System? {
let pvsystem: PVSystem? = system(forDatabaseID: databaseID)
return pvsystem?.asDomain()
}

@objc
class func system(forIdentifier systemID: String) -> PVSystem? {
let system = RomDatabase.sharedInstance.object(ofType: PVSystem.self, wherePrimaryKeyEquals: systemID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import PVLookupTypes
public extension ROMMetadata {
/// The corresponding PVSystem for this ROM metadata
var system: PVSystem? {
return PVEmulatorConfiguration.system(forDatabaseID: systemID.openVGDBID)
return PVEmulatorConfiguration.system(forIdentifier: self.systemID)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,10 @@ public enum ProcessingState {
@Perceptible
public class ImportQueueItem: Identifiable, ObservableObject {

// TODO: Make this more generic with AnySystem, some System?
//public typealias System = PVSystem //AnySystem

public let id = UUID()
public var url: URL
public var fileType: FileType
@MainActor
@PerceptionIgnored
public var systems: [SystemIdentifier] = [] // Can be set to the specific system type
@MainActor
@PerceptionIgnored
public var userChosenSystem: (SystemIdentifier)? = nil
public var destinationUrl: URL?
public var errorValue: String?
Expand All @@ -91,9 +84,8 @@ public class ImportQueueItem: Identifiable, ObservableObject {
}
}

@MainActor
private func updateSystems() {
systems = RomDatabase.sharedInstance.all(PVSystem.self).map { $0.systemIdentifier }
systems = PVEmulatorConfiguration.availableSystemIdentifiers
}

private let md5Provider: MD5Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ public final class GameImporter: GameImporting, ObservableObject {
var importAutoStartDelayTask: Task<Void, Never>?
public var importQueue: [ImportQueueItem] = [] {
didSet {
importAutoStartDelayTask?.cancel()
importAutoStartDelayTask = Task {
await try? Task.sleep(for: .seconds(1))
self.startProcessing()
// Schedule auto-start if there are queued items OR items with a user-chosen system
if importQueue.contains(where: {
$0.status == .queued || $0.userChosenSystem != nil
}) {
importAutoStartDelayTask?.cancel()
importAutoStartDelayTask = Task {
await try? Task.sleep(for: .seconds(1))
self.startProcessing()
}
}
}
}
Expand Down Expand Up @@ -646,17 +651,33 @@ public final class GameImporter: GameImporting, ObservableObject {
// Processes each ImportItem in the queue sequentially
@MainActor
private func processQueue() async {
// Check for items that are either queued or have a user-chosen system
let itemsToProcess = importQueue.filter {
$0.status == .queued || $0.userChosenSystem != nil
}

guard !itemsToProcess.isEmpty else {
DispatchQueue.main.async {
self.processingState = .idle
}
return
}

ILOG("GameImportQueue - processQueue beginning Import Processing")
DispatchQueue.main.async {
self.processingState = .processing
}

for item in importQueue where item.status == .queued {
for item in itemsToProcess {
// If there's a user-chosen system, ensure the item is queued
if item.userChosenSystem != nil {
item.status = .queued
}
await processItem(item)
}

DispatchQueue.main.async {
self.processingState = .idle // Reset processing status when queue is fully processed
self.processingState = .idle
}
ILOG("GameImportQueue - processQueue complete Import Processing")
}
Expand Down Expand Up @@ -733,7 +754,7 @@ public final class GameImporter: GameImporting, ObservableObject {

//update item's candidate systems with the result of determineSystems
item.systems = systems

//this might be a conflict if we can't infer what to do
//for BIOS, we can handle multiple systems, so allow that to proceed
if item.fileType != .bios && item.targetSystem() == nil {
Expand Down
23 changes: 11 additions & 12 deletions PVUI/Sources/PVUIBase/State Management/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,19 @@ public class AppState: ObservableObject {
}

/// Method to initialize the database
private func initializeDatabase() {
@MainActor
private func initializeDatabase() async {
ILOG("AppState: Starting database initialization")
bootupStateManager.transition(to: .initializingDatabase)
Task { @MainActor in
do {
ILOG("AppState: Calling RomDatabase.initDefaultDatabase()")
try await RomDatabase.initDefaultDatabase()
ILOG("AppState: Database initialization completed successfully")
bootupStateManager.transition(to: .databaseInitialized)
await initializeLibrary()
} catch {
ELOG("AppState: Error initializing database: \(error.localizedDescription)")
bootupStateManager.transition(to: .error(error))
}
do {
ILOG("AppState: Calling RomDatabase.initDefaultDatabase()")
try await RomDatabase.initDefaultDatabase()
ILOG("AppState: Database initialization completed successfully")
bootupStateManager.transition(to: .databaseInitialized)
await initializeLibrary()
} catch {
ELOG("AppState: Error initializing database: \(error.localizedDescription)")
bootupStateManager.transition(to: .error(error))
}
}

Expand Down
12 changes: 6 additions & 6 deletions Provenance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8296,7 +8296,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.arcade-games";
INFOPLIST_KEY_NSStickerSharingLevel = OS;
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
Expand Down Expand Up @@ -8394,7 +8394,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.arcade-games";
INFOPLIST_KEY_NSStickerSharingLevel = OS;
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
Expand Down Expand Up @@ -8493,7 +8493,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.arcade-games";
INFOPLIST_KEY_NSStickerSharingLevel = OS;
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
Expand Down Expand Up @@ -8976,7 +8976,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.arcade-games";
INFOPLIST_KEY_NSStickerSharingLevel = OS;
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
Expand Down Expand Up @@ -9074,7 +9074,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.arcade-games";
INFOPLIST_KEY_NSStickerSharingLevel = OS;
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
Expand Down Expand Up @@ -9172,7 +9172,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.arcade-games";
INFOPLIST_KEY_NSStickerSharingLevel = OS;
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
Expand Down

0 comments on commit e65f02c

Please sign in to comment.