Uses alternate app icon for AltStore in My Apps, if one is chosen

This commit is contained in:
Riley Testut
2024-02-15 14:19:34 -06:00
committed by Magesh K
parent b8b32d501c
commit ac62612a18
3 changed files with 58 additions and 0 deletions

View File

@@ -111,6 +111,8 @@ class MyAppsViewController: UICollectionViewController, PeekPopPreviewing
}
(self as PeekPopPreviewing).registerForPreviewing(with: self, sourceView: self.collectionView)
NotificationCenter.default.addObserver(self, selector: #selector(MyAppsViewController.didChangeAppIcon(_:)), name: UIApplication.didChangeAppIconNotification, object: nil)
}
override func viewIsAppearing(_ animated: Bool)
@@ -1593,6 +1595,43 @@ private extension MyAppsViewController
sender.endRefreshing()
}
}
@objc func didChangeAppIcon(_ notification: Notification)
{
guard let altStoreApp = InstalledApp.fetchAltStore(in: DatabaseManager.shared.viewContext) else { return }
// Remove previous icon from cache.
self.activeAppsDataSource.prefetchItemCache.removeObject(forKey: altStoreApp)
self.inactiveAppsDataSource.prefetchItemCache.removeObject(forKey: altStoreApp)
if let indexPath = self.activeAppsDataSource.fetchedResultsController.indexPath(forObject: altStoreApp)
{
let indexPath = IndexPath(item: indexPath.item, section: Section.activeApps.rawValue)
if #available(iOS 15, *)
{
self.collectionView.reconfigureItems(at: [indexPath])
}
else
{
self.collectionView.reloadItems(at: [indexPath])
}
}
if let indexPath = self.inactiveAppsDataSource.fetchedResultsController.indexPath(forObject: altStoreApp)
{
let indexPath = IndexPath(item: indexPath.item, section: Section.inactiveApps.rawValue)
if #available(iOS 15, *)
{
self.collectionView.reconfigureItems(at: [indexPath])
}
else
{
self.collectionView.reloadItems(at: [indexPath])
}
}
}
}
extension MyAppsViewController

View File

@@ -13,6 +13,11 @@ import AltSign
import AltStoreCore
import Roxas
extension UIApplication
{
static let didChangeAppIconNotification = Notification.Name("io.altstore.AppManager.didChangeAppIcon")
}
private final class AltIcon: Decodable
{
var name: String
@@ -190,6 +195,10 @@ extension AltAppIconsViewController
alertController.addAction(.ok)
self.present(alertController, animated: true)
}
else
{
NotificationCenter.default.post(name: UIApplication.didChangeAppIconNotification, object: icon)
}
if let selectedIndexPath = self.collectionView.indexPathsForSelectedItems?.first
{

View File

@@ -159,6 +159,16 @@ public extension InstalledApp
func loadIcon(completion: @escaping (Result<UIImage?, Error>) -> Void)
{
if self.bundleIdentifier == StoreApp.altstoreAppID, let iconName = UIApplication.alt_shared?.alternateIconName
{
// Use alternate app icon for AltStore, if one is chosen.
let image = UIImage(named: iconName)
completion(.success(image))
return
}
let hasAlternateIcon = self.hasAlternateIcon
let alternateIconURL = self.alternateIconURL
let fileURL = self.fileURL