-
-
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
base: fix/core/alignment
Are you sure you want to change the base?
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||
// 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> { | ||||||
try { | ||||||
const module = await import(baseurl + '/km-core.js'); | ||||||
const createCoreProcessor = module.default; | ||||||
return await createCoreProcessor({ | ||||||
locateFile: function (path: string, scriptDirectory: string) { | ||||||
return baseurl + '/' + path; | ||||||
} | ||||||
}); | ||||||
} catch (e: any) { | ||||||
console.log('got execption in CoreFactory.createCoreProcessor', e); | ||||||
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.
Suggested change
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. I think we need to ensure that exceptions here aren't masked. Console log is not available in many contexts e.g. System keyboard. Console.error is a start but not enough maybe? 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. What do you suggest? 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. Is there a reason the exception needs to be masked here? Could it just change to propagate? |
||||||
return null; | ||||||
} | ||||||
} | ||||||
} |
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?