From 75e398822f9c1541926d98f9c8bf5ae47f13a258 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 30 Jul 2019 16:54:44 -0700 Subject: [PATCH] [AltStore] Adds LaunchViewController to async load database before UI appears --- AltStore.xcodeproj/project.pbxproj | 4 +++ AltStore/AppDelegate.swift | 15 --------- AltStore/Base.lproj/Main.storyboard | 20 ++++++++++- AltStore/LaunchViewController.swift | 51 +++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 AltStore/LaunchViewController.swift diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 6b4651ed..1911a671 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -176,6 +176,7 @@ BFDB6A0B22AAEDB7007EA6D6 /* Operation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDB6A0A22AAEDB7007EA6D6 /* Operation.swift */; }; BFDB6A0D22AAFC1A007EA6D6 /* OperationError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDB6A0C22AAFC19007EA6D6 /* OperationError.swift */; }; BFDB6A0F22AB2776007EA6D6 /* SendAppOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDB6A0E22AB2776007EA6D6 /* SendAppOperation.swift */; }; + BFE338E822F10E56002E24B9 /* LaunchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFE338E722F10E56002E24B9 /* LaunchViewController.swift */; }; BFE6325A22A83BEB00F30809 /* Authentication.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BFE6325922A83BEB00F30809 /* Authentication.storyboard */; }; BFE6325C22A83C0100F30809 /* AuthenticationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFE6325B22A83C0100F30809 /* AuthenticationViewController.swift */; }; BFE6325E22A8497000F30809 /* SelectTeamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFE6325D22A8497000F30809 /* SelectTeamViewController.swift */; }; @@ -426,6 +427,7 @@ BFDB6A0A22AAEDB7007EA6D6 /* Operation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Operation.swift; sourceTree = ""; }; BFDB6A0C22AAFC19007EA6D6 /* OperationError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationError.swift; sourceTree = ""; }; BFDB6A0E22AB2776007EA6D6 /* SendAppOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendAppOperation.swift; sourceTree = ""; }; + BFE338E722F10E56002E24B9 /* LaunchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchViewController.swift; sourceTree = ""; }; BFE6325922A83BEB00F30809 /* Authentication.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Authentication.storyboard; sourceTree = ""; }; BFE6325B22A83C0100F30809 /* AuthenticationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationViewController.swift; sourceTree = ""; }; BFE6325D22A8497000F30809 /* SelectTeamViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectTeamViewController.swift; sourceTree = ""; }; @@ -760,6 +762,7 @@ children = ( BF219A7E22CAC431007676A6 /* AltStore.entitlements */, BFD2476D2284B9A500981D42 /* AppDelegate.swift */, + BFE338E722F10E56002E24B9 /* LaunchViewController.swift */, BFD247732284B9A500981D42 /* Main.storyboard */, BFE6325822A83BA800F30809 /* Authentication */, BF9ABA4322DCFF33008935CF /* Browse */, @@ -1293,6 +1296,7 @@ BF770E6722BD57C4002A40FE /* BackgroundTaskManager.swift in Sources */, BF3D64B022E8D4B800E9056B /* AppContentViewControllerCells.swift in Sources */, BFBBE2DD22931B20002097FA /* AltStore.xcdatamodeld in Sources */, + BFE338E822F10E56002E24B9 /* LaunchViewController.swift in Sources */, BFE6325C22A83C0100F30809 /* AuthenticationViewController.swift in Sources */, BFB1169B2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift in Sources */, BF9ABA4722DD0638008935CF /* BrowseCollectionViewCell.swift in Sources */, diff --git a/AltStore/AppDelegate.swift b/AltStore/AppDelegate.swift index 4b50c50b..e35f3ce1 100644 --- a/AltStore/AppDelegate.swift +++ b/AltStore/AppDelegate.swift @@ -53,21 +53,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ServerManager.shared.startDiscovering() - DatabaseManager.shared.start { (error) in - if let error = error - { - print("Failed to start DatabaseManager.", error) - } - else - { - print("Started DatabaseManager") - - DispatchQueue.main.async { - AppManager.shared.update() - } - } - } - if UserDefaults.standard.firstLaunch == nil { Keychain.shared.reset() diff --git a/AltStore/Base.lproj/Main.storyboard b/AltStore/Base.lproj/Main.storyboard index a8f1be41..59b8353c 100644 --- a/AltStore/Base.lproj/Main.storyboard +++ b/AltStore/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -11,6 +11,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/AltStore/LaunchViewController.swift b/AltStore/LaunchViewController.swift new file mode 100644 index 00000000..5fb949ea --- /dev/null +++ b/AltStore/LaunchViewController.swift @@ -0,0 +1,51 @@ +// +// LaunchViewController.swift +// AltStore +// +// Created by Riley Testut on 7/30/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit +import Roxas + +class LaunchViewController: RSTLaunchViewController +{ + override var launchConditions: [RSTLaunchCondition] { + let isDatabaseStarted = RSTLaunchCondition(condition: { DatabaseManager.shared.isStarted }) { (completionHandler) in + DatabaseManager.shared.start(completionHandler: completionHandler) + } + + return [isDatabaseStarted] + } +} + +extension LaunchViewController +{ + override func handleLaunchError(_ error: Error) + { + do + { + throw error + } + catch let error as NSError + { + let title = error.userInfo[NSLocalizedFailureErrorKey] as? String ?? NSLocalizedString("Unable to Launch AltStore", comment: "") + + let alertController = UIAlertController(title: title, message: error.localizedDescription, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: NSLocalizedString("Retry", comment: ""), style: .default, handler: { (action) in + self.handleLaunchConditions() + })) + self.present(alertController, animated: true, completion: nil) + } + } + + override func finishLaunching() + { + super.finishLaunching() + + AppManager.shared.update() + + self.performSegue(withIdentifier: "finishLaunching", sender: nil) + } +}