mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-06 14:07:32 +00:00
refactor(ios/engine): package install moved out of package welcome view
This commit is contained in:
parent
1b04151a0d
commit
8c0828ade6
3 changed files with 51 additions and 20 deletions
|
|
@ -472,6 +472,7 @@ public class KeymanPackage {
|
|||
*/
|
||||
public class TypedKeymanPackage<TypedLanguageResource: LanguageResource>: KeymanPackage {
|
||||
public private(set) var installables: [[TypedLanguageResource]] = []
|
||||
typealias Resource = TypedLanguageResource
|
||||
|
||||
internal func setInstallableResourceSets<Resource: KMPResource>(for kmpResources: [Resource]) where
|
||||
TypedLanguageResource: KMPInitializableLanguageResource {
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
import Foundation
|
||||
import WebKit
|
||||
|
||||
public class PackageInstallViewController: UIViewController {
|
||||
public typealias CompletionHandler = (Error?) -> Void
|
||||
public class PackageInstallViewController<Resource: LanguageResource>: UIViewController {
|
||||
public typealias CompletionHandler = ([Resource.FullID]?) -> Void
|
||||
|
||||
let package: KeymanPackage
|
||||
let package: Resource.Package
|
||||
var wkWebView: WKWebView?
|
||||
let completionHandler: CompletionHandler
|
||||
let isCustom: Bool
|
||||
|
||||
public init(for package: KeymanPackage, isCustom: Bool, completionHandler: @escaping CompletionHandler) {
|
||||
public init(for package: Resource.Package, isCustom: Bool, completionHandler: @escaping CompletionHandler) {
|
||||
self.package = package
|
||||
self.completionHandler = completionHandler
|
||||
self.isCustom = isCustom
|
||||
|
|
@ -59,16 +59,20 @@ public class PackageInstallViewController: UIViewController {
|
|||
}
|
||||
|
||||
@objc func cancelBtnHandler() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
dismiss(animated: true, completion: {
|
||||
self.completionHandler(nil)
|
||||
})
|
||||
}
|
||||
|
||||
@objc func installBtnHandler() {
|
||||
dismiss(animated: true, completion: {
|
||||
do {
|
||||
try ResourceFileManager.shared.finalizePackageInstall(self.package, isCustom: self.isCustom)
|
||||
self.completionHandler(nil)
|
||||
} catch {
|
||||
self.completionHandler(error)
|
||||
// A stop-gap pending further changes.
|
||||
let defaultResource = self.package.installableResourceSets[0] as! [Resource]
|
||||
switch self.package.resourceType() {
|
||||
case .keyboard:
|
||||
self.completionHandler([defaultResource[0].typedFullID])
|
||||
case .lexicalModel:
|
||||
self.completionHandler(defaultResource.map { $0.typedFullID })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,26 +199,52 @@ public class ResourceFileManager {
|
|||
}
|
||||
}
|
||||
|
||||
public func promptPackageInstall(of package: KeymanPackage,
|
||||
internal func typedPromptForPackageInstall<Resource: LanguageResource, Package: TypedKeymanPackage<Resource>>(
|
||||
of package: Package,
|
||||
in rootVC: UIViewController,
|
||||
isCustom: Bool,
|
||||
successHandler: ((KeymanPackage) -> Void)? = nil) {
|
||||
let vc = PackageInstallViewController(for: package, isCustom: isCustom, completionHandler: { error in
|
||||
if let err = error {
|
||||
if let kmpError = err as? KMPError {
|
||||
let alert = self.buildKMPError(kmpError)
|
||||
rootVC.present(alert, animated: true, completion: nil)
|
||||
successHandler: ((Package) -> Void)? = nil) -> PackageInstallViewController<Resource>
|
||||
where Package == Resource.Package {
|
||||
return PackageInstallViewController(for: package, isCustom: isCustom, completionHandler: { fullIDs in
|
||||
|
||||
if let fullIDs = fullIDs {
|
||||
do {
|
||||
//try ResourceFileManager.shared.finalizePackageInstall(self.package, isCustom: self.isCustom)
|
||||
try ResourceFileManager.shared.install(resourcesWithIDs: fullIDs, from: package)
|
||||
} catch {
|
||||
if let kmpError = error as? KMPError {
|
||||
let alert = self.buildKMPError(kmpError)
|
||||
rootVC.present(alert, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
let alert = self.buildSimpleAlert(title: "Success", message: "Installed successfully.", completionHandler: {
|
||||
successHandler?(package)
|
||||
})
|
||||
rootVC.present(alert, animated: true, completion: nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let nvc = UINavigationController.init(rootViewController: vc)
|
||||
rootVC.present(nvc, animated: true, completion: nil)
|
||||
public func promptPackageInstall(of package: KeymanPackage,
|
||||
in rootVC: UIViewController,
|
||||
isCustom: Bool,
|
||||
successHandler: ((KeymanPackage) -> Void)? = nil) {
|
||||
var vc: UIViewController? = nil
|
||||
if let kbdPackage = package as? KeyboardKeymanPackage {
|
||||
vc = typedPromptForPackageInstall(of: kbdPackage, in: rootVC, isCustom: isCustom) { package in
|
||||
successHandler?(package)
|
||||
}
|
||||
} else if let lmPackage = package as? LexicalModelKeymanPackage {
|
||||
vc = typedPromptForPackageInstall(of: lmPackage, in: rootVC, isCustom: isCustom) { package in
|
||||
successHandler?(package)
|
||||
}
|
||||
}
|
||||
|
||||
if let vc = vc {
|
||||
let nvc = UINavigationController.init(rootViewController: vc)
|
||||
rootVC.present(nvc, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
public func buildKMPError(_ error: KMPError) -> UIAlertController {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue