-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(web): load .kmx keyboard from blob 🎼 #12823
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,11 +191,11 @@ export default class KeymanEngine extends KeymanEngineBase<BrowserConfiguration, | |
// globe key - are accessible. | ||
// | ||
// The `super` call above initializes `keyboardRequisitioner`, as needed here. | ||
this.keyboardRequisitioner.cloudQueryEngine.once('unboundregister', () => { | ||
this.keyboardRequisitioner.cloudQueryEngine.once('unboundregister', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if(!this.contextManager.activeKeyboard?.keyboard) { | ||
// Autoselects this.keyboardRequisitioner.cache.defaultStub, which will be | ||
// set to an actual keyboard on mobile devices. | ||
this.setActiveKeyboard('', ''); | ||
await this.setActiveKeyboard('', ''); | ||
} | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -442,15 +442,15 @@ if(!keyman?.ui?.name) { | |
* @param {Object} e event | ||
* Description Change active keyboard in response to user selection event | ||
*/ | ||
readonly SelectKeyboardChange = (e: Event) => { | ||
readonly SelectKeyboardChange = async (e: Event) => { | ||
keymanweb.activatingUI(true); | ||
|
||
if(this.KeyboardSelector.value != '-') { | ||
var i=this.KeyboardSelector.selectedIndex; | ||
var t=this.KeyboardSelector.options[i].value.split(':'); | ||
keymanweb.setActiveKeyboard(t[0],t[1]); | ||
await keymanweb.setActiveKeyboard(t[0],t[1]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the review for me learning. Just did some very quick reading of promises. So as I understand setActiveKeyboard is a promise function which will either resolve or reject. However this code doesn't take into account whether it resolved or rejected, is it just simply waiting to it has run (async) before continuing... regardless of resolved or rejected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If rejected, an exception is thrown. Generally setActiveKeyboard should never reject. |
||
} else { | ||
keymanweb.setActiveKeyboard(''); | ||
await keymanweb.setActiveKeyboard(''); | ||
} | ||
|
||
//if(osk['show']) osk['show'](osk['isEnabled']()); handled by keyboard change event??? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Keyman is copyright (C) SIL International. MIT License. | ||
|
||
import { type MainModule } from './import/core/keymancore.js'; | ||
|
||
// Unfortunately embind has an open issue with enums and typescript where it | ||
// only generates a type for the enum, but not the values in a usable way. | ||
// So we have to re-define the enum here. | ||
// See https://github.com/emscripten-core/emscripten/issues/18585 | ||
// NOTE: Keep in sync with core/include/keyman/keyman_core_api.h#L311 | ||
export enum KM_CORE_STATUS { | ||
OK = 0, | ||
NO_MEM = 1, | ||
IO_ERROR = 2, | ||
INVALID_ARGUMENT = 3, | ||
KEY_ERROR = 4, | ||
INSUFFICENT_BUFFER = 5, | ||
INVALID_UTF = 6, | ||
INVALID_KEYBOARD = 7, | ||
NOT_IMPLEMENTED = 8, | ||
OS_ERROR = 0x80000000 | ||
} | ||
|
||
export class CoreFactory { | ||
public static async createCoreProcessor(baseurl: string): Promise<MainModule> { | ||
const module = await import(baseurl + '/km-core.js'); | ||
const createCoreProcessor = module.default; | ||
return await createCoreProcessor({ | ||
locateFile: function (path: string, scriptDirectory: string) { | ||
return baseurl + '/' + path; | ||
} | ||
}); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './core-processor.js'; | ||
export { CoreFactory, KM_CORE_STATUS } from './core-factory.js'; | ||
import { type MainModule, type km_core_keyboard, type CoreKeyboardReturn } from './import/core/keymancore.js'; | ||
export { MainModule, km_core_keyboard, CoreKeyboardReturn }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
import { assert } from 'chai'; | ||
import { CoreProcessor } from 'keyman/engine/core-processor'; | ||
import { CoreFactory, KM_CORE_STATUS } from 'keyman/engine/core-processor'; | ||
|
||
const coreurl = '/web/build/engine/core-processor/obj/import/core'; | ||
const coreurl = '/build/engine/core-processor/obj/import/core'; | ||
|
||
// Test the CoreProcessor interface. | ||
describe('CoreProcessor', function () { | ||
async function loadKeyboardBlob(uri: string) { | ||
const response = await fetch(uri); | ||
if (!response.ok) { | ||
throw new Error(`HTTP ${response.status} ${response.statusText}`); | ||
} | ||
|
||
const buffer = await response.arrayBuffer(); | ||
return new Uint8Array(buffer); | ||
} | ||
|
||
it('can initialize without errors', async function () { | ||
const kp = new CoreProcessor(); | ||
assert.isTrue(await kp.init(coreurl)); | ||
assert.isNotNull(await CoreFactory.createCoreProcessor(coreurl)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here for example would fail if there's an err. |
||
}); | ||
|
||
it('can call temp function', async function () { | ||
const kp = new CoreProcessor(); | ||
await kp.init(coreurl); | ||
const a = kp.tmp_wasm_attributes(); | ||
const km_core = await CoreFactory.createCoreProcessor(coreurl); | ||
const a = km_core.tmp_wasm_attributes(); | ||
assert.isNotNull(a); | ||
assert.isNumber(a.max_context); | ||
console.dir(a); | ||
}); | ||
|
||
it('can load a keyboard from blob', async function () { | ||
const km_core = await CoreFactory.createCoreProcessor(coreurl); | ||
const blob = await loadKeyboardBlob('/common/test/resources/keyboards/test_8568_deadkeys.kmx') | ||
const result = km_core.keyboard_load_from_blob('test', blob); | ||
assert.equal(result.status, KM_CORE_STATUS.OK); | ||
assert.isNotNull(result.object); | ||
result.delete(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention emscripten-core/emscripten#18585 here too?