Skip to content

Commit

Permalink
fixes pull to referesh
Browse files Browse the repository at this point in the history
  • Loading branch information
proskd committed Nov 11, 2024
1 parent 374ce6a commit 90e5a64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ public final class GameImporter: GameImporting, ObservableObject {
defer { importQueueLock.unlock() }

self.addImportItemToQueue(item)


// startProcessing()
}

public func addImports(forPaths paths: [URL]) {
Expand All @@ -351,7 +348,17 @@ public final class GameImporter: GameImporting, ObservableObject {
for path in paths {
self.addImportItemToQueue(ImportQueueItem(url: path, fileType: .unknown))
}
// startProcessing()
}

public func addImports(forPaths paths: [URL], targetSystem: PVSystem) {
importQueueLock.lock()
defer { importQueueLock.unlock() }

for path in paths {
var item = ImportQueueItem(url: path, fileType: .unknown)
item.userChosenSystem = targetSystem
self.addImportItemToQueue(item)
}
}

// Public method to manually start processing if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,14 @@ public final class PVGameLibraryUpdatesController: ObservableObject {
}
}

/// auto scans ROM directories and adds to the import queue
public func importROMDirectories() async {
ILOG("PVGameLibrary: Starting Import")
RomDatabase.reloadCache(force: true)
RomDatabase.reloadFileSystemROMCache()
let dbGames: [AnyHashable: PVGame] = await RomDatabase.gamesCache
let dbSystems: [AnyHashable: PVSystem] = RomDatabase.systemCache
var queueGames = false

for system in dbSystems.values {
ILOG("PVGameLibrary: Importing \(system.identifier)")
Expand All @@ -288,20 +290,17 @@ public final class PVGameLibraryUpdatesController: ObservableObject {
dbGames.index(forKey: (system.identifier as NSString).appendingPathComponent($0.lastPathComponent)) == nil
}
if !newGames.isEmpty {
ILOG("PVGameLibraryUpdatesController: Importing \(newGames)")
//TODO: I think we want to add items to the import queue here
//await gameImporter.getRomInfoForFiles(atPaths: newGames, userChosenSystem: system.asDomain())
#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
await MainActor.run {
Task {
await self.addImportedGames(to: CSSearchableIndex.default(), database: RomDatabase.sharedInstance)
}
}
#endif
ILOG("PVGameLibraryUpdatesController: Adding \(newGames) to the queue")
gameImporter.addImports(forPaths: newGames, targetSystem:system)
queueGames = true
}
ILOG("PVGameLibrary: Imported OK \(system.identifier)")
ILOG("PVGameLibrary: Added items for \(system.identifier) to queue")
}
if (queueGames) {
ILOG("PVGameLibrary: Queued new items, starting to process")
gameImporter.startProcessing()
}
ILOG("PVGameLibrary: Import Complete")
ILOG("PVGameLibrary: importROMDirectories complete")
}

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
Expand Down

0 comments on commit 90e5a64

Please sign in to comment.