feat(web): dispose KMXKeyboards on shutdown

This commit is contained in:
Eberhard Beilharz 2025-05-15 15:41:08 +02:00
parent 4339462f1a
commit 2b2e8fc85b
No known key found for this signature in database
GPG key ID: E9140597606020D3
7 changed files with 29 additions and 4 deletions

View file

@ -115,6 +115,10 @@ export default class KeyboardRequisitioner {
});
}
shutdown(): void{
this.cache.shutdown();
}
addKeyboardArray(x: (string|RawKeyboardMetadata)[]): Promise<(KeyboardStub | ErrorStub)[]> {
let completeStubs: KeyboardStub[] = [];
let incompleteStubs: KeyboardStub[] = [];

View file

@ -1,4 +1,4 @@
import { type Keyboard, JSKeyboard, KeyboardLoaderBase as KeyboardLoader } from "keyman/engine/keyboard";
import { type Keyboard, JSKeyboard, KeyboardLoaderBase as KeyboardLoader, KMXKeyboard } from "keyman/engine/keyboard";
import { EventEmitter } from "eventemitter3";
import KeyboardStub from "./keyboardStub.js";
@ -52,6 +52,16 @@ export default class StubAndKeyboardCache extends EventEmitter<EventMap> {
this.keyboardLoader = keyboardLoader;
}
shutdown(): void {
for (const kbdId in this.keyboardTable) {
const kbd = this.keyboardTable[kbdId];
if (kbd instanceof KMXKeyboard) {
(kbd as KMXKeyboard).shutdown();
}
// TODO-web-core: do we have to do something if instanceof Promise?
}
}
getKeyboardForStub(stub: KeyboardStub): Keyboard {
return stub ? this.getKeyboard(stub.KI) : null;
}

View file

@ -8,6 +8,13 @@ export class KMXKeyboard {
constructor(private _keyboard: km_core_keyboard) {
}
shutdown() {
if (this._keyboard) {
KM_Core.instance.keyboard_dispose(this._keyboard);
this._keyboard = null;
}
}
get isMnemonic(): boolean {
return false;
}

View file

@ -7,6 +7,9 @@
"tsBuildInfoFile": "../../../build/engine/keyboard/obj/tsconfig.tsbuildinfo",
"rootDir": "./src/"
},
"references": [
{ "path": "../core-processor"},
],
"include": [ "./src/**/*.ts"],
"exclude": ["./src/keyboards/loaders/**/*.ts"]
}

View file

@ -11,7 +11,7 @@ interface EventMap {
'keyevent': (event: KeyEvent, callback?: (result: RuleBehavior, error?: Error) => void) => void
}
export default class HardKeyboard extends EventEmitter<EventMap> implements KeyEventSourceInterface<EventMap> { }
export class HardKeyboard extends EventEmitter<EventMap> implements KeyEventSourceInterface<EventMap> { }
export function processForMnemonicsAndLegacy(s: KeyEvent, activeKeyboard: Keyboard, baseLayout: string): KeyEvent {
if (!activeKeyboard) {

View file

@ -1,6 +1,6 @@
export { EngineConfiguration, InitOptionDefaults, InitOptionSpec } from './engineConfiguration.js';
export { ContextManagerBase, ContextManagerConfiguration } from './contextManagerBase.js';
export { default as HardKeyboard, processForMnemonicsAndLegacy } from './hardKeyboard.js';
export { HardKeyboard, processForMnemonicsAndLegacy } from './hardKeyboard.js';
export { KeyboardInterfaceBase } from './keyboardInterfaceBase.js';
export { KeymanEngineBase } from './keymanEngineBase.js';
export { LegacyAPIEvents } from './legacyAPIEvents.js';

View file

@ -11,7 +11,7 @@ import { ModelSpec, PredictionContext } from "keyman/engine/interfaces";
import { EngineConfiguration, InitOptionSpec } from "./engineConfiguration.js";
import { KeyboardInterfaceBase } from "./keyboardInterfaceBase.js";
import { ContextManagerBase } from "./contextManagerBase.js";
import HardKeyboardBase from "./hardKeyboard.js";
import { HardKeyboard as HardKeyboardBase } from "./hardKeyboard.js";
import { LegacyAPIEvents } from "./legacyAPIEvents.js";
import { EventNames, EventListener, LegacyEventEmitter } from "keyman/engine/events";
import DOMCloudRequester from "keyman/engine/keyboard-storage/dom-requester";
@ -463,6 +463,7 @@ export class KeymanEngineBase<
shutdown() {
this.legacyAPIEvents.shutdown();
this.osk?.shutdown();
this.keyboardRequisitioner?.shutdown();
}
// API methods