mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-18 19:23:43 +01:00
fix: Refreshing via Xcode would cause a crash here
This commit is contained in:
@@ -1015,120 +1015,129 @@ private extension AppManager
|
|||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeAppExtensions(from application: ALTApplication, existingApp: InstalledApp?, extensions: Set<ALTApplication>, _ presentingViewController: UIViewController?, completion: @escaping (Result<Void, Error>) -> Void)
|
func removeAppExtensions(
|
||||||
{
|
from application: ALTApplication,
|
||||||
|
existingApp: InstalledApp?,
|
||||||
|
extensions: Set<ALTApplication>,
|
||||||
|
_ presentingViewController: UIViewController?,
|
||||||
|
completion: @escaping (Result<Void, Error>) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
//App-Extensions: Ensure existing app's extensions and currently installing app's extensions must match
|
// App-Extensions: Ensure existing app's extensions and currently installing app's extensions must match
|
||||||
let existingAppEx: Set<InstalledExtension> = existingApp?.appExtensions ?? Set()
|
if let existingApp {
|
||||||
let currentAppEx: Set<ALTApplication> = application.appExtensions
|
_ = RSTAsyncBlockOperation { _ in
|
||||||
|
let existingAppEx: Set<InstalledExtension> = existingApp.appExtensions
|
||||||
|
let currentAppEx: Set<ALTApplication> = application.appExtensions
|
||||||
|
|
||||||
let currentAppExNames = currentAppEx.map{ appEx in appEx.bundleIdentifier}
|
let currentAppExNames = currentAppEx.map{ appEx in appEx.bundleIdentifier}
|
||||||
let existingAppExNames = existingAppEx.map{ appEx in appEx.bundleIdentifier}
|
let existingAppExNames = existingAppEx.map{ appEx in appEx.bundleIdentifier}
|
||||||
|
|
||||||
let excessExtensions = currentAppEx.filter{
|
let excessExtensions = currentAppEx.filter{
|
||||||
!(existingAppExNames.contains($0.bundleIdentifier))
|
!(existingAppExNames.contains($0.bundleIdentifier))
|
||||||
}
|
}
|
||||||
|
|
||||||
let isMatching = (currentAppEx.count == existingAppEx.count) && excessExtensions.isEmpty
|
|
||||||
let diagnosticsMsg = "AppManager.removeAppExtensions: App Extensions in existingApp and currentApp are matching: \(isMatching)\n"
|
let isMatching = (currentAppEx.count == existingAppEx.count) && excessExtensions.isEmpty
|
||||||
+ "AppManager.removeAppExtensions: existingAppEx: \(existingAppExNames); currentAppEx: \(String(describing: currentAppExNames))\n"
|
let diagnosticsMsg = "AppManager.removeAppExtensions: App Extensions in existingApp and currentApp are matching: \(isMatching)\n"
|
||||||
print(diagnosticsMsg)
|
+ "AppManager.removeAppExtensions: existingAppEx: \(existingAppExNames); currentAppEx: \(String(describing: currentAppExNames))\n"
|
||||||
|
print(diagnosticsMsg)
|
||||||
// if background mode, then remove only the excess extensions
|
|
||||||
guard let presentingViewController: UIViewController = presentingViewController else {
|
|
||||||
// perform silent extensions cleanup for those that aren't already present in existing app
|
// if background mode, then remove only the excess extensions
|
||||||
print("\n Performing background mode Extensions removal \n")
|
guard let presentingViewController: UIViewController = presentingViewController else {
|
||||||
print("AppManager.removeAppExtensions: Excess Extensions: \(excessExtensions)")
|
// perform silent extensions cleanup for those that aren't already present in existing app
|
||||||
|
print("\n Performing background mode Extensions removal \n")
|
||||||
do {
|
print("AppManager.removeAppExtensions: Excess Extensions: \(excessExtensions)")
|
||||||
for appExtension in excessExtensions {
|
|
||||||
print("Deleting extension \(appExtension.bundleIdentifier)")
|
do {
|
||||||
try FileManager.default.removeItem(at: appExtension.fileURL)
|
for appExtension in excessExtensions {
|
||||||
|
print("Deleting extension \(appExtension.bundleIdentifier)")
|
||||||
|
try FileManager.default.removeItem(at: appExtension.fileURL)
|
||||||
|
}
|
||||||
|
return completion(.success(()))
|
||||||
|
} catch {
|
||||||
|
return completion(.failure(error))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return completion(.success(()))
|
|
||||||
} catch {
|
|
||||||
return completion(.failure(error))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guard !application.appExtensions.isEmpty else { return completion(.success(())) }
|
guard !application.appExtensions.isEmpty else { return completion(.success(())) }
|
||||||
|
|
||||||
let firstSentence: String
|
DispatchQueue.main.async {
|
||||||
|
let firstSentence: String
|
||||||
|
|
||||||
if UserDefaults.standard.activeAppLimitIncludesExtensions
|
if UserDefaults.standard.activeAppLimitIncludesExtensions
|
||||||
{
|
|
||||||
firstSentence = NSLocalizedString("Non-developer Apple IDs are limited to 3 active apps and app extensions.", comment: "")
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
firstSentence = NSLocalizedString("Non-developer Apple IDs are limited to creating 10 App IDs per week.", comment: "")
|
|
||||||
}
|
|
||||||
|
|
||||||
let message = firstSentence + " " + NSLocalizedString("Would you like to remove this app's extensions so they don't count towards your limit? There are \(extensions.count) Extensions", comment: "")
|
|
||||||
|
|
||||||
let alertController = UIAlertController(title: NSLocalizedString("App Contains Extensions", comment: ""), message: message, preferredStyle: .alert)
|
|
||||||
alertController.addAction(UIAlertAction(title: UIAlertAction.cancel.title, style: UIAlertAction.cancel.style, handler: { (action) in
|
|
||||||
completion(.failure(OperationError.cancelled))
|
|
||||||
}))
|
|
||||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Keep App Extensions", comment: ""), style: .default) { (action) in
|
|
||||||
completion(.success(()))
|
|
||||||
})
|
|
||||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Remove App Extensions", comment: ""), style: .destructive) { (action) in
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
for appExtension in application.appExtensions
|
firstSentence = NSLocalizedString("Non-developer Apple IDs are limited to 3 active apps and app extensions.", comment: "")
|
||||||
{
|
}
|
||||||
print("Deleting extension \(appExtension.bundleIdentifier)")
|
else
|
||||||
try FileManager.default.removeItem(at: appExtension.fileURL)
|
{
|
||||||
}
|
firstSentence = NSLocalizedString("Non-developer Apple IDs are limited to creating 10 App IDs per week.", comment: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = firstSentence + " " + NSLocalizedString("Would you like to remove this app's extensions so they don't count towards your limit? There are \(extensions.count) Extensions", comment: "")
|
||||||
|
|
||||||
|
let alertController = UIAlertController(title: NSLocalizedString("App Contains Extensions", comment: ""), message: message, preferredStyle: .alert)
|
||||||
|
alertController.addAction(UIAlertAction(title: UIAlertAction.cancel.title, style: UIAlertAction.cancel.style, handler: { (action) in
|
||||||
|
completion(.failure(OperationError.cancelled))
|
||||||
|
}))
|
||||||
|
alertController.addAction(UIAlertAction(title: NSLocalizedString("Keep App Extensions", comment: ""), style: .default) { (action) in
|
||||||
completion(.success(()))
|
completion(.success(()))
|
||||||
}
|
})
|
||||||
catch
|
alertController.addAction(UIAlertAction(title: NSLocalizedString("Remove App Extensions", comment: ""), style: .destructive) { (action) in
|
||||||
{
|
|
||||||
completion(.failure(error))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Choose App Extensions", comment: ""), style: .default) { (action) in
|
|
||||||
let popoverContentController = AppExtensionViewHostingController(extensions: extensions) { (selection) in
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
for appExtension in selection
|
for appExtension in application.appExtensions
|
||||||
{
|
{
|
||||||
print("Deleting extension \(appExtension.bundleIdentifier)")
|
print("Deleting extension \(appExtension.bundleIdentifier)")
|
||||||
|
|
||||||
try FileManager.default.removeItem(at: appExtension.fileURL)
|
try FileManager.default.removeItem(at: appExtension.fileURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
completion(.success(()))
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
completion(.failure(error))
|
completion(.failure(error))
|
||||||
}
|
}
|
||||||
return nil
|
})
|
||||||
|
|
||||||
|
if let presentingViewController {
|
||||||
|
alertController.addAction(UIAlertAction(title: NSLocalizedString("Choose App Extensions", comment: ""), style: .default) { (action) in
|
||||||
|
let popoverContentController = AppExtensionViewHostingController(extensions: extensions) { (selection) in
|
||||||
|
do
|
||||||
|
{
|
||||||
|
for appExtension in selection
|
||||||
|
{
|
||||||
|
print("Deleting extension \(appExtension.bundleIdentifier)")
|
||||||
|
|
||||||
|
try FileManager.default.removeItem(at: appExtension.fileURL)
|
||||||
|
}
|
||||||
|
completion(.success(()))
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
completion(.failure(error))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let suiview = popoverContentController.view!
|
||||||
|
suiview.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
||||||
|
popoverContentController.modalPresentationStyle = .popover
|
||||||
|
|
||||||
|
if let popoverPresentationController = popoverContentController.popoverPresentationController {
|
||||||
|
popoverPresentationController.sourceView = presentingViewController.view
|
||||||
|
popoverPresentationController.sourceRect = CGRect(x: 50, y: 50, width: 4, height: 4)
|
||||||
|
popoverPresentationController.delegate = popoverContentController
|
||||||
|
|
||||||
|
presentingViewController.present(popoverContentController, animated: true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
presentingViewController.present(alertController, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
let suiview = popoverContentController.view!
|
|
||||||
suiview.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
|
|
||||||
popoverContentController.modalPresentationStyle = .popover
|
|
||||||
|
|
||||||
if let popoverPresentationController = popoverContentController.popoverPresentationController {
|
|
||||||
popoverPresentationController.sourceView = presentingViewController.view
|
|
||||||
popoverPresentationController.sourceRect = CGRect(x: 50, y: 50, width: 4, height: 4)
|
|
||||||
popoverPresentationController.delegate = popoverContentController
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
presentingViewController.present(popoverContentController, animated: true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
presentingViewController.present(alertController, animated: true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user