diff --git a/ios/engine/KMEI/KeymanEngine.xcodeproj/project.pbxproj b/ios/engine/KMEI/KeymanEngine.xcodeproj/project.pbxproj index 419b659897..8659926949 100644 --- a/ios/engine/KMEI/KeymanEngine.xcodeproj/project.pbxproj +++ b/ios/engine/KMEI/KeymanEngine.xcodeproj/project.pbxproj @@ -87,7 +87,6 @@ C059FCBD1FD9266C00BD1A64 /* XCGLogger.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1687ACCC1FD8DE5300926D69 /* XCGLogger.framework */; }; C059FCBE1FD9266C00BD1A64 /* Zip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 165C8B8B1FD8220600D4A78D /* Zip.framework */; }; C05B14331FD914870082A316 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05B14321FD914870082A316 /* Log.swift */; }; - C05F432D1FBD5A4C0058CBD4 /* KeyboardAPICall.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05F432C1FBD5A4C0058CBD4 /* KeyboardAPICall.swift */; }; C05F43311FBD62550058CBD4 /* JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05F43301FBD62550058CBD4 /* JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift */; }; C06085B41F9485E40057E5B9 /* UIButton+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06085B31F9485E40057E5B9 /* UIButton+Helpers.swift */; }; C06D372F1F81F4E100F61AE0 /* KeymanEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = C06D372D1F81F4E100F61AE0 /* KeymanEngine.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -393,7 +392,6 @@ C04C2A6C1F6B7D9A00BA42B6 /* LanguageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LanguageViewController.swift; sourceTree = ""; }; C055E6EA1F99ED090035C2DD /* RegisteredFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisteredFont.swift; sourceTree = ""; }; C05B14321FD914870082A316 /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = ""; }; - C05F432C1FBD5A4C0058CBD4 /* KeyboardAPICall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardAPICall.swift; sourceTree = ""; }; C05F43301FBD62550058CBD4 /* JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift"; sourceTree = ""; }; C06085B31F9485E40057E5B9 /* UIButton+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Helpers.swift"; sourceTree = ""; }; C06D372B1F81F4E100F61AE0 /* KeymanEngine.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KeymanEngine.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -739,7 +737,6 @@ 9A079E3C223B5FAF00581263 /* InstallableLexicalModel.swift */, C055E6EA1F99ED090035C2DD /* RegisteredFont.swift */, C007C4641F9F52D8006461B9 /* LanguagesAPICall.swift */, - C05F432C1FBD5A4C0058CBD4 /* KeyboardAPICall.swift */, 9A4609982242047400B0BFD1 /* LexicalModelAPICall.swift */, C042ED5C1FC6A65A001D82F4 /* Version.swift */, C08E69901FDA6F6F0026056B /* FullKeyboardID.swift */, @@ -1405,7 +1402,6 @@ C06D37411F81F5C400F61AE0 /* LanguageViewController.swift in Sources */, C06D37421F81F5C400F61AE0 /* KeyboardPickerButton.swift in Sources */, 165EB3A12098993900040A69 /* KeyboardError.swift in Sources */, - C05F432D1FBD5A4C0058CBD4 /* KeyboardAPICall.swift in Sources */, CE7ADD6623DE89FC00BC9A00 /* Alerts.swift in Sources */, CE754A0423D162E90030CB79 /* ResourceInfoViewController.swift in Sources */, C055E6EB1F99ED090035C2DD /* RegisteredFont.swift in Sources */, diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift b/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift index fd66191987..640680f039 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift @@ -1017,10 +1017,6 @@ public class Manager: NSObject, UIGestureRecognizerDelegate { * the data for apps built on older versions of KMEI, though. */ - public func downloadKeyboard(from url: URL) { - ResourceDownloadManager.shared.downloadKeyboard(from: url) - } - public func downloadKeyboard(withID: String, languageID: String, isUpdate: Bool, fetchRepositoryIfNeeded: Bool = true) { ResourceDownloadManager.shared.downloadKeyboard(withID: withID, languageID: languageID, @@ -1028,11 +1024,6 @@ public class Manager: NSObject, UIGestureRecognizerDelegate { fetchRepositoryIfNeeded: fetchRepositoryIfNeeded) } - // A new API, but it so closely parallels downloadKeyboard that we should add a 'helper' handler here. - public func downloadLexicalModel(from url: URL) { - ResourceDownloadManager.shared.downloadLexicalModel(from: url) - } - // A new API, but it so closely parallels downloadKeyboard that we should add a 'helper' handler here. public func downloadLexicalModel(withID: String, languageID: String, isUpdate: Bool, fetchRepositoryIfNeeded: Bool = true) { ResourceDownloadManager.shared.downloadLexicalModel(withID: withID, diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Model/KeyboardAPICall.swift b/ios/engine/KMEI/KeymanEngine/Classes/Model/KeyboardAPICall.swift deleted file mode 100644 index 9dc5eefcd5..0000000000 --- a/ios/engine/KMEI/KeymanEngine/Classes/Model/KeyboardAPICall.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// KeyboardAPICall.swift -// KeymanEngine -// -// Created by Gabriel Wong on 2017-11-16. -// Copyright © 2017 SIL International. All rights reserved. -// - -import Foundation - -struct KeyboardAPICall: Codable { - let options: Options - let keyboard: Keyboard -} diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceDownloadManager.swift b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceDownloadManager.swift index c77f9bb9fa..1fac7f37a1 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceDownloadManager.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceDownloadManager.swift @@ -163,64 +163,6 @@ public class ResourceDownloadManager { .map({ options.fontBaseURL.appendingPathComponent($0) }) } - /// Downloads a custom keyboard from the URL (old ad-hoc method) - /// - Parameters: - /// - url: URL to a JSON description of the keyboard - public func downloadKeyboard(from url: URL) { - guard downloader.hasConnection() else { - let error = NSError(domain: "Keyman", code: 0, - userInfo: [NSLocalizedDescriptionKey: "No connection"]) - downloader.downloadFailed(forKeyboards: [], error: error) - return - } - - guard let data = try? Data(contentsOf: url) else { - let error = NSError(domain: "Keyman", code: 0, - userInfo: [NSLocalizedDescriptionKey: "Failed to fetch JSON file"]) - downloader.downloadFailed(forKeyboards: [], error: error) - return - } - - decodeKeyboardData(data, decodingStrategy: .ios8601WithFallback) - } - - // Step 2 of old ad-hoc process. May be worth preserving for use with .kmp packages. - private func decodeKeyboardData(_ data: Data, decodingStrategy : JSONDecoder.DateDecodingStrategy) { - let decoder = JSONDecoder() - decoder.dateDecodingStrategy = decodingStrategy - - if let keyboard = try? decoder.decode(KeyboardAPICall.self, from: data) { - downloadKeyboard(keyboard) - } else { - decoder.dateDecodingStrategy = .iso8601WithoutTimezone - if let keyboard = try? decoder.decode(KeyboardAPICall.self, from: data) { - downloadKeyboard(keyboard) - } else { - decoder.dateDecodingStrategy = .ios8601WithMilliseconds - do { - let keyboard = try decoder.decode(KeyboardAPICall.self, from: data) - downloadKeyboard(keyboard) - } catch { - downloader.downloadFailed(forKeyboards: [], error: error) - } - } - } - } - - // Step 3 of the old ad-hoc process. - /// Assumes that Keyboard has font and oskFont set and ignores fonts contained in Language. - private func downloadKeyboard(_ keyboardAPI: KeyboardAPICall) { - let keyboard = keyboardAPI.keyboard - let installableKeyboards = keyboard.languages!.map { language in - InstallableKeyboard(keyboard: keyboard, language: language, isCustom: true) - } - - let filename = keyboard.filename - let isUpdate = Storage.active.userDefaults.userKeyboards?.contains { $0.id == keyboard.id } ?? false - - _ = downloadKeyboardCore(withMetadata: installableKeyboards, asActivity: isUpdate ? .update : .download, withFilename: filename, withOptions: keyboardAPI.options) - } - /// - Returns: The current state for a keyboard public func stateForKeyboard(withID keyboardID: String) -> KeyboardState { // Needs validation - I don't think this if-condition can be met in Keyman's current state @@ -394,79 +336,6 @@ public class ResourceDownloadManager { _ = downloadLexicalModelCore(withMetadata: [lexicalModel], asActivity: isUpdate ? .update : .download, fromPath: URL.init(string: filename)!) } - /// Downloads a custom lexical model from the URL - /// - Parameters: - /// - url: URL to a JSON description of the lexical model - public func downloadLexicalModel(from url: URL) { - guard downloader.hasConnection() else { - let error = NSError(domain: "Keyman", code: 0, - userInfo: [NSLocalizedDescriptionKey: "No connection"]) - downloader.downloadFailed(forKeyboards: [], error: error) //??? forLexicalModels - return - } - - guard let data = try? Data(contentsOf: url) else { - let error = NSError(domain: "Keyman", code: 0, - userInfo: [NSLocalizedDescriptionKey: "Failed to fetch JSON file"]) - downloader.downloadFailed(forKeyboards: [], error: error) //??? forLexicalModels - return - } - - decodeLexicalModelData(data, decodingStrategy: .ios8601WithFallback) - } - - // This should be usable as part of the .model.kmp processing process; we have a kmp.json, after all. - private func decodeLexicalModelData(_ data: Data, decodingStrategy : JSONDecoder.DateDecodingStrategy) { - let decoder = JSONDecoder() - decoder.dateDecodingStrategy = decodingStrategy - - if let lexicalModel = try? decoder.decode(LexicalModelAPICall.self, from: data) { - downloadLexicalModel(lexicalModel) - } else { - decoder.dateDecodingStrategy = .iso8601WithoutTimezone - if let lexicalModel = try? decoder.decode(LexicalModelAPICall.self, from: data) { - downloadLexicalModel(lexicalModel) - } else { - decoder.dateDecodingStrategy = .ios8601WithMilliseconds - do { - let lexicalModel = try decoder.decode(LexicalModelAPICall.self, from: data) - downloadLexicalModel(lexicalModel) - } catch { - downloader.downloadFailed(forKeyboards: [], error: error) //??? forLexicalModels - } - } - } - } - - // Accordingly, this could be retooled to help with .model.kmp files too. - private func downloadLexicalModel(_ lexicalModelAPI: LexicalModelAPICall) { - let lexicalModel = lexicalModelAPI.lexicalModels[0] - let installableLexicalModels = lexicalModel.languages.map { language in - InstallableLexicalModel(lexicalModel: lexicalModel, languageID: language, isCustom: true) - } - - let packageFilename = lexicalModel.packageFilename - let lexicalModelURL = URL(string: "https://api.keyman.com/model")!.appendingPathComponent(packageFilename) - - do { - try FileManager.default.createDirectory(at: Storage.active.lexicalModelDir(forID: lexicalModel.id), - withIntermediateDirectories: true) - } catch { - log.error("Could not create dir for download: \(error)") - return - } - - let isUpdate = Storage.active.userDefaults.userLexicalModels?.contains { $0.id == lexicalModel.id } ?? false - - if let batch = buildLexicalModelDownloadBatch(for: installableLexicalModels[0], withFilename: lexicalModelURL, asActivity: isUpdate ? .update : .download) { - if !downloader.canExecute(batch) { - return - } - - downloader.queue(batch) - } - } - /// - Returns: The current state for a lexical model //TODO: rename KeyboardState to ResourceState? so it can be used with both keybaoards and lexical models without confusion public func stateForLexicalModel(withID lexicalModelID: String) -> KeyboardState { diff --git a/ios/engine/KMEI/KeymanEngineDemo/MainViewController.swift b/ios/engine/KMEI/KeymanEngineDemo/MainViewController.swift index fe75be2854..e05cd507ad 100644 --- a/ios/engine/KMEI/KeymanEngineDemo/MainViewController.swift +++ b/ios/engine/KMEI/KeymanEngineDemo/MainViewController.swift @@ -248,11 +248,6 @@ class MainViewController: UIViewController, UIAlertViewDelegate, TextViewDelegat textView1.becomeFirstResponder() } - func downloadCustomKeyboard() { - let url = URL(string: "https://sites.google.com/site/hebrewsoftware/files/yiddish_zc-1.0.json") - ResourceDownloadManager.shared.downloadKeyboard(from: url!) - } - func showActivityIndicator() { if parent?.view.viewWithTag(-1) != nil { return diff --git a/ios/keyman/Keyman/Keyman/MainViewController.swift b/ios/keyman/Keyman/Keyman/MainViewController.swift index 169387ea23..5adf2c9d4e 100644 --- a/ios/keyman/Keyman/Keyman/MainViewController.swift +++ b/ios/keyman/Keyman/Keyman/MainViewController.swift @@ -837,27 +837,7 @@ class MainViewController: UIViewController, TextViewDelegate, UIActionSheetDeleg } let params = self.params(of: query) - if let urlString = params["url"] { - // Download and set custom keyboard - guard let url = URL(string: urlString) else { - let alert = ResourceFileManager.shared.buildSimpleAlert(title: "Custom Keyboard", - message: "The keyboard could not be installed: Invalid Url") - self.present(alert, animated: true, completion: nil) - launchUrl = nil - return - } - - Manager.shared.dismissKeyboardPicker(self) - if !infoView.view.isHidden { - perform(#selector(self.infoButtonClick), with: nil) - } - - customKeyboardToDownload = url - let title = "Custom Keyboard: \(url.lastPathComponent)" - confirmInstall(withTitle: title, message: "Would you like to install this keyboard?", - cancelButtonHandler: showGetStartedIfNeeded, - installButtonHandler: proceedWithCustomKeyboardDownload) - } else if let kbID = params["keyboard"], let langID = params["language"] { + if let kbID = params["keyboard"], let langID = params["language"] { // Query should include keyboard and language IDs to set the keyboard (first download if not available) guard let keyboard = Manager.shared.apiKeyboardRepository.installableKeyboard(withID: kbID, languageID: langID) else { @@ -970,13 +950,6 @@ class MainViewController: UIViewController, TextViewDelegate, UIActionSheetDeleg } } - private func proceedWithCustomKeyboardDownload(withAction action: UIAlertAction) { - if let url = customKeyboardToDownload { - ResourceDownloadManager.shared.downloadKeyboard(from: url) - } - showGetStartedIfNeeded(withAction: action) - } - private func showGetStartedIfNeeded(withAction action: UIAlertAction) { if shouldShowGetStarted { showGetStartedView(nil)