2019-05-20 21:26:01 +02:00
|
|
|
//
|
|
|
|
|
// MyAppsViewController.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 5/9/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
import Roxas
|
|
|
|
|
|
|
|
|
|
class MyAppsViewController: UITableViewController
|
|
|
|
|
{
|
|
|
|
|
private lazy var dataSource = self.makeDataSource()
|
|
|
|
|
|
|
|
|
|
private lazy var dateFormatter: DateFormatter = {
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
|
|
dateFormatter.dateStyle = .short
|
|
|
|
|
dateFormatter.timeStyle = .none
|
|
|
|
|
return dateFormatter
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
override func viewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
|
|
self.tableView.dataSource = self.dataSource
|
|
|
|
|
}
|
2019-05-20 21:40:04 +02:00
|
|
|
|
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
|
|
|
|
|
{
|
|
|
|
|
guard segue.identifier == "showAppDetail" else { return }
|
|
|
|
|
|
|
|
|
|
guard let cell = sender as? UITableViewCell, let indexPath = self.tableView.indexPath(for: cell) else { return }
|
|
|
|
|
|
|
|
|
|
let installedApp = self.dataSource.item(at: indexPath)
|
|
|
|
|
guard let app = installedApp.app else { return }
|
|
|
|
|
|
|
|
|
|
let appDetailViewController = segue.destination as! AppDetailViewController
|
|
|
|
|
appDetailViewController.app = app
|
|
|
|
|
}
|
2019-05-20 21:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extension MyAppsViewController
|
|
|
|
|
{
|
|
|
|
|
func makeDataSource() -> RSTFetchedResultsTableViewDataSource<InstalledApp>
|
|
|
|
|
{
|
|
|
|
|
let fetchRequest = InstalledApp.fetchRequest() as NSFetchRequest<InstalledApp>
|
|
|
|
|
fetchRequest.relationshipKeyPathsForPrefetching = [#keyPath(InstalledApp.app)]
|
|
|
|
|
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \InstalledApp.app?.name, ascending: true)]
|
|
|
|
|
fetchRequest.returnsObjectsAsFaults = false
|
|
|
|
|
|
|
|
|
|
let dataSource = RSTFetchedResultsTableViewDataSource(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext)
|
2019-05-20 21:36:39 +02:00
|
|
|
dataSource.proxy = self
|
2019-05-20 21:26:01 +02:00
|
|
|
dataSource.cellConfigurationHandler = { (cell, installedApp, indexPath) in
|
|
|
|
|
guard let app = installedApp.app else { return }
|
|
|
|
|
|
|
|
|
|
cell.textLabel?.text = app.name
|
|
|
|
|
|
|
|
|
|
let detailText =
|
|
|
|
|
"""
|
|
|
|
|
Signed: \(self.dateFormatter.string(from: installedApp.signedDate))
|
|
|
|
|
Expires: \(self.dateFormatter.string(from: installedApp.expirationDate))
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
cell.detailTextLabel?.numberOfLines = 2
|
|
|
|
|
cell.detailTextLabel?.text = detailText
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dataSource
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-20 21:36:39 +02:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|