From b16dc6f2f8b979ce06863cee21bf8a899574d280 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Fri, 17 Apr 2026 19:11:18 +0200 Subject: [PATCH] refactor(web): cleanup return types in KeymanEngine This change explicitly specifies the return types and access for the functions in KeymanEngine. Also introduce `KeyboardDetails` instead of `ReturnType<>`. Test-bot: skip --- web/src/app/browser/src/keyboardDetails.ts | 66 +++++++++++++++++++ web/src/app/browser/src/keymanEngine.ts | 75 +++++++++++----------- 2 files changed, 102 insertions(+), 39 deletions(-) create mode 100644 web/src/app/browser/src/keyboardDetails.ts diff --git a/web/src/app/browser/src/keyboardDetails.ts b/web/src/app/browser/src/keyboardDetails.ts new file mode 100644 index 0000000000..9ced50ee46 --- /dev/null +++ b/web/src/app/browser/src/keyboardDetails.ts @@ -0,0 +1,66 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + */ + +import { InternalKeyboardFont } from 'keyman/engine/keyboard'; + +/** + * Defines keyboard metadata + */ +export interface KeyboardDetails { + /** + * true if the keyboard has been loaded, false otherwise + */ + HasLoaded: boolean, + /** + * User-friendly name of the keyboard. + */ + Name: string, + /** + * Internal name of the keyboard. + */ + InternalName: string, + /** + * User-friendly name of the language actively tied to the keyboard. + */ + LanguageName: string, + /** + * The three-letter code used to internally represent the language. + */ + LanguageCode: string, + /** + * The user-friendly name of the region of the world within which + * the language is predominantly found. + */ + RegionName: string, + /** + * The three-letter code representing the region. + */ + RegionCode: string, + /** + * The user-friendly name of the country in which the language is spoken. (Optional) + */ + CountryName: string | null, + /** + * A three-letter code corresponding to the country. (Optional) + */ + CountryCode: string| null, + /** + * Deprecated. A unique identifier for the keyboard. (Use 'InternalName' instead.) + */ + KeyboardID: string | null, + /** + * The font packaged with the keyboard to support its use. (Optional) + */ + Font: InternalKeyboardFont | null, + /** + * The font packaged with the keyboard to properly display specialized + * OSK characters. (Optional) + */ + OskFont: InternalKeyboardFont | null, + /** + * Indicates whether the keyboard is designed for right-to-left scripts, + * null if the keyboard hasn't been loaded yet (and thus the value is unknown). + */ + IsRTL: boolean | null +}; diff --git a/web/src/app/browser/src/keymanEngine.ts b/web/src/app/browser/src/keymanEngine.ts index b9663ca374..0d81bbdeaa 100644 --- a/web/src/app/browser/src/keymanEngine.ts +++ b/web/src/app/browser/src/keymanEngine.ts @@ -29,6 +29,7 @@ import { HotkeyManager } from './hotkeyManager.js'; import { BeepHandler } from './beepHandler.js'; import { KeyboardInterface } from './keyboardInterface.js'; import { WorkerFactory } from '@keymanapp/lexical-model-layer/web'; +import { KeyboardDetails } from './keyboardDetails.js'; export class KeymanEngine extends KeymanEngineBase { touchLanguageMenu?: LanguageMenu; @@ -43,8 +44,8 @@ export class KeymanEngine extends KeymanEngineBase number = null; - getOskWidth?: () => number = null; + public getOskHeight?: () => number = null; + public getOskWidth?: () => number = null; /** * Provides a quick link to the base help page for Keyman keyboards. @@ -53,7 +54,7 @@ export class KeymanEngine extends KeymanEngineBase { + public keyEventRefocus = () => { this.contextManager.restoreLastActiveTextStore(); } @@ -87,7 +88,7 @@ export class KeymanEngine extends KeymanEngineBase) { + public async init(options: Required): Promise { const deviceDetector = new DeviceDetector(); const device = deviceDetector.detect(); @@ -269,7 +270,7 @@ export class KeymanEngine extends KeymanEngineBase (and document!) - private _GetKeyboardDetail = function(Lstub: KeyboardStub, Lkbd: JSKeyboard) { // I2078 - Full keyboard detail - const Lr = { + private _GetKeyboardDetail(Lstub: KeyboardStub, Lkbd: Keyboard): KeyboardDetails { // I2078 - Full keyboard detail + return { Name: Lstub.KN, InternalName: Lstub.KI, LanguageName: Lstub.KL, // I1300 - Add support for language names @@ -419,8 +418,6 @@ export class KeymanEngine extends KeymanEngineBase /* [b/c Toolbar UI]*/) { + public isCJK(k0?: KeyboardObject | KeyboardDetails /* [b/c Toolbar UI]*/) { let kbd: Keyboard; if(k0) { - const kbdDetail = k0 as ReturnType; + const kbdDetail = k0 as KeyboardDetails; if(kbdDetail.KeyboardID){ kbd = this.keyboardRequisitioner.cache.getKeyboard(kbdDetail.KeyboardID); } else { @@ -460,7 +457,7 @@ export class KeymanEngine extends KeymanEngineBase[] { - const Lr: ReturnType[] = []; + public getKeyboards(): KeyboardDetails[] { + const Lr: KeyboardDetails[] = []; const cache = this.keyboardRequisitioner.cache; const keyboardStubs = cache.getStubList() @@ -511,7 +508,7 @@ export class KeymanEngine extends KeymanEngineBase void) { + public addHotKey(keyCode: number, shiftState: number, handler: () => void): void { this.hotkeyManager.addHotKey(keyCode, shiftState, handler); } @@ -619,7 +616,7 @@ export class KeymanEngine extends KeymanEngineBase