From 6db5aec672ae8a4a3193ce30f24f070a03a9cd33 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 11 Apr 2022 11:59:56 -0700 Subject: [PATCH] Supports landscape app screenshots Rotates landscape screenshots before displaying them. For now, we still assume screenshots have 16:9 aspect ratio. --- AltStore.xcodeproj/project.pbxproj | 4 +++ .../App Detail/AppContentViewController.swift | 3 ++- .../Browse/BrowseCollectionViewCell.swift | 3 ++- AltStore/Types/ScreenshotProcessor.swift | 25 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 AltStore/Types/ScreenshotProcessor.swift diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 40c34294..1aee238d 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -357,6 +357,7 @@ D57F2C9426E01BC700B9FA39 /* UIDevice+Vibration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57F2C9326E01BC700B9FA39 /* UIDevice+Vibration.swift */; }; D58D5F2E26DFE68E00E55E38 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = D58D5F2D26DFE68E00E55E38 /* LaunchAtLogin */; }; D593F1942717749A006E82DE /* PatchAppOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D593F1932717749A006E82DE /* PatchAppOperation.swift */; }; + D5DAE0942804B0B80034D8D4 /* ScreenshotProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5DAE0932804B0B80034D8D4 /* ScreenshotProcessor.swift */; }; D5F2F6A92720B7C20081CCF5 /* PatchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F2F6A82720B7C20081CCF5 /* PatchViewController.swift */; }; /* End PBXBuildFile section */ @@ -816,6 +817,7 @@ D57F2C9026E0070200B9FA39 /* EnableJITOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnableJITOperation.swift; sourceTree = ""; }; D57F2C9326E01BC700B9FA39 /* UIDevice+Vibration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIDevice+Vibration.swift"; sourceTree = ""; }; D593F1932717749A006E82DE /* PatchAppOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchAppOperation.swift; sourceTree = ""; }; + D5DAE0932804B0B80034D8D4 /* ScreenshotProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotProcessor.swift; sourceTree = ""; }; D5F2F6A82720B7C20081CCF5 /* PatchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchViewController.swift; sourceTree = ""; }; EA79A60285C6AF5848AA16E9 /* Pods-AltStore.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AltStore.debug.xcconfig"; path = "Target Support Files/Pods-AltStore/Pods-AltStore.debug.xcconfig"; sourceTree = ""; }; FC3822AB1C4CF1D4CDF7445D /* Pods_AltServer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AltServer.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -979,6 +981,7 @@ children = ( BF41B807233433C100C593A3 /* LoadingState.swift */, BFB39B5B252BC10E00D1BE50 /* Managed.swift */, + D5DAE0932804B0B80034D8D4 /* ScreenshotProcessor.swift */, ); path = Types; sourceTree = ""; @@ -2559,6 +2562,7 @@ BFF0B68E23219520007A79E1 /* PatreonViewController.swift in Sources */, BFF00D302501BD7D00746320 /* Intents.intentdefinition in Sources */, BF6C336224197D700034FD24 /* NSError+AltStore.swift in Sources */, + D5DAE0942804B0B80034D8D4 /* ScreenshotProcessor.swift in Sources */, BFD2476E2284B9A500981D42 /* AppDelegate.swift in Sources */, BF41B806233423AE00C593A3 /* TabBarController.swift in Sources */, BFE00A202503097F00EB4D0C /* INInteraction+AltStore.swift in Sources */, diff --git a/AltStore/App Detail/AppContentViewController.swift b/AltStore/App Detail/AppContentViewController.swift index 8783f429..9b017073 100644 --- a/AltStore/App Detail/AppContentViewController.swift +++ b/AltStore/App Detail/AppContentViewController.swift @@ -138,7 +138,8 @@ private extension AppContentViewController } dataSource.prefetchHandler = { (imageURL, indexPath, completionHandler) in return RSTAsyncBlockOperation() { (operation) in - ImagePipeline.shared.loadImage(with: imageURL as URL, progress: nil, completion: { (response, error) in + let request = ImageRequest(url: imageURL as URL, processor: .screenshot) + ImagePipeline.shared.loadImage(with: request, progress: nil, completion: { (response, error) in guard !operation.isCancelled else { return operation.finish() } if let image = response?.image diff --git a/AltStore/Browse/BrowseCollectionViewCell.swift b/AltStore/Browse/BrowseCollectionViewCell.swift index e27b51bf..07fae19c 100644 --- a/AltStore/Browse/BrowseCollectionViewCell.swift +++ b/AltStore/Browse/BrowseCollectionViewCell.swift @@ -53,7 +53,8 @@ private extension BrowseCollectionViewCell } dataSource.prefetchHandler = { (imageURL, indexPath, completionHandler) in return RSTAsyncBlockOperation() { (operation) in - ImagePipeline.shared.loadImage(with: imageURL as URL, progress: nil, completion: { (response, error) in + let request = ImageRequest(url: imageURL as URL, processor: .screenshot) + ImagePipeline.shared.loadImage(with: request, progress: nil, completion: { (response, error) in guard !operation.isCancelled else { return operation.finish() } if let image = response?.image diff --git a/AltStore/Types/ScreenshotProcessor.swift b/AltStore/Types/ScreenshotProcessor.swift new file mode 100644 index 00000000..ce1ad8b5 --- /dev/null +++ b/AltStore/Types/ScreenshotProcessor.swift @@ -0,0 +1,25 @@ +// +// ScreenshotProcessor.swift +// AltStore +// +// Created by Riley Testut on 4/11/22. +// Copyright © 2022 Riley Testut. All rights reserved. +// + +import Nuke + +struct ScreenshotProcessor: ImageProcessing +{ + func process(image: Image, context: ImageProcessingContext) -> Image? + { + guard let cgImage = image.cgImage, image.size.width > image.size.height else { return image } + + let rotatedImage = UIImage(cgImage: cgImage, scale: image.scale, orientation: .right) + return rotatedImage + } +} + +extension ImageProcessing where Self == ScreenshotProcessor +{ + static var screenshot: Self { Self() } +}