From 03b95f7fed424299e88f5248f9f30afdc4dc2dcd Mon Sep 17 00:00:00 2001 From: Gabriel Wong Date: Thu, 23 Nov 2017 11:13:07 +0700 Subject: [PATCH] Remove unnecessary copying for iOS8 --- .../KMEI/KeymanEngine/Classes/Manager.swift | 41 +------------------ 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift b/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift index 3464fe67cf..0e528a5648 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift @@ -258,11 +258,6 @@ UIGestureRecognizerDelegate { } kmLog("Setting language: \(kb.languageID)_\(kb.id)", checkDebugPrinting: true) - if usingTempFolder { - if !copyKeymanFilesToTemp() { - return false - } - } // FIXME: kb.version is not respected. Ideally we should be able to trust that the version number in UserDefaults // is-to-date but it is sometimes not updated. @@ -1220,32 +1215,6 @@ UIGestureRecognizerDelegate { return true } - private func copyKeymanFilesToTemp() -> Bool { - let tempKeymanDir = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("keyman") - let tempLangDir = tempKeymanDir.appendingPathComponent("languages") - let tempFontDir = tempKeymanDir.appendingPathComponent("fonts") - - do { - try FileManager.default.createDirectory(at: tempKeymanDir, withIntermediateDirectories: true, attributes: nil) - try FileManager.default.createDirectory(at: tempLangDir, withIntermediateDirectories: true, attributes: nil) - try FileManager.default.createDirectory(at: tempFontDir, withIntermediateDirectories: true, attributes: nil) - try copyDirectoryContents(at: Storage.active.baseDir, to: tempKeymanDir) - try copyDirectoryContents(at: Storage.active.languageDir, to: tempLangDir) - try copyDirectoryContents(at: Storage.active.fontDir, to: tempFontDir) - } catch { - kmLog("copyKeymanFilesToTemp(): \(error)", checkDebugPrinting: false) - return false - } - return true - } - - private var usingTempFolder: Bool { - if #available(iOS 9.0, *) { - return false - } - return true - } - // FIXME: The check for empty filename, etc was removed. Check whether that needs to be added back. private func keyboardPath(forID keyboardID: String, keyboardVersion: String?) -> URL? { var keyboardVersion = keyboardVersion @@ -1519,18 +1488,12 @@ UIGestureRecognizerDelegate { } private func reloadKeyboard(in view: WKWebView) { + let codeURL = Storage.active.baseDir.appendingPathComponent(kmwFullFileName) if #available(iOS 9.0, *) { - let codeURL = Storage.active.baseDir.appendingPathComponent(kmwFullFileName) view.loadFileURL(codeURL, allowingReadAccessTo: codeURL.deletingLastPathComponent()) } else { // WKWebView in iOS < 9 is missing loadFileURL(). - // The files need to be copied to a temporary directory and loaded from there. - if copyKeymanFilesToTemp() { - let codeURL = URL(fileURLWithPath: NSTemporaryDirectory()) - .appendingPathComponent("keyman") - .appendingPathComponent(kmwFullFileName) - view.load(URLRequest(url: codeURL, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: 60.0)) - } + view.load(URLRequest(url: codeURL, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: 60.0)) } }