From 3154a86b7a87c6efd83b62587fb373038bf5aa9e Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 20 May 2019 21:36:39 +0200 Subject: [PATCH] =?UTF-8?q?Adds=20support=20for=20=E2=80=9Cdeleting?= =?UTF-8?q?=E2=80=9D=20installed=20apps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Temporary, because later we won’t be able to actually uninstall apps from within AltStore --- AltStore/My Apps/MyAppsViewController.swift | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index 5fe2cbd7..886d3dc4 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -38,6 +38,7 @@ private extension MyAppsViewController fetchRequest.returnsObjectsAsFaults = false let dataSource = RSTFetchedResultsTableViewDataSource(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext) + dataSource.proxy = self dataSource.cellConfigurationHandler = { (cell, installedApp, indexPath) in guard let app = installedApp.app else { return } @@ -56,3 +57,27 @@ private extension MyAppsViewController return dataSource } } + +extension MyAppsViewController +{ + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) + { + guard editingStyle == .delete else { return } + + let installedApp = self.dataSource.item(at: indexPath) + + DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in + let installedApp = context.object(with: installedApp.objectID) as! InstalledApp + context.delete(installedApp) + + do + { + try context.save() + } + catch + { + print("Failed to delete installed app.", error) + } + } + } +}