mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-12 08:13:26 +01:00
Supports both iPhone + iPad screenshots
Prefers showing screenshots for current device, but falls back to all screenshots if there are no relevant ones.
This commit is contained in:
@@ -189,7 +189,7 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
|
||||
var permissionsByGlobalAppID = [String: Set<AnyHashable>]()
|
||||
var sortedVersionIDsByGlobalAppID = [String: NSOrderedSet]()
|
||||
var sortedScreenshotURLsByGlobalAppID = [String: NSOrderedSet]()
|
||||
var sortedScreenshotIDsByGlobalAppID = [String: NSOrderedSet]()
|
||||
|
||||
var featuredAppIDsBySourceID = [String: [String]]()
|
||||
|
||||
@@ -220,10 +220,10 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
}
|
||||
|
||||
// Screenshots
|
||||
let contextScreenshotURLs = NSOrderedSet(array: contextApp._screenshots.lazy.compactMap { $0 as? AppScreenshot }.map { $0.imageURL })
|
||||
for case let databaseScreenshot as AppScreenshot in databaseObject._screenshots where !contextScreenshotURLs.contains(databaseScreenshot.imageURL)
|
||||
let contextScreenshotIDs = NSOrderedSet(array: contextApp._screenshots.lazy.compactMap { $0 as? AppScreenshot }.map { $0.screenshotID })
|
||||
for case let databaseScreenshot as AppScreenshot in databaseObject._screenshots where !contextScreenshotIDs.contains(databaseScreenshot.screenshotID)
|
||||
{
|
||||
// Screenshot's imageURL does NOT exist in context, so delete existing databaseScreenshot.
|
||||
// Screenshot ID does NOT exist in context, so delete existing databaseScreenshot.
|
||||
databaseScreenshot.managedObjectContext?.delete(databaseScreenshot)
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
{
|
||||
permissionsByGlobalAppID[globallyUniqueID] = contextPermissions
|
||||
sortedVersionIDsByGlobalAppID[globallyUniqueID] = contextVersionIDs
|
||||
sortedScreenshotURLsByGlobalAppID[globallyUniqueID] = contextScreenshotURLs
|
||||
sortedScreenshotIDsByGlobalAppID[globallyUniqueID] = contextScreenshotIDs
|
||||
}
|
||||
|
||||
case let databaseObject as Source:
|
||||
@@ -313,27 +313,27 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
}
|
||||
|
||||
// Screenshots
|
||||
if let sortedScreenshotURLs = sortedScreenshotURLsByGlobalAppID[globallyUniqueID],
|
||||
let sortedScreenshotURLsArray = sortedScreenshotURLs.array as? [URL],
|
||||
case let databaseScreenshotURLs = databaseObject.screenshots.map({ $0.imageURL }),
|
||||
databaseScreenshotURLs != sortedScreenshotURLsArray
|
||||
if let sortedScreenshotIDs = sortedScreenshotIDsByGlobalAppID[globallyUniqueID],
|
||||
let sortedScreenshotIDsArray = sortedScreenshotIDs.array as? [String],
|
||||
case let databaseScreenshotIDs = databaseObject.allScreenshots.map({ $0.screenshotID }),
|
||||
databaseScreenshotIDs != sortedScreenshotIDsArray
|
||||
{
|
||||
// Screenshot order is incorrect, so attempt to fix by re-sorting.
|
||||
let fixedScreenshots = databaseObject.screenshots.sorted { (screenshotA, screenshotB) in
|
||||
let indexA = sortedScreenshotURLs.index(of: screenshotA.imageURL)
|
||||
let indexB = sortedScreenshotURLs.index(of: screenshotB.imageURL)
|
||||
let fixedScreenshots = databaseObject.allScreenshots.sorted { (screenshotA, screenshotB) in
|
||||
let indexA = sortedScreenshotIDs.index(of: screenshotA.screenshotID)
|
||||
let indexB = sortedScreenshotIDs.index(of: screenshotB.screenshotID)
|
||||
return indexA < indexB
|
||||
}
|
||||
|
||||
let appScreenshotURLs = fixedScreenshots.map { $0.imageURL }
|
||||
if appScreenshotURLs == sortedScreenshotURLsArray
|
||||
let appScreenshotIDs = fixedScreenshots.map { $0.screenshotID }
|
||||
if appScreenshotIDs == sortedScreenshotIDsArray
|
||||
{
|
||||
databaseObject.setScreenshots(fixedScreenshots)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Screenshots are still not in correct order, but not worth throwing error so ignore.
|
||||
print("Failed to re-sort screenshots into correct order. Expected:", sortedScreenshotURLsArray)
|
||||
print("Failed to re-sort screenshots into correct order. Expected:", sortedScreenshotIDsArray)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user