Fix samples

This commit is contained in:
Gabriel Wong 2017-12-11 12:42:49 +07:00
parent 63ab59c011
commit 161a129407
3 changed files with 25 additions and 21 deletions

View file

@ -698,6 +698,7 @@ public class Manager: NSObject, HTTPDownloadDelegate, UIGestureRecognizerDelegat
/// Preloads the JS and font files required for a keyboard.
public func preloadFiles(forKeyboardID keyboardID: String, at urls: [URL], shouldOverwrite: Bool) throws {
let keyboardDir = Storage.active.keyboardDir(forID: keyboardID)
try FileManager.default.createDirectory(at: keyboardDir, withIntermediateDirectories: true)
for url in urls {
try Storage.copyAndExcludeFromBackup(at: url,
to: keyboardDir.appendingPathComponent(url.lastPathComponent),

View file

@ -15,17 +15,7 @@ class ViewController: UIViewController, TextViewDelegate {
super.viewDidLoad()
Manager.shared.openURL = UIApplication.shared.openURL
Manager.shared.isKeymanHelpOn = false
do {
try Manager.shared.preloadKeyboardFile(at: Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!,
shouldOverwrite: true)
try Manager.shared.preloadFontFile(at: Bundle.main.url(forResource: "aava1", withExtension: "ttf")!,
shouldOverwrite: true)
} catch {
print("Error preloading: \(error)")
}
FontManager.shared.registerCustomFonts()
Manager.shared.addKeyboard(Defaults.keyboard)
let kb = InstallableKeyboard(id: "tamil99m",
name: "Tamil 99M",
languageID: "tam",
@ -35,6 +25,18 @@ class ViewController: UIViewController, TextViewDelegate {
font: Font(filename: "aava1.ttf"),
oskFont: nil,
isCustom: true)
let urls = [
Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!,
Bundle.main.url(forResource: "aava1", withExtension: "ttf")!
]
do {
try Manager.shared.preloadFiles(forKeyboardID: kb.id, at: urls, shouldOverwrite: true)
} catch {
print("Error preloading: \(error)")
}
FontManager.shared.registerCustomFonts()
Manager.shared.addKeyboard(Defaults.keyboard)
Manager.shared.addKeyboard(kb)
textView.setKeymanDelegate(self)

View file

@ -16,19 +16,8 @@ class ViewController: UIViewController, TextViewDelegate {
super.viewDidLoad()
Manager.shared.openURL = UIApplication.shared.openURL
Manager.shared.isKeymanHelpOn = false
do {
try Manager.shared.preloadKeyboardFile(at: Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!,
shouldOverwrite: true)
try Manager.shared.preloadFontFile(at: Bundle.main.url(forResource: "aava1", withExtension: "ttf")!,
shouldOverwrite: true)
} catch {
print("Error preloading: \(error)")
}
FontManager.shared.registerCustomFonts()
Manager.shared.addKeyboard(Defaults.keyboard)
let kb = InstallableKeyboard(id: "tamil99m",
name: "Tamil 99M",
languageID: "tam",
@ -38,6 +27,18 @@ class ViewController: UIViewController, TextViewDelegate {
font: Font(filename: "aava1.ttf"),
oskFont: nil,
isCustom: true)
let urls = [
Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!,
Bundle.main.url(forResource: "aava1", withExtension: "ttf")!
]
do {
try Manager.shared.preloadFiles(forKeyboardID: kb.id, at: urls, shouldOverwrite: true)
} catch {
print("Error preloading: \(error)")
}
FontManager.shared.registerCustomFonts()
Manager.shared.addKeyboard(Defaults.keyboard)
Manager.shared.addKeyboard(kb)
textView.setKeymanDelegate(self)