diff --git a/package-lock.json b/package-lock.json index a1c9ed48f0d..a4da5da25d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "uhk-agent", - "version": "10.1.0", + "version": "11.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "uhk-agent", - "version": "10.1.0", + "version": "11.0.0", "hasInstallScript": true, "license": "See in LICENSE", "devDependencies": { @@ -19,7 +19,10 @@ "@types/decompress": "4.2.7", "@types/file-saver": "2.0.7", "@types/lodash": "4.17.24", + "@types/lodash.isequal": "4.5.8", + "@types/md5": "2.3.6", "@types/node": "24.13.3", + "@types/semver": "7.7.1", "check-node-version": "4.2.1", "copy-webpack-plugin": "14.0.0", "cross-env": "10.1.0", @@ -2651,6 +2654,23 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/lodash.isequal": { + "version": "4.5.8", + "resolved": "https://registry.npmjs.org/@types/lodash.isequal/-/lodash.isequal-4.5.8.tgz", + "integrity": "sha512-uput6pg4E/tj2LGxCZo9+y27JNyB2OZuuI/T5F+ylVDYuqICLG2/ktjxx0v6GvVntAf8TvEzeQLcV0ffRirXuA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/lodash": "*" + } + }, + "node_modules/@types/md5": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/@types/md5/-/md5-2.3.6.tgz", + "integrity": "sha512-WD69gNXtRBnpknfZcb4TRQ0XJQbUPZcai/Qdhmka3sxUR3Et8NrXoeAoknG/LghYHTf4ve795rInVYHBTQdNVA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/ms": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", @@ -2678,6 +2698,13 @@ "@types/node": "*" } }, + "node_modules/@types/semver": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.7.1.tgz", + "integrity": "sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/triple-beam": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", diff --git a/package.json b/package.json index 107f6111119..4cb2c34ab4e 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,10 @@ "@types/decompress": "4.2.7", "@types/file-saver": "2.0.7", "@types/lodash": "4.17.24", + "@types/lodash.isequal": "4.5.8", + "@types/md5": "2.3.6", "@types/node": "24.13.3", + "@types/semver": "7.7.1", "check-node-version": "4.2.1", "copy-webpack-plugin": "14.0.0", "cross-env": "10.1.0", diff --git a/packages/mcumgr/src/util/cbor.ts b/packages/mcumgr/src/util/cbor.ts index 33f3aa47837..ed96a0a977d 100644 --- a/packages/mcumgr/src/util/cbor.ts +++ b/packages/mcumgr/src/util/cbor.ts @@ -178,9 +178,9 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function, let offset = 0; if (typeof tagger !== "function") - tagger = function(value) { return value; }; + tagger = function(value: unknown): unknown { return value; }; if (typeof simpleValue !== "function") - simpleValue = function() { return undefined; }; + simpleValue = function(): undefined { return undefined; }; function commitRead(length: number, value: T): T { offset += length; @@ -364,7 +364,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function, } case 5: { - const retObject = {}; + const retObject: Record = {}; for (i = 0; i < length || length < 0 && !readBreak(); ++i) { const key = decodeItem() as string | number; retObject[key] = decodeItem(); diff --git a/packages/uhk-agent/src/electron-menu.ts b/packages/uhk-agent/src/electron-menu.ts index 09d61741c76..64beaf0bde4 100644 --- a/packages/uhk-agent/src/electron-menu.ts +++ b/packages/uhk-agent/src/electron-menu.ts @@ -1,6 +1,6 @@ import { app, BrowserWindow, Menu, MenuItemConstructorOptions, systemPreferences } from 'electron'; -export const setMenu = (win: BrowserWindow, allowDevTools): void => { +export const setMenu = (win: BrowserWindow, allowDevTools: boolean): void => { if (!allowDevTools && process.platform !== 'darwin') { win.setMenuBarVisibility(false); diff --git a/packages/uhk-agent/src/services/device.service.ts b/packages/uhk-agent/src/services/device.service.ts index 472e8ee2ed7..83601c74dbd 100644 --- a/packages/uhk-agent/src/services/device.service.ts +++ b/packages/uhk-agent/src/services/device.service.ts @@ -330,7 +330,7 @@ export class DeviceService { logService.misc('[DeviceService] init success'); } - public async areBleAddressesPaired(event: Electron.IpcMainEvent, args): Promise { + public async areBleAddressesPaired(event: Electron.IpcMainEvent, args: [string[]]): Promise { this.logService.misc('[DeviceService] Check BLE Addresses are paired'); const response: AreBleAddressesPairedIpcResponse = { @@ -365,7 +365,7 @@ export class DeviceService { * Return with the actual UserConfiguration from UHK Device * @returns {Promise} */ - public async loadConfigurations(event: Electron.IpcMainEvent, args): Promise { + public async loadConfigurations(event: Electron.IpcMainEvent, args: []): Promise { this.logService.misc('[DeviceService] load user configuration'); let response: ConfigurationReply; @@ -839,7 +839,7 @@ export class DeviceService { event.sender.send(IpcEvents.device.updateFirmwareReply, response); } - public async recoveryDevice(event: Electron.IpcMainEvent, args): Promise { + public async recoveryDevice(event: Electron.IpcMainEvent, args: [{ deviceId: UHK_DEVICE_IDS_TYPE, userConfig: Object }]): Promise { const response: FirmwareUpgradeIpcResponse = { success: false, }; @@ -895,7 +895,7 @@ export class DeviceService { this.startPollUhkDevice(); } - public async recoveryModule(event: Electron.IpcMainEvent, args): Promise { + public async recoveryModule(event: Electron.IpcMainEvent, args: [number]): Promise { const response: FirmwareUpgradeIpcResponse = { success: false, }; @@ -1161,7 +1161,7 @@ export class DeviceService { } } - private async changeKeyboardLayout(event: Electron.IpcMainEvent, args): Promise { + private async changeKeyboardLayout(event: Electron.IpcMainEvent, args: [KeyboardLayout, unknown]): Promise { const layout: KeyboardLayout = args[0]; const hardwareConfiguration: HardwareConfiguration = new HardwareConfiguration().fromJsonObject(args[1]); const layoutName = layout === KeyboardLayout.ISO ? 'iso': 'ansi'; @@ -1444,7 +1444,7 @@ export class DeviceService { event.sender.send(IpcEvents.device.deleteUserConfigHistoryReply, response); } - private async toggleI2cDebugging(_: Electron.IpcMainEvent, [enabled]): Promise { + private async toggleI2cDebugging(_: Electron.IpcMainEvent, [enabled]: [boolean]): Promise { this.logService.misc('[DeviceService] Toggle I2C debugging =>', enabled); this.isI2cDebuggingEnabled = enabled; @@ -1465,7 +1465,7 @@ export class DeviceService { } } - private async toggleRightHalfZephyrLogging(_: Electron.IpcMainEvent, [enabled]): Promise { + private async toggleRightHalfZephyrLogging(_: Electron.IpcMainEvent, [enabled]: [boolean]): Promise { this.logService.misc('[DeviceService] Toggle Right Half zephyr logging =>', enabled); try { diff --git a/packages/uhk-agent/src/services/logger.service.ts b/packages/uhk-agent/src/services/logger.service.ts index 3e0a18ccc26..2ec72e57161 100644 --- a/packages/uhk-agent/src/services/logger.service.ts +++ b/packages/uhk-agent/src/services/logger.service.ts @@ -73,7 +73,8 @@ export class ElectronLogService extends LogService { } } - usbOps(...args) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + usbOps(...args: any[]): void { if (!this._options.usbOps) { return; } diff --git a/packages/uhk-agent/src/services/smart-macro-doc.service.ts b/packages/uhk-agent/src/services/smart-macro-doc.service.ts index 15c992cb35e..d87ba655b7a 100644 --- a/packages/uhk-agent/src/services/smart-macro-doc.service.ts +++ b/packages/uhk-agent/src/services/smart-macro-doc.service.ts @@ -167,7 +167,7 @@ export class SmartMacroDocService { event.sender.send(IpcEvents.smartMacroDoc.serviceListening, this.port); } - private async handleDownloadDocumentation(event: Electron.IpcMainEvent, args): Promise { + private async handleDownloadDocumentation(event: Electron.IpcMainEvent, args: [FirmwareRepoInfo]): Promise { try { const firmwareRepoInfo: FirmwareRepoInfo = args[0]; if (!firmwareRepoInfo.firmwareGitRepo || !firmwareRepoInfo.firmwareGitTag) { diff --git a/packages/uhk-agent/src/types/decompress-plugins.d.ts b/packages/uhk-agent/src/types/decompress-plugins.d.ts new file mode 100644 index 00000000000..c587d4f6d63 --- /dev/null +++ b/packages/uhk-agent/src/types/decompress-plugins.d.ts @@ -0,0 +1,11 @@ +declare module 'decompress-tarbz2' { + export default function decompressTarbz2(): unknown; +} + +declare module 'decompress-targz' { + export default function decompressTargz(): unknown; +} + +declare module 'decompress-unzip' { + export default function decompressUnzip(): unknown; +} diff --git a/packages/uhk-common/src/config-serializer/assert.ts b/packages/uhk-common/src/config-serializer/assert.ts index afe124f97ef..993c6bf6ddf 100644 --- a/packages/uhk-common/src/config-serializer/assert.ts +++ b/packages/uhk-common/src/config-serializer/assert.ts @@ -81,7 +81,7 @@ export function assertEnum(enumerated: E) { } if (this[priv] !== newVal) { - if (enumerated[newVal] === undefined) { + if (enumerated[newVal as keyof E] === undefined) { throw new Error(`${target.constructor.name}.${key}: ${newVal} is not enum`); } this[priv] = newVal; diff --git a/packages/uhk-common/src/config-serializer/config-items/advanced-secondary-role-configuration-values.ts b/packages/uhk-common/src/config-serializer/config-items/advanced-secondary-role-configuration-values.ts index 784d0792c0b..b9a316a0e9d 100644 --- a/packages/uhk-common/src/config-serializer/config-items/advanced-secondary-role-configuration-values.ts +++ b/packages/uhk-common/src/config-serializer/config-items/advanced-secondary-role-configuration-values.ts @@ -1,4 +1,5 @@ import { UHK_80_USER_CONFIG } from '../../user-config-80.js'; +import { fromStringUnsafe } from '../../util/from-string-unsafe.js'; import { AdvancedSecondaryRoleConfiguration } from './advanced-secondary-role-configuration'; import { SecondaryRoleAdvancedStrategyTimeoutAction } from './secondary-role-advanced-strategy-timeout-action.js'; @@ -39,9 +40,9 @@ export const SIMPLE_ADVANCED_SECONDARY_ROLE_CONFIGURATION_PRESET: AdvancedSecond configuration: { secondaryRoleAdvancedStrategyTimeout: UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTimeout, // TODO: Firngrod, can the timeout be disabled with the new implementation? secondaryRoleAdvancedStrategyMinimumHoldTime: UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyMinimumHoldTime, - secondaryRoleAdvancedStrategyTimeoutAction: SecondaryRoleAdvancedStrategyTimeoutAction[UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTimeoutAction], - secondaryRoleAdvancedStrategyTimeoutType: SecondaryRoleAdvancedStrategyTimeoutType[UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTimeoutType], - secondaryRoleAdvancedStrategyTrigger: SecondaryRoleAdvancedStrategyTriggeringEvent[UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTrigger], + secondaryRoleAdvancedStrategyTimeoutAction: fromStringUnsafe(SecondaryRoleAdvancedStrategyTimeoutAction, UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTimeoutAction), + secondaryRoleAdvancedStrategyTimeoutType: fromStringUnsafe(SecondaryRoleAdvancedStrategyTimeoutType, UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTimeoutType), + secondaryRoleAdvancedStrategyTrigger: fromStringUnsafe(SecondaryRoleAdvancedStrategyTriggeringEvent, UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTrigger), secondaryRoleAdvancedStrategySafetyMargin: UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategySafetyMargin, secondaryRoleAdvancedStrategyDoubletapToPrimary: UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyDoubletapToPrimary, secondaryRoleAdvancedStrategyTriggerByMouse: UHK_80_USER_CONFIG.secondaryRoleAdvancedStrategyTriggerByMouse, diff --git a/packages/uhk-common/src/config-serializer/config-items/host-connection.ts b/packages/uhk-common/src/config-serializer/config-items/host-connection.ts index d8aca12dd5e..7b8aaa32e72 100644 --- a/packages/uhk-common/src/config-serializer/config-items/host-connection.ts +++ b/packages/uhk-common/src/config-serializer/config-items/host-connection.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../util/from-string-unsafe.js'; import { assertEnum } from '../assert.js'; import { UhkBuffer } from '../uhk-buffer.js'; import { isSerialisationInfoLt } from './serialisation-info.js'; @@ -193,7 +194,7 @@ export class HostConnection { // eslint-disable-next-line @typescript-eslint/no-explicit-any private fromJsonObjectV8(jsonObject: any, serialisationInfo: SerialisationInfo): HostConnection { - this.type = HostConnections[jsonObject.type]; + this.type = fromStringUnsafe(HostConnections, jsonObject.type); if (this.hasAddress()) { this.address = jsonObject.address; @@ -220,7 +221,7 @@ export class HostConnection { // eslint-disable-next-line @typescript-eslint/no-explicit-any private fromJsonObjectV9(jsonObject: any, serialisationInfo: SerialisationInfo): HostConnection { - this.type = HostConnections[jsonObject.type]; + this.type = fromStringUnsafe(HostConnections, jsonObject.type); if (this.hasAddress()) { this.address = jsonObject.address; } diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/connections-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/connections-action.ts index ee2688430e9..36c111ce4b3 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/connections-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/connections-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertEnum, assertUInt8 } from '../../assert.js'; import { UhkBuffer } from '../../uhk-buffer.js'; import { SerialisationInfo } from '../serialisation-info.js'; @@ -31,7 +32,7 @@ export class ConnectionsAction extends KeyAction { // eslint-disable-next-line @typescript-eslint/no-explicit-any fromJsonObject(jsonObject: any, serialisationInfo: SerialisationInfo): ConnectionsAction { this.assertKeyActionType(jsonObject); - this.command = ConnectionCommands[jsonObject.command] + this.command = fromStringUnsafe(ConnectionCommands, jsonObject.command) if (this.hasHostConnectionId()) { this.hostConnectionId = jsonObject.hostConnectionId; } diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts index a1975dbcde9..50b4eb236aa 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts @@ -1,4 +1,5 @@ import { defaultRgbColor, RgbColorInterface } from '../../../models/rgb-color-interface.js'; +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertUInt8 } from '../../assert.js'; import { Macro } from '../macro.js'; import { UhkBuffer } from '../../uhk-buffer.js'; @@ -61,7 +62,7 @@ export abstract class KeyAction implements RgbColorInterface { // eslint-disable-next-line @typescript-eslint/no-explicit-any assertKeyActionType(jsObject: any): void { const keyActionClassname: string = this.getName(); - const keyActionTypeString: string = keyActionType[keyActionClassname]; + const keyActionTypeString: string = keyActionType[keyActionClassname as keyof typeof keyActionType]; if (jsObject.keyActionType !== keyActionTypeString) { throw new Error(`Invalid ${keyActionClassname}.keyActionType: ${jsObject.keyActionType}`); } @@ -70,7 +71,7 @@ export abstract class KeyAction implements RgbColorInterface { readAndAssertKeyActionId(buffer: UhkBuffer): KeyActionId { const classname: string = this.getName(); const readKeyActionId: number = buffer.readUInt8(); - const keyActionId: number = KeyActionId[classname]; + const keyActionId: number = fromStringUnsafe(KeyActionId, classname); if (keyActionId === KeyActionId.KeystrokeAction) { if (readKeyActionId < KeyActionId.KeystrokeAction || readKeyActionId > KeyActionId.LastKeystrokeAction) { throw new Error(`Invalid ${classname} first byte: ${readKeyActionId}`); diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/keystroke-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/keystroke-action.ts index a978282e753..47b4e87aa3e 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/keystroke-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/keystroke-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertEnum, assertUInt8 } from '../../assert.js'; import { UhkBuffer } from '../../uhk-buffer.js'; import { KeyModifiers } from '../key-modifiers.js'; @@ -251,12 +252,12 @@ export class KeystrokeAction extends KeyAction { if (jsonObject.type === 'media') { this.type = jsonObject.scancode < 256 ? KeystrokeType.shortMedia : KeystrokeType.longMedia; } else { - this.type = KeystrokeType[jsonObject.type]; + this.type = fromStringUnsafe(KeystrokeType, jsonObject.type); } this._scancode = jsonObject.scancode; this.modifierMask = jsonObject.modifierMask; - this.secondaryRoleAction = SecondaryRoleAction[jsonObject.secondaryRoleAction]; + this.secondaryRoleAction = fromStringUnsafe(SecondaryRoleAction, jsonObject.secondaryRoleAction); } private fromJsonObjectV6(jsonObject: JsonObjectKeystrokeAction, serialisationInfo: SerialisationInfo): void { diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/mouse-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/mouse-action.ts index 41dffd5f912..e25f78bebd5 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/mouse-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/mouse-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertEnum } from '../../assert.js'; import { UhkBuffer } from '../../uhk-buffer.js'; import { SerialisationInfo } from '../serialisation-info.js'; @@ -133,7 +134,7 @@ export class MouseAction extends KeyAction { // eslint-disable-next-line @typescript-eslint/no-explicit-any private fromJsonObjectV1(jsObject: any): MouseAction { this.assertKeyActionType(jsObject); - this.mouseAction = MouseActionParam[jsObject.mouseAction]; + this.mouseAction = fromStringUnsafe(MouseActionParam, jsObject.mouseAction); return this; } diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/other-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/other-action.ts index d7517182d3b..b2e28bb139c 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/other-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/other-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertEnum } from '../../assert.js'; import { UhkBuffer } from '../../uhk-buffer.js'; import { SerialisationInfo } from '../serialisation-info.js'; @@ -24,7 +25,7 @@ export class OtherAction extends KeyAction { // eslint-disable-next-line @typescript-eslint/no-explicit-any fromJsonObject(jsonObject: any, serialisationInfo: SerialisationInfo): OtherAction { this.assertKeyActionType(jsonObject); - this.actionSubtype = OtherActionSubTypes[jsonObject.actionSubtype]; + this.actionSubtype = fromStringUnsafe(OtherActionSubTypes, jsonObject.actionSubtype); this.rgbColorFromJson(jsonObject, serialisationInfo); return this; diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/play-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/play-macro-action.ts index 23b7ed89dbe..274b7efe15f 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/play-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/play-macro-action.ts @@ -181,7 +181,7 @@ export class PlayMacroAction extends KeyAction { this.rgbColorFromJson(jsonObject, serialisationInfo); if (Array.isArray(jsonObject.macroArguments)) { - this.macroArguments = jsonObject.macroArguments.map(macroArgument => { + this.macroArguments = jsonObject.macroArguments.map((macroArgument: unknown) => { const argument = new MacroArgumentAction(); argument.fromJsonObject(macroArgument); diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/switch-layer-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/switch-layer-action.ts index 1c81554e7e3..fa993d3ebae 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/switch-layer-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/switch-layer-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertEnum } from '../../assert.js'; import { UhkBuffer } from '../../uhk-buffer.js'; import { SerialisationInfo } from '../serialisation-info.js'; @@ -144,7 +145,7 @@ export class SwitchLayerAction extends KeyAction { // eslint-disable-next-line @typescript-eslint/no-explicit-any private fromJsonObjectV1(jsonObject: any): void { this.assertKeyActionType(jsonObject); - this.layer = LayerName[jsonObject.layer]; + this.layer = fromStringUnsafe(LayerName, jsonObject.layer); // Backward compatibility when "switchLayerMode" was a boolean type as "toggle" if (typeof jsonObject.toggle === 'boolean') { diff --git a/packages/uhk-common/src/config-serializer/config-items/keymap.ts b/packages/uhk-common/src/config-serializer/config-items/keymap.ts index 4caceff1b40..57327038add 100644 --- a/packages/uhk-common/src/config-serializer/config-items/keymap.ts +++ b/packages/uhk-common/src/config-serializer/config-items/keymap.ts @@ -190,7 +190,7 @@ export class Keymap { this.abbreviation = jsonObject.abbreviation; this.name = jsonObject.name; this.description = jsonObject.description; - this.layers = jsonObject.layers.map((layer) => new Layer().fromJsonObject(layer, macros, serialisationInfo)); + this.layers = jsonObject.layers.map((layer: unknown) =>new Layer().fromJsonObject(layer, macros, serialisationInfo)); } private fromBinaryV1(buffer: UhkBuffer, macros: Macro[], serialisationInfo: SerialisationInfo): void { diff --git a/packages/uhk-common/src/config-serializer/config-items/layer.ts b/packages/uhk-common/src/config-serializer/config-items/layer.ts index e43ac3dea53..c01464fce61 100644 --- a/packages/uhk-common/src/config-serializer/config-items/layer.ts +++ b/packages/uhk-common/src/config-serializer/config-items/layer.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../util/from-string-unsafe.js'; import { UhkBuffer } from '../uhk-buffer.js'; import { assertEnum } from '../assert.js'; @@ -126,7 +127,7 @@ export class Layer { // eslint-disable-next-line @typescript-eslint/no-explicit-any fromJsonObjectV1(jsonObject: any, macros: Macro[], serialisationInfo: SerialisationInfo): void { - this.modules = jsonObject.modules.map((module) => { + this.modules = jsonObject.modules.map((module: unknown) => { return new Module().fromJsonObject(module, macros, serialisationInfo); }); } @@ -139,8 +140,8 @@ export class Layer { // eslint-disable-next-line @typescript-eslint/no-explicit-any fromJsonObjectV5(jsonObject: any, macros: Macro[], serialisationInfo: SerialisationInfo): void { - this.id = LayerName[jsonObject.id]; - this.modules = jsonObject.modules.map((module) => { + this.id = fromStringUnsafe(LayerName, jsonObject.id); + this.modules = jsonObject.modules.map((module: unknown) => { return new Module().fromJsonObject(module, macros, serialisationInfo); }); } diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts index 9c0adde8b6b..6395b06ab9a 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertEnum, assertUInt8, assertUInt16 } from '../../assert.js'; import { UhkBuffer } from '../../uhk-buffer.js'; import { KeyModifiers } from '../key-modifiers.js'; @@ -177,11 +178,11 @@ export class KeyMacroAction extends MacroAction { private fromJsonObjectV1(jsObject: JsObjectKeyMacroAction): void { this.assertMacroActionType(jsObject); - this.action = MacroKeySubAction[jsObject.action]; + this.action = fromStringUnsafe(MacroKeySubAction, jsObject.action); if (jsObject.type === 'media') { this.type = jsObject.scancode < 256 ? KeystrokeType.shortMedia : KeystrokeType.longMedia; } else { - this.type = KeystrokeType[jsObject.type]; + this.type = fromStringUnsafe(KeystrokeType, jsObject.type); } this._scancode = jsObject.scancode; this.modifierMask = jsObject.modifierMask; diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts index d9ca3c5f070..19c7a118fa0 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { UhkBuffer } from '../../uhk-buffer.js'; export enum MacroActionId { @@ -50,7 +51,7 @@ export abstract class MacroAction { // eslint-disable-next-line @typescript-eslint/no-explicit-any assertMacroActionType(jsObject: any) { const macroActionClassname = this.getName(); - const macroActionTypeString = macroActionType[macroActionClassname]; + const macroActionTypeString = macroActionType[macroActionClassname as keyof typeof macroActionType]; if (jsObject.macroActionType !== macroActionTypeString) { throw new Error(`Invalid ${macroActionClassname}.macroActionType: ${jsObject.macroActionType}`); } @@ -59,7 +60,7 @@ export abstract class MacroAction { readAndAssertMacroActionId(buffer: UhkBuffer): MacroActionId { const classname: string = this.getName(); const readMacroActionId: MacroActionId = buffer.readUInt8(); - const macroActionId: MacroActionId = MacroActionId[classname]; + const macroActionId: MacroActionId = fromStringUnsafe(MacroActionId, classname); if (macroActionId === MacroActionId.KeyMacroAction) { if (readMacroActionId < MacroActionId.KeyMacroAction || readMacroActionId > MacroActionId.LastKeyMacroAction) { throw new Error(`Invalid ${classname} first byte: ${readMacroActionId}`); diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts index 50239bc21b7..e703ef0a574 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../../util/from-string-unsafe.js'; import { assertEnum, assertUInt8 } from '../../assert.js'; import { UhkBuffer } from '../../uhk-buffer.js'; import { SerialisationInfo } from '../serialisation-info.js'; @@ -137,7 +138,7 @@ export class MouseButtonMacroAction extends MacroAction { private fromJsonObjectV1(jsObject: JsObjectMouseButtonMacroAction): void { this.assertMacroActionType(jsObject); - this.action = MacroMouseSubAction[jsObject.action]; + this.action = fromStringUnsafe(MacroMouseSubAction, jsObject.action); this.mouseButtonsMask = jsObject.mouseButtonsMask; } diff --git a/packages/uhk-common/src/config-serializer/config-items/macro.ts b/packages/uhk-common/src/config-serializer/config-items/macro.ts index dd44f0dd10d..ca197c26c73 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro.ts @@ -106,7 +106,8 @@ export class Macro { this.isLooped = jsonObject.isLooped; this.isPrivate = jsonObject.isPrivate; this.name = jsonObject.name; - this.macroActions = jsonObject.macroActions.map((macroAction) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.macroActions = jsonObject.macroActions.map((macroAction: any) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument return MacroActionHelper.createMacroAction(macroAction, serialisationInfo); }); diff --git a/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts b/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts index 34e2d721894..88275321e80 100644 --- a/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts +++ b/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts @@ -1,3 +1,4 @@ +import { fromStringUnsafe } from '../../util/from-string-unsafe.js'; import { assertEnum, assertFloat, assertUInt16 } from '../assert.js'; import { UhkBuffer } from '../uhk-buffer.js'; import { ModuleId } from './module-configuration/module-id.js'; @@ -242,16 +243,16 @@ export class ModuleConfiguration { // eslint-disable-next-line @typescript-eslint/no-explicit-any private fromJsonObjectV7(jsonObject: any): void { - this.id = ModuleId[jsonObject.id as string]; + this.id = fromStringUnsafe(ModuleId, jsonObject.id); - this.navigationModeBaseLayer = NavigationMode[jsonObject.navigationModeBaseLayer as string]; - this.navigationModeModLayer = NavigationMode[jsonObject.navigationModeModLayer as string]; - this.navigationModeFnLayer = NavigationMode[jsonObject.navigationModeFnLayer as string]; - this.navigationModeMouseLayer = NavigationMode[jsonObject.navigationModeMouseLayer as string]; - this.navigationModeFn2Layer = NavigationMode[jsonObject.navigationModeFn2Layer as string]; - this.navigationModeFn3Layer = NavigationMode[jsonObject.navigationModeFn3Layer as string]; - this.navigationModeFn4Layer = NavigationMode[jsonObject.navigationModeFn4Layer as string]; - this.navigationModeFn5Layer = NavigationMode[jsonObject.navigationModeFn5Layer as string]; + this.navigationModeBaseLayer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeBaseLayer); + this.navigationModeModLayer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeModLayer); + this.navigationModeFnLayer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeFnLayer); + this.navigationModeMouseLayer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeMouseLayer); + this.navigationModeFn2Layer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeFn2Layer); + this.navigationModeFn3Layer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeFn3Layer); + this.navigationModeFn4Layer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeFn4Layer); + this.navigationModeFn5Layer = fromStringUnsafe(NavigationMode, jsonObject.navigationModeFn5Layer); this.speed = jsonObject.speed; this.baseSpeed = jsonObject.baseSpeed; @@ -272,7 +273,7 @@ export class ModuleConfiguration { } else if (this.id === ModuleId.TouchpadRight){ this.touchpadPinchZoomDivisor = jsonObject.touchpadPinchZoomDivisor; this.touchpadHoldContinuationTimeout = jsonObject.touchpadHoldContinuationTimeout; - this.touchpadPinchToZoom = NavigationMode[jsonObject.touchpadPinchToZoom as string]; + this.touchpadPinchToZoom = fromStringUnsafe(NavigationMode, jsonObject.touchpadPinchToZoom); } } diff --git a/packages/uhk-common/src/config-serializer/config-items/module.ts b/packages/uhk-common/src/config-serializer/config-items/module.ts index 58fcee9c11e..7feff0b41eb 100644 --- a/packages/uhk-common/src/config-serializer/config-items/module.ts +++ b/packages/uhk-common/src/config-serializer/config-items/module.ts @@ -141,7 +141,8 @@ export class Module { // eslint-disable-next-line @typescript-eslint/no-explicit-any fromJsonObjectV1(jsonObject: any, macros: Macro[], serialisationInfo: SerialisationInfo): void { this.id = jsonObject.id; - this.keyActions = jsonObject.keyActions.map((keyActionJson) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.keyActions = jsonObject.keyActions.map((keyActionJson: any) => { const keyAction = KeyActionHelper.fromJSONObject(keyActionJson, macros, serialisationInfo); if (keyActionJson?.label) { keyAction.label = keyActionJson.label; diff --git a/packages/uhk-common/src/config-serializer/config-items/user-configuration.ts b/packages/uhk-common/src/config-serializer/config-items/user-configuration.ts index 2e5b86edd22..893c8db67b3 100644 --- a/packages/uhk-common/src/config-serializer/config-items/user-configuration.ts +++ b/packages/uhk-common/src/config-serializer/config-items/user-configuration.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { DEFAULT_DEVICE_NAME } from '../../util/constants.js'; +import { fromStringUnsafe } from '../../util/from-string-unsafe.js'; import { assertEnum, assertFloat, assertInt16, assertUInt16, assertUInt32, assertUInt8 } from '../assert.js'; import { resolveSwitchKeymapActions } from '../resolve-switch-keymap-actions.js'; import { UhkBuffer } from '../uhk-buffer.js'; @@ -976,7 +977,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo this.keyBacklightBrightness = jsonObject.keyBacklightBrightness; this.ledsFadeTimeout = jsonObject.ledsFadeTimeout; this.perKeyRgbPresent = jsonObject.perKeyRgbPresent; - this.backlightingMode = BacklightingMode[jsonObject.backlightingMode as string]; + this.backlightingMode = fromStringUnsafe(BacklightingMode, jsonObject.backlightingMode); this.backlightingNoneActionColor = new RgbColor().fromJsonObject(jsonObject.backlightingNoneActionColor, this.userConfigMajorVersion); this.backlightingScancodeColor = new RgbColor().fromJsonObject(jsonObject.backlightingScancodeColor, this.userConfigMajorVersion); this.backlightingModifierColor = new RgbColor().fromJsonObject(jsonObject.backlightingModifierColor, this.userConfigMajorVersion); @@ -996,13 +997,13 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo this.mouseScrollBaseSpeed = jsonObject.mouseScrollBaseSpeed; this.mouseScrollAcceleratedSpeed = jsonObject.mouseScrollAcceleratedSpeed; - this.secondaryRoleStrategy = SecondaryRoleStrategy[jsonObject.secondaryRoleStrategy as string]; + this.secondaryRoleStrategy = fromStringUnsafe(SecondaryRoleStrategy, jsonObject.secondaryRoleStrategy); this.secondaryRoleAdvancedStrategyDoubletapTimeout = jsonObject.secondaryRoleAdvancedStrategyDoubletapTimeout; this.secondaryRoleAdvancedStrategyTimeout = jsonObject.secondaryRoleAdvancedStrategyTimeout; this.secondaryRoleAdvancedStrategySafetyMargin = jsonObject.secondaryRoleAdvancedStrategySafetyMargin; this.secondaryRoleAdvancedStrategyTriggerByRelease = jsonObject.secondaryRoleAdvancedStrategyTriggerByRelease; this.secondaryRoleAdvancedStrategyDoubletapToPrimary = jsonObject.secondaryRoleAdvancedStrategyDoubletapToPrimary; - this.secondaryRoleAdvancedStrategyTimeoutAction = SecondaryRoleAdvancedStrategyTimeoutAction[jsonObject.secondaryRoleAdvancedStrategyTimeoutAction as string]; + this.secondaryRoleAdvancedStrategyTimeoutAction = fromStringUnsafe(SecondaryRoleAdvancedStrategyTimeoutAction, jsonObject.secondaryRoleAdvancedStrategyTimeoutAction); this.mouseScrollAxisSkew = jsonObject.mouseScrollAxisSkew; this.mouseMoveAxisSkew = jsonObject.mouseMoveAxisSkew; this.diagonalSpeedCompensation = jsonObject.diagonalSpeedCompensation; @@ -1028,7 +1029,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo this.setDefaultDeviceName(); this.doubleTapSwitchLayerTimeout = jsonObject.doubleTapSwitchLayerTimeout; this.perKeyRgbPresent = jsonObject.perKeyRgbPresent; - this.backlightingMode = BacklightingMode[jsonObject.backlightingMode as string]; + this.backlightingMode = fromStringUnsafe(BacklightingMode, jsonObject.backlightingMode); this.backlightingNoneActionColor = new RgbColor().fromJsonObject(jsonObject.backlightingNoneActionColor, this.userConfigMajorVersion); this.backlightingScancodeColor = new RgbColor().fromJsonObject(jsonObject.backlightingScancodeColor, this.userConfigMajorVersion); this.backlightingModifierColor = new RgbColor().fromJsonObject(jsonObject.backlightingModifierColor, this.userConfigMajorVersion); @@ -1048,13 +1049,13 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo this.mouseScrollBaseSpeed = jsonObject.mouseScrollBaseSpeed; this.mouseScrollAcceleratedSpeed = jsonObject.mouseScrollAcceleratedSpeed; - this.secondaryRoleStrategy = SecondaryRoleStrategy[jsonObject.secondaryRoleStrategy as string]; + this.secondaryRoleStrategy = fromStringUnsafe(SecondaryRoleStrategy, jsonObject.secondaryRoleStrategy); this.secondaryRoleAdvancedStrategyDoubletapTimeout = jsonObject.secondaryRoleAdvancedStrategyDoubletapTimeout; this.secondaryRoleAdvancedStrategyTimeout = jsonObject.secondaryRoleAdvancedStrategyTimeout; this.secondaryRoleAdvancedStrategySafetyMargin = jsonObject.secondaryRoleAdvancedStrategySafetyMargin; this.secondaryRoleAdvancedStrategyTriggerByRelease = jsonObject.secondaryRoleAdvancedStrategyTriggerByRelease; this.secondaryRoleAdvancedStrategyDoubletapToPrimary = jsonObject.secondaryRoleAdvancedStrategyDoubletapToPrimary; - this.secondaryRoleAdvancedStrategyTimeoutAction = SecondaryRoleAdvancedStrategyTimeoutAction[jsonObject.secondaryRoleAdvancedStrategyTimeoutAction as string]; + this.secondaryRoleAdvancedStrategyTimeoutAction = fromStringUnsafe(SecondaryRoleAdvancedStrategyTimeoutAction, jsonObject.secondaryRoleAdvancedStrategyTimeoutAction); this.mouseScrollAxisSkew = jsonObject.mouseScrollAxisSkew; this.mouseMoveAxisSkew = jsonObject.mouseMoveAxisSkew; this.diagonalSpeedCompensation = jsonObject.diagonalSpeedCompensation; @@ -1102,7 +1103,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo const serialisationInfo = this.getSerialisationInfo(); - this.backlightingMode = BacklightingMode[jsonObject.backlightingMode as string]; + this.backlightingMode = fromStringUnsafe(BacklightingMode, jsonObject.backlightingMode); this.backlightingNoneActionColor = new RgbColor().fromJsonObject(jsonObject.backlightingNoneActionColor, this.userConfigMajorVersion); this.backlightingScancodeColor = new RgbColor().fromJsonObject(jsonObject.backlightingScancodeColor, this.userConfigMajorVersion); this.backlightingModifierColor = new RgbColor().fromJsonObject(jsonObject.backlightingModifierColor, this.userConfigMajorVersion); @@ -1123,13 +1124,13 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo this.mouseScrollBaseSpeed = jsonObject.mouseScrollBaseSpeed; this.mouseScrollAcceleratedSpeed = jsonObject.mouseScrollAcceleratedSpeed; - this.secondaryRoleStrategy = SecondaryRoleStrategy[jsonObject.secondaryRoleStrategy as string]; + this.secondaryRoleStrategy = fromStringUnsafe(SecondaryRoleStrategy, jsonObject.secondaryRoleStrategy); this.secondaryRoleAdvancedStrategyDoubletapTimeout = jsonObject.secondaryRoleAdvancedStrategyDoubletapTimeout; this.secondaryRoleAdvancedStrategyTimeout = jsonObject.secondaryRoleAdvancedStrategyTimeout; this.secondaryRoleAdvancedStrategySafetyMargin = jsonObject.secondaryRoleAdvancedStrategySafetyMargin; this.secondaryRoleAdvancedStrategyTriggerByRelease = jsonObject.secondaryRoleAdvancedStrategyTriggerByRelease; this.secondaryRoleAdvancedStrategyDoubletapToPrimary = jsonObject.secondaryRoleAdvancedStrategyDoubletapToPrimary; - this.secondaryRoleAdvancedStrategyTimeoutAction = SecondaryRoleAdvancedStrategyTimeoutAction[jsonObject.secondaryRoleAdvancedStrategyTimeoutAction as string]; + this.secondaryRoleAdvancedStrategyTimeoutAction = fromStringUnsafe(SecondaryRoleAdvancedStrategyTimeoutAction, jsonObject.secondaryRoleAdvancedStrategyTimeoutAction); this.mouseScrollAxisSkew = jsonObject.mouseScrollAxisSkew; this.mouseMoveAxisSkew = jsonObject.mouseMoveAxisSkew; this.diagonalSpeedCompensation = jsonObject.diagonalSpeedCompensation; @@ -1137,11 +1138,11 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo this.keystrokeDelay = jsonObject.keystrokeDelay; if (isSerialisationInfoGte(serialisationInfo, '14.0.0')) { - this.secondaryRoleAdvancedStrategyTrigger = SecondaryRoleAdvancedStrategyTriggeringEvent[jsonObject.secondaryRoleAdvancedStrategyTrigger as string]; + this.secondaryRoleAdvancedStrategyTrigger = fromStringUnsafe(SecondaryRoleAdvancedStrategyTriggeringEvent, jsonObject.secondaryRoleAdvancedStrategyTrigger); this.secondaryRoleAdvancedStrategyTriggerByMouse = jsonObject.secondaryRoleAdvancedStrategyTriggerByMouse; this.secondaryRoleAdvancedStrategyTriggerFromSameHalf = jsonObject.secondaryRoleAdvancedStrategyTriggerFromSameHalf; this.secondaryRoleAdvancedStrategyMinimumHoldTime = jsonObject.secondaryRoleAdvancedStrategyMinimumHoldTime; - this.secondaryRoleAdvancedStrategyTimeoutType = SecondaryRoleAdvancedStrategyTimeoutType[jsonObject.secondaryRoleAdvancedStrategyTimeoutType as string]; + this.secondaryRoleAdvancedStrategyTimeoutType = fromStringUnsafe(SecondaryRoleAdvancedStrategyTimeoutType, jsonObject.secondaryRoleAdvancedStrategyTimeoutType); } this.displayBrightness = jsonObject.displayBrightness; @@ -1155,7 +1156,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo if (isSerialisationInfoGte(serialisationInfo, '9.99.0')) { this.keyBacklightBrightnessChargingDefault = jsonObject.keyBacklightBrightnessChargingDefault; - this.batteryChargingMode = BatteryChargingMode[jsonObject.batteryChargingMode as string]; + this.batteryChargingMode = fromStringUnsafe(BatteryChargingMode, jsonObject.batteryChargingMode); } if (isSerialisationInfoGte(serialisationInfo, '15.0.0')) { diff --git a/packages/uhk-common/src/models/hardware-modules.ts b/packages/uhk-common/src/models/hardware-modules.ts index 72600fe7c4c..f76c36a2ba3 100644 --- a/packages/uhk-common/src/models/hardware-modules.ts +++ b/packages/uhk-common/src/models/hardware-modules.ts @@ -12,7 +12,7 @@ export interface HardwareModules { rightModuleInfo?: RightModuleInfo; } -export function defaultHardwareModules() { +export function defaultHardwareModules(): HardwareModules { return { moduleInfos: [], rightModuleInfo: { diff --git a/packages/uhk-common/src/util/from-string-unsafe.ts b/packages/uhk-common/src/util/from-string-unsafe.ts new file mode 100644 index 00000000000..7d0d85e7c96 --- /dev/null +++ b/packages/uhk-common/src/util/from-string-unsafe.ts @@ -0,0 +1,7 @@ +/** + * Looks up an enum member by its name, e.g. fromStringUnsafe(MouseActionParam, 'leftClick') === MouseActionParam.leftClick. + * Unchecked: returns undefined for an unknown name. + */ +export function fromStringUnsafe(enumObject: E, name: unknown): E[keyof E] | undefined { + return enumObject[name as keyof E]; +} diff --git a/packages/uhk-common/src/util/index.ts b/packages/uhk-common/src/util/index.ts index be978009ff8..29d7e34f10f 100644 --- a/packages/uhk-common/src/util/index.ts +++ b/packages/uhk-common/src/util/index.ts @@ -7,6 +7,7 @@ export * from './create-md5-hash.js'; export * from './date-formatter.js'; export * from './disable-agent-upgrade-protection.js'; export * from './find-uhk-module-by-id.js'; +export * from './from-string-unsafe.js'; export * from './get-formatted-timestamp.js'; export * from './get-md5-hash-from-file-name.js'; export * from './get-slot-id-name.js'; diff --git a/packages/uhk-usb/src/uhk-operations.ts b/packages/uhk-usb/src/uhk-operations.ts index be2c84355ec..de024c8459b 100644 --- a/packages/uhk-usb/src/uhk-operations.ts +++ b/packages/uhk-usb/src/uhk-operations.ts @@ -1026,7 +1026,7 @@ export class UhkOperations { */ private async sendConfigToKeyboard( buffer: Buffer, - isUserConfiguration, + isUserConfiguration: boolean, onProgress?: ProgressCallback ): Promise { const command = isUserConfiguration diff --git a/packages/uhk-usb/src/utils/calculate-halves-state.ts b/packages/uhk-usb/src/utils/calculate-halves-state.ts index ad6b168027b..b52ce7b717a 100644 --- a/packages/uhk-usb/src/utils/calculate-halves-state.ts +++ b/packages/uhk-usb/src/utils/calculate-halves-state.ts @@ -1,4 +1,4 @@ -import {HalvesInfo, LeftSlotModules, RightSlotModules} from "uhk-common"; +import {fromStringUnsafe, HalvesInfo, LeftSlotModules, RightSlotModules} from "uhk-common"; import {DeviceState} from "../models/index.js"; @@ -6,7 +6,7 @@ export function calculateHalvesState(deviceState: DeviceState): HalvesInfo { return { areHalvesMerged: deviceState.areHalvesMerged, isLeftHalfConnected: deviceState.isLeftHalfConnected, - leftModuleSlot: LeftSlotModules[deviceState.leftModuleSlot], - rightModuleSlot: RightSlotModules[deviceState.rightModuleSlot] + leftModuleSlot: fromStringUnsafe(LeftSlotModules, deviceState.leftModuleSlot), + rightModuleSlot: fromStringUnsafe(RightSlotModules, deviceState.rightModuleSlot) }; } diff --git a/packages/uhk-usb/src/utils/convert-slave-i2c-error-buffer.ts b/packages/uhk-usb/src/utils/convert-slave-i2c-error-buffer.ts index 19f5b85820f..87fd4f99827 100644 --- a/packages/uhk-usb/src/utils/convert-slave-i2c-error-buffer.ts +++ b/packages/uhk-usb/src/utils/convert-slave-i2c-error-buffer.ts @@ -11,7 +11,7 @@ const SLAVE_ID_TO_NAME = [ 'kboot' ]; -const STATUS_CODE_TO_NAME = { +const STATUS_CODE_TO_NAME: Record = { 0: 'nak', 1: 'failure', 1100: 'busy', diff --git a/packages/uhk-web/src/app/app.component.ts b/packages/uhk-web/src/app/app.component.ts index e0cdf24a6b9..da957dfff1e 100644 --- a/packages/uhk-web/src/app/app.component.ts +++ b/packages/uhk-web/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { Component, HostListener, OnDestroy, ChangeDetectorRef, ViewChild, inject } from '@angular/core'; +import { Component, HostListener, OnDestroy, ChangeDetectorRef, TemplateRef, ViewChild, inject } from '@angular/core'; import { ActivatedRoute, Event, NavigationEnd, Router } from '@angular/router'; import { animate, style, transition, trigger } from '@angular/animations'; import { faPuzzlePiece, faArrowUp } from '@fortawesome/free-solid-svg-icons'; @@ -113,7 +113,7 @@ import { SecondSideMenuContainerComponent } from './components/side-menu'; }) export class MainAppComponent implements OnDestroy { @ViewChild(SecondSideMenuContainerComponent) secondarySideMenuContainer: SecondSideMenuContainerComponent; - @ViewChild('manuallyUpdateNotification', { static: true }) manuallyUpdateNotificationTmpl; + @ViewChild('manuallyUpdateNotification', { static: true }) manuallyUpdateNotificationTmpl: TemplateRef; donglePairingState: DonglePairingState; halvesPairingState: HalvesPairingState; diff --git a/packages/uhk-web/src/app/app.routes.ts b/packages/uhk-web/src/app/app.routes.ts index fb4427c75e9..266a8d4e43d 100644 --- a/packages/uhk-web/src/app/app.routes.ts +++ b/packages/uhk-web/src/app/app.routes.ts @@ -1,4 +1,4 @@ -import { ModuleWithProviders } from '@angular/core'; +import { ModuleWithProviders, Provider } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { deviceRoutes } from './components/device'; @@ -77,6 +77,6 @@ const appRoutes: Routes = [ } ]; -export const appRoutingProviders = []; +export const appRoutingProviders: Provider[] = []; export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, { useHash: true }); diff --git a/packages/uhk-web/src/app/components/auto-grow-input/auto-grow-input.component.ts b/packages/uhk-web/src/app/components/auto-grow-input/auto-grow-input.component.ts index 35209b5b1f1..91076093005 100644 --- a/packages/uhk-web/src/app/components/auto-grow-input/auto-grow-input.component.ts +++ b/packages/uhk-web/src/app/components/auto-grow-input/auto-grow-input.component.ts @@ -143,8 +143,8 @@ export class AutoGrowInputComponent implements ControlValueAccessor, AfterViewIn this._onChanged(this._model); } - keyEnter(event): void { - event.target.blur(); + keyEnter(event: Event): void { + (event.target as HTMLElement).blur(); } calculateTextWidth(text: string): void { diff --git a/packages/uhk-web/src/app/components/back-to/back-to.component.ts b/packages/uhk-web/src/app/components/back-to/back-to.component.ts index 887bb71e231..2f30890f7fe 100644 --- a/packages/uhk-web/src/app/components/back-to/back-to.component.ts +++ b/packages/uhk-web/src/app/components/back-to/back-to.component.ts @@ -15,7 +15,7 @@ export class BackToComponent implements OnDestroy { backUrl: string | undefined; backText: string; backSuffix = ''; - queryParams = {}; + queryParams: Record = {}; private readonly cdRef = inject(ChangeDetectorRef); private readonly route = inject(ActivatedRoute); diff --git a/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.ts b/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.ts index 9076606a691..55124e0b0dc 100644 --- a/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.ts +++ b/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.ts @@ -23,8 +23,8 @@ export class FirmwareFileUploadComponent { private _uploadFileData: UploadFileData; - changeFile(event): void { - const files = event.srcElement.files; + changeFile(event: Event): void { + const files = (event.target as HTMLInputElement).files; if (files.length === 0) { return; @@ -33,7 +33,7 @@ export class FirmwareFileUploadComponent { const fileReader = new FileReader(); fileReader.onloadend = () => { const arrayBuffer = new Uint8Array(fileReader.result as ArrayBuffer); - const target = event.target || event.srcElement || event.currentTarget; + const target = (event.target || event.srcElement || event.currentTarget) as HTMLInputElement; this._uploadFileData = { filename: target.value, data: Array.from(arrayBuffer), diff --git a/packages/uhk-web/src/app/components/device/host-connections/host-connections.component.ts b/packages/uhk-web/src/app/components/device/host-connections/host-connections.component.ts index be393b69e93..907c2819035 100644 --- a/packages/uhk-web/src/app/components/device/host-connections/host-connections.component.ts +++ b/packages/uhk-web/src/app/components/device/host-connections/host-connections.component.ts @@ -169,7 +169,7 @@ export class HostConnectionsComponent implements OnInit, OnDestroy { } } - private setUserConfigurationValue(propertyName: string, value: boolean): void { + private setUserConfigurationValue(propertyName: keyof HostConnectionsComponent, value: boolean): void { const hasChanged = this[propertyName] !== value; if (hasChanged) { diff --git a/packages/uhk-web/src/app/components/device/typing-behavior-page/typing-behavior-page.component.ts b/packages/uhk-web/src/app/components/device/typing-behavior-page/typing-behavior-page.component.ts index 1cdbc9c494b..ac66d18c558 100644 --- a/packages/uhk-web/src/app/components/device/typing-behavior-page/typing-behavior-page.component.ts +++ b/packages/uhk-web/src/app/components/device/typing-behavior-page/typing-behavior-page.component.ts @@ -114,7 +114,7 @@ export class TypingBehaviorPage implements AdvancedSecondaryRoleConfiguration, O this.store.dispatch(new LoadTypingBehaviorPresetAction(name)); } - onSetPropertyValue(propertyName: string, value: number): void { + onSetPropertyValue(propertyName: keyof TypingBehaviorPage, value: number): void { // The slider fires a change event after preset loaded otherwise it Changes the Simple preset to Advanced if (this[propertyName] === value) { return; diff --git a/packages/uhk-web/src/app/components/file-upload/file-upload.component.ts b/packages/uhk-web/src/app/components/file-upload/file-upload.component.ts index f1cbb74f885..d08bd63e483 100644 --- a/packages/uhk-web/src/app/components/file-upload/file-upload.component.ts +++ b/packages/uhk-web/src/app/components/file-upload/file-upload.component.ts @@ -14,8 +14,8 @@ export class FileUploadComponent { @Output() fileChanged = new EventEmitter(); - changeFile(event): void { - const files = event.srcElement.files; + changeFile(event: Event): void { + const files = (event.target as HTMLInputElement).files; if (files.length === 0) { return; @@ -24,7 +24,7 @@ export class FileUploadComponent { const fileReader = new FileReader(); fileReader.onloadend = function () { const arrayBuffer = new Uint8Array(fileReader.result as ArrayBuffer); - const target = event.target || event.srcElement || event.currentTarget; + const target = (event.target || event.srcElement || event.currentTarget) as HTMLInputElement; this.fileChanged.emit({ filename: target.value, data: Array.from(arrayBuffer) diff --git a/packages/uhk-web/src/app/components/layers/layer-option.component.ts b/packages/uhk-web/src/app/components/layers/layer-option.component.ts index 02b7c17ffbb..2e4f95d8b6e 100644 --- a/packages/uhk-web/src/app/components/layers/layer-option.component.ts +++ b/packages/uhk-web/src/app/components/layers/layer-option.component.ts @@ -42,7 +42,7 @@ export class LayerOptionComponent { }); } - onCheckboxChange(event): void { + onCheckboxChange(event: boolean): void { console.log('checkbox', event); } diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/command/macro-command-editor.component.ts b/packages/uhk-web/src/app/components/macro/action-editor/tab/command/macro-command-editor.component.ts index 9c1d6de79ce..c9d4d4ee57f 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/command/macro-command-editor.component.ts +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/command/macro-command-editor.component.ts @@ -271,7 +271,7 @@ export class MacroCommandEditorComponent implements AfterViewInit, ControlValueA this.setCursorPosition(); if (!this.changeObserver$) { - Observable.create(observer => { + Observable.create((observer: Observer) => { this.changeObserver$ = observer; }).pipe( debounceTime(MACRO_CHANGE_DEBOUNCE_TIME), diff --git a/packages/uhk-web/src/app/components/popover/tab/keypress/keypress-tab.component.ts b/packages/uhk-web/src/app/components/popover/tab/keypress/keypress-tab.component.ts index 15b65d39fd9..0232038ff69 100644 --- a/packages/uhk-web/src/app/components/popover/tab/keypress/keypress-tab.component.ts +++ b/packages/uhk-web/src/app/components/popover/tab/keypress/keypress-tab.component.ts @@ -15,6 +15,7 @@ import { Store } from '@ngrx/store'; import { Subscription } from 'rxjs'; import { copyRgbColor, + fromStringUnsafe, getScancodesForKeyLanguage, KeyAction, KeyLanguage, @@ -154,7 +155,7 @@ export class KeypressTabComponent extends Tab implements OnChanges, OnDestroy { if (scTypePair[1] === 'media') { keystrokeAction.type = keystrokeAction.scancode > 255 ? KeystrokeType.longMedia : KeystrokeType.shortMedia; } else { - keystrokeAction.type = KeystrokeType[scTypePair[1]]; + keystrokeAction.type = fromStringUnsafe(KeystrokeType, scTypePair[1]); } keystrokeAction.modifierMask = mapLeftRightModifierToKeyActionModifier(this.leftModifiers, this.rightModifiers); diff --git a/packages/uhk-web/src/app/components/resize.ts b/packages/uhk-web/src/app/components/resize.ts index 67b8438336a..05fdb90968f 100644 --- a/packages/uhk-web/src/app/components/resize.ts +++ b/packages/uhk-web/src/app/components/resize.ts @@ -130,7 +130,7 @@ function createResizeStream( zone.runOutsideAngular(() => { if (emitInitialResult) { const [result] = calculateResult(nativeElement, window, offsetSize, []); - if (emitInZone) zone.run(() => void subscriber.next(result)); + if (emitInZone) zone.run((): void => void subscriber.next(result)); else subscriber.next(result); } @@ -138,13 +138,13 @@ function createResizeStream( lastEntries = entries; const [result, size] = calculateResult(nativeElement, window, offsetSize, entries); - if (emitInZone) zone.run(() => void subscriber.next(result)); + if (emitInZone) zone.run((): void => void subscriber.next(result)); else subscriber.next(result); if (!areBoundsEqual(lastBounds || {} as Omit, size)) lastBounds = size; }; - const boundCallback = () => void callback(lastEntries); + const boundCallback = (): void => void callback(lastEntries); observer = new ResizeObserver(callback); diff --git a/packages/uhk-web/src/app/components/side-menu/second-side-menu-container.component.ts b/packages/uhk-web/src/app/components/side-menu/second-side-menu-container.component.ts index c438be15992..37b9b452e6f 100644 --- a/packages/uhk-web/src/app/components/side-menu/second-side-menu-container.component.ts +++ b/packages/uhk-web/src/app/components/side-menu/second-side-menu-container.component.ts @@ -15,7 +15,7 @@ import { template: '' })) export class SecondSideMenuContainerComponent { - @ViewChild('secondaryContainer', { read: ViewContainerRef }) container; + @ViewChild('secondaryContainer', { read: ViewContainerRef }) container: ViewContainerRef; private readonly cdRef = inject(ChangeDetectorRef); private readonly componentFactoryResolver = inject(ComponentFactoryResolver); diff --git a/packages/uhk-web/src/app/components/slider-wrapper/slider-wrapper.component.ts b/packages/uhk-web/src/app/components/slider-wrapper/slider-wrapper.component.ts index ff419c8af70..e250ba184c8 100644 --- a/packages/uhk-web/src/app/components/slider-wrapper/slider-wrapper.component.ts +++ b/packages/uhk-web/src/app/components/slider-wrapper/slider-wrapper.component.ts @@ -214,7 +214,7 @@ export class SliderWrapperComponent implements ControlValueAccessor, OnDestroy { private propagateValueChange(value: number, skipFirstChange = false): void { if (!this.changeObserver$) { - Observable.create(observer => { + Observable.create((observer: Observer) => { this.changeObserver$ = observer; }).pipe( debounceTime(this.changeDebounceTime), diff --git a/packages/uhk-web/src/app/components/svg/module/svg-module.model.ts b/packages/uhk-web/src/app/components/svg/module/svg-module.model.ts index 587fda08e63..0aa2abe98a8 100644 --- a/packages/uhk-web/src/app/components/svg/module/svg-module.model.ts +++ b/packages/uhk-web/src/app/components/svg/module/svg-module.model.ts @@ -2,8 +2,10 @@ import { SvgKeyboardKey } from '../keys'; export class SvgModule { // circle svg elements that not programmable. Part of the coverages - circles = []; - coverages = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + circles: any[] = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + coverages: any[] = []; keyboardKeys: SvgKeyboardKey[]; // eslint-disable-next-line @typescript-eslint/no-explicit-any attributes: any; @@ -14,7 +16,7 @@ export class SvgModule { moduleNavPath: any; // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(obj: { rect: any[], path: any[], $: Object, circle?: any[], g?: any[] }) { + constructor(obj: { rect: any[], path: any[], $: Record, circle?: any[], g?: any[] }) { this.keyboardKeys = []; if (obj.rect) { const keys = obj.rect.map(rect => rect.$); @@ -100,7 +102,8 @@ export class SvgModule { }; if (g.path) { - key.elements.paths = g.path.map(path => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + key.elements.paths = g.path.map((path: any) => { path = path.$; const style = parseStyle(path.style as string); @@ -113,7 +116,8 @@ export class SvgModule { } if (g.circle) { - key.elements.circles = g.circle.map(circle => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + key.elements.circles = g.circle.map((circle: any) => { circle = circle.$; const style = parseStyle(circle.style as string); @@ -128,7 +132,7 @@ export class SvgModule { } if (g.rect) { - const rect = g.rect.find(r => r.$.id.endsWith('print')); + const rect = g.rect.find((r: { $: Record }) => r.$.id.endsWith('print')); if (rect) { key.x = +rect.$.x; key.y = +rect.$.y; @@ -159,7 +163,7 @@ function parseStyle(style: string): Record | undefined { return style .split(';') - .reduce((result: unknown, value: string) => { + .reduce((result: Record, value: string) => { const split = value.split(':'); if (split.length < 2) { return result; diff --git a/packages/uhk-web/src/app/custom-fa-icons/fa-battery-full.ts b/packages/uhk-web/src/app/custom-fa-icons/fa-battery-full.ts index 3e54e193ae6..0712b602bef 100644 --- a/packages/uhk-web/src/app/custom-fa-icons/fa-battery-full.ts +++ b/packages/uhk-web/src/app/custom-fa-icons/fa-battery-full.ts @@ -4,8 +4,8 @@ const prefix = 'far'; const iconName = 'faBatteryFull'; const width = 576; const height = 512; -const ligatures = []; -const unicode = undefined; +const ligatures: string[] = []; +const unicode: string = undefined; const svgPathData = 'M464 144c17.7 0 32 14.3 32 32l0 160c0 17.7-14.3 32-32 32L80 368c-17.7 0-32-14.3-32-32l0-160c0-17.7 14.3-32 32-32l384 0zM80 96C35.8 96 0 131.8 0 176L0 336c0 44.2 35.8 80 80 80l384 0c44.2 0 80-35.8 80-80l0-16c17.7 0 32-14.3 32-32l0-64c0-17.7-14.3-32-32-32l0-16c0-44.2-35.8-80-80-80L80 96zm368 96L96 192l0 128 352 0 0-128z'; export const faBatteryFull: IconDefinition = { diff --git a/packages/uhk-web/src/app/custom-fa-icons/fa-brackets-with-dots.ts b/packages/uhk-web/src/app/custom-fa-icons/fa-brackets-with-dots.ts index f9d6c3ba04f..6ee13d77589 100644 --- a/packages/uhk-web/src/app/custom-fa-icons/fa-brackets-with-dots.ts +++ b/packages/uhk-web/src/app/custom-fa-icons/fa-brackets-with-dots.ts @@ -4,8 +4,8 @@ const prefix = 'far'; const iconName = 'faBracketsWithDots'; const width = 512; const height = 512; -const ligatures = []; -const unicode = undefined; +const ligatures: string[] = []; +const unicode: string = undefined; const svgPathData = 'M32 64h120v32H64v320h88v32H32V64zm328 0h120v384H360v-32h88V96h-88V64zM176 232a24 24 0 1 1 0 48 24 24 0 1 1 0-48zm80 0a24 24 0 1 1 0 48 24 24 0 1 1 0-48zm80 0a24 24 0 1 1 0 48 24 24 0 1 1 0-48z'; export const faBracketsWithDots: IconDefinition = { diff --git a/packages/uhk-web/src/app/custom-fa-icons/fa-sparkle.ts b/packages/uhk-web/src/app/custom-fa-icons/fa-sparkle.ts index d1014eab703..7840a2ac7b9 100644 --- a/packages/uhk-web/src/app/custom-fa-icons/fa-sparkle.ts +++ b/packages/uhk-web/src/app/custom-fa-icons/fa-sparkle.ts @@ -4,8 +4,8 @@ const prefix = 'fas'; const iconName = 'faSparkle'; const width = 512; const height = 512; -const ligatures = []; -const unicode = undefined; +const ligatures: string[] = []; +const unicode: string = undefined; const svgPathData = 'M245.8 45.9C241.9 37.4 233.4 32 224 32s-17.9 5.4-21.8 13.9L142.7 174.7 13.9 234.2C5.4 238.1 0 246.6 0 256s5.4 17.9 13.9 21.8l128.8 59.5 59.5 128.8c3.9 8.5 12.4 13.9 21.8 13.9s17.9-5.4 21.8-13.9l59.5-128.8 128.8-59.5c8.5-3.9 13.9-12.4 13.9-21.8s-5.4-17.9-13.9-21.8L305.3 174.7 245.8 45.9z'; export const faSparkle: IconDefinition = { diff --git a/packages/uhk-web/src/app/custom-fa-icons/fa-square-a.ts b/packages/uhk-web/src/app/custom-fa-icons/fa-square-a.ts index 4c143ab5427..3a90a348aab 100644 --- a/packages/uhk-web/src/app/custom-fa-icons/fa-square-a.ts +++ b/packages/uhk-web/src/app/custom-fa-icons/fa-square-a.ts @@ -4,8 +4,8 @@ const prefix = 'fas'; const iconName = 'faSquareA'; const width = 512; const height = 512; -const ligatures = []; -const unicode = undefined; +const ligatures: string[] = []; +const unicode: string = undefined; const svgPathData = 'M 48 32 C 21.5 32 0 53.5 0 80 L 0 432 C 0 458.5 21.5 480 48 480 L 400 480 C 426.5 480 448 458.5 448 432 L 448 80 C 448 53.5 426.5 32 400 32 L 48 32 z M 203.98047 112.54297 L 247.92578 112.54297 L 352.02734 399.45703 L 309.44922 399.45703 L 280.34766 313.51953 L 166.87109 313.51953 L 135.81641 399.45703 L 95.972656 399.45703 L 203.98047 112.54297 z M 224.29297 155.12109 L 178.00391 281.87891 L 267.84766 281.87891 L 224.29297 155.12109 z'; export const faSquareA: IconDefinition = { diff --git a/packages/uhk-web/src/app/directives/ng-select-max-height.ts b/packages/uhk-web/src/app/directives/ng-select-max-height.ts index 95b069bb320..cc1527ffe1f 100644 --- a/packages/uhk-web/src/app/directives/ng-select-max-height.ts +++ b/packages/uhk-web/src/app/directives/ng-select-max-height.ts @@ -45,6 +45,6 @@ export class NgSelectMaxHeight implements OnDestroy { dropdownPanel.classList.add('ng-select-bottom'); } - dropdownPanelItems.style['max-height'] = `${newHeight}px`; + dropdownPanelItems.style.maxHeight = `${newHeight}px`; } } diff --git a/packages/uhk-web/src/app/pages/main-page/main.page.ts b/packages/uhk-web/src/app/pages/main-page/main.page.ts index d3bf9534b18..378860d077f 100644 --- a/packages/uhk-web/src/app/pages/main-page/main.page.ts +++ b/packages/uhk-web/src/app/pages/main-page/main.page.ts @@ -10,7 +10,7 @@ export class MainPage { constructor() { } - onActivate(e, outlet) { + onActivate(e: unknown, outlet: HTMLElement) { outlet.scrollIntoView(); } } diff --git a/packages/uhk-web/src/app/services/app-renderer.service.ts b/packages/uhk-web/src/app/services/app-renderer.service.ts index 176d7224989..01602d16d4e 100644 --- a/packages/uhk-web/src/app/services/app-renderer.service.ts +++ b/packages/uhk-web/src/app/services/app-renderer.service.ts @@ -55,8 +55,9 @@ export class AppRendererService { })); }); - this.ipcRenderer.on('__ELECTRON_LOG_IPC__', (event: string, { level, data }) => { - const message = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.ipcRenderer.on('__ELECTRON_LOG_IPC__', (event: string, { level, data }: { level: string, data: any[] }) => { + const message: string[] = []; if (data.length > 0 && data[data.length - 1]?.substr diff --git a/packages/uhk-web/src/app/store/reducers/advanced-settings.reducer.ts b/packages/uhk-web/src/app/store/reducers/advanced-settings.reducer.ts index 2aa64c61306..5e4708cabb5 100644 --- a/packages/uhk-web/src/app/store/reducers/advanced-settings.reducer.ts +++ b/packages/uhk-web/src/app/store/reducers/advanced-settings.reducer.ts @@ -188,7 +188,7 @@ export function reducer(state = initialState(), action: Actions | App.Actions | } case ActionTypes.toggleI2CDebugging: { - const newState = { + const newState: State = { ...state, i2cLogs: [], activeButton: state.activeButton === ActiveButton.I2CRecoveryDebugging diff --git a/packages/uhk-web/src/app/store/reducers/progress-button-state.ts b/packages/uhk-web/src/app/store/reducers/progress-button-state.ts index 23e9d2c0461..ca496b05099 100644 --- a/packages/uhk-web/src/app/store/reducers/progress-button-state.ts +++ b/packages/uhk-web/src/app/store/reducers/progress-button-state.ts @@ -9,7 +9,7 @@ export interface ProgressButtonState { action?: Action; } -export const initProgressButtonState = { +export const initProgressButtonState: ProgressButtonState = { showButton: false, text: null, showProgress: false, diff --git a/packages/uhk-web/src/app/store/reducers/user-configuration.ts b/packages/uhk-web/src/app/store/reducers/user-configuration.ts index c15ba77144c..1ef462ee1a5 100644 --- a/packages/uhk-web/src/app/store/reducers/user-configuration.ts +++ b/packages/uhk-web/src/app/store/reducers/user-configuration.ts @@ -961,7 +961,7 @@ export function reducer( } case MacroActions.ActionTypes.Remove: { - const newState = { + const newState: State = { ...state, selectedMacroId: undefined }; @@ -1229,7 +1229,7 @@ export function reducer( userConfiguration.moduleConfigurations = userConfiguration.moduleConfigurations.map(moduleConfiguration => { if(moduleConfiguration.id === payload.moduleId) { moduleConfiguration = new ModuleConfiguration(moduleConfiguration); - moduleConfiguration[payload.propertyName] = payload.value; + (moduleConfiguration as unknown as Record)[payload.propertyName] = payload.value; return moduleConfiguration; } @@ -1245,7 +1245,7 @@ export function reducer( case UserConfig.ActionTypes.SetUserConfigurationRgbValue: { const payload = (action as UserConfig.SetUserConfigurationRgbValueAction).payload; const userConfiguration: UserConfiguration = Object.assign(new UserConfiguration(), state.userConfiguration); - userConfiguration[payload.propertyName] = new RgbColor(payload.value); + (userConfiguration as unknown as Record)[payload.propertyName] = new RgbColor(payload.value); return { ...state, @@ -1260,7 +1260,7 @@ export function reducer( ...state, userConfiguration, }; - userConfiguration[payload.propertyName] = payload.value; + (userConfiguration as unknown as Record)[payload.propertyName] = payload.value; if (payload.propertyName === 'backlightingMode') { newState.selectedBacklightingColorIndex = -1; @@ -1306,7 +1306,7 @@ export function reducer( } case KeymapActions.ActionTypes.Select: { - const newState = { + const newState: State = { ...state, selectedKeymapAbbr: (action as KeymapActions.SelectKeymapAction).payload, lastEditedKey: defaultLastEditKey(), @@ -1648,7 +1648,7 @@ function checkExistence(layers: Layer[], property: string, value: any): Layer[] const keyActions = modules[moduleIdx].keyActions; for (let keyActionIdx = 0; keyActionIdx < keyActions.length; ++keyActionIdx) { const action = keyActions[keyActionIdx]; - if (action && action.hasOwnProperty(property) && action[property] === value) { + if (action && action.hasOwnProperty(property) && (action as unknown as Record)[property] === value) { keyActionsToClear.push({ layerIdx, moduleIdx, diff --git a/packages/uhk-web/src/app/util/status-buffer-parser.ts b/packages/uhk-web/src/app/util/status-buffer-parser.ts index 9b0dc4d3cca..164609edf3c 100644 --- a/packages/uhk-web/src/app/util/status-buffer-parser.ts +++ b/packages/uhk-web/src/app/util/status-buffer-parser.ts @@ -12,7 +12,7 @@ export function parseStatusBuffer(macros: Macro[], statusBuffer: string): string } function splitToErrorBlocks(text: string): string[] { - const errorBlocks = []; + const errorBlocks: string[] = []; const lines = text.split('\n'); let block = ''; diff --git a/packages/uhk-web/src/renderer/services/ipc-uhk-renderer.ts b/packages/uhk-web/src/renderer/services/ipc-uhk-renderer.ts index 7aa4f68a6db..d9f1f875a92 100644 --- a/packages/uhk-web/src/renderer/services/ipc-uhk-renderer.ts +++ b/packages/uhk-web/src/renderer/services/ipc-uhk-renderer.ts @@ -6,7 +6,7 @@ export class IpcUhkRenderer implements IpcCommonRenderer { (window as any).electron.ipcRenderer.send(channel, args); } - public on(channel: string, listener: (_, ...args: any[]) => void): this { + public on(channel: string, listener: (_: unknown, ...args: any[]) => void): this { (window as any).electron.ipcRenderer.on(channel, listener); return this; } diff --git a/packages/usb/debug-i2c.ts b/packages/usb/debug-i2c.ts index ab27593f89e..3b866efaace 100755 --- a/packages/usb/debug-i2c.ts +++ b/packages/usb/debug-i2c.ts @@ -9,7 +9,7 @@ const argv = yargs .argv; const { operations } = Uhk(argv); -let i2cRecovery; +let i2cRecovery: number; setInterval(async function () { try { diff --git a/packages/usb/send-command.ts b/packages/usb/send-command.ts index 568224aa8ef..6bf6fce3fb9 100755 --- a/packages/usb/send-command.ts +++ b/packages/usb/send-command.ts @@ -16,7 +16,7 @@ try { const { device } = Uhk(argv); - const buffer = Buffer.from(argv._.map(arg => parseInt(arg, 10))); + const buffer = Buffer.from(argv._.map((arg: string | number) => parseInt(String(arg), 10))); const response = await device.write(buffer); diff --git a/packages/usb/set-variable.ts b/packages/usb/set-variable.ts index c323cc8c9a8..8b72f3c1da8 100755 --- a/packages/usb/set-variable.ts +++ b/packages/usb/set-variable.ts @@ -1,5 +1,6 @@ #!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning +import { fromStringUnsafe } from 'uhk-common'; import { UhkHidDevice, UhkOperations, @@ -40,13 +41,13 @@ try { for (const hidDevice of hidDevices) { const uhkHidDevice = new UhkHidDevice(logger, argv, rootDir, hidDevice); const uhkOperations = new UhkOperations(logger, uhkHidDevice); - await uhkOperations.setVariable(UsbVariables[variable], value); + await uhkOperations.setVariable(fromStringUnsafe(UsbVariables, variable), value); } } else { const { operations } = Uhk(argv); - await operations.setVariable(UsbVariables[variable], value); + await operations.setVariable(fromStringUnsafe(UsbVariables, variable), value); } } catch (error) { await errorHandler(error); diff --git a/packages/usb/shell.ts b/packages/usb/shell.ts index 6a73aa9c2cd..58077ef08e7 100755 --- a/packages/usb/shell.ts +++ b/packages/usb/shell.ts @@ -103,7 +103,7 @@ try { let stdinClosed = false; let idleMs = 0; - const initialCommand = argv._.map(arg => String(arg)).join(' '); + const initialCommand = argv._.map((arg: string | number) => String(arg)).join(' '); if (initialCommand.length > 0) { pending.push(initialCommand); } diff --git a/packages/usb/src/error-handler.ts b/packages/usb/src/error-handler.ts index a7e42b5855e..aba49228e98 100644 --- a/packages/usb/src/error-handler.ts +++ b/packages/usb/src/error-handler.ts @@ -8,7 +8,8 @@ import { import { InvalidArgumentError } from './invalid-argument-error.js'; -export async function errorHandler(error) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export async function errorHandler(error: any) { if (error instanceof InvalidArgumentError) { console.error(error.message); } diff --git a/packages/usb/src/types/yargs.d.ts b/packages/usb/src/types/yargs.d.ts new file mode 100644 index 00000000000..6f4a3a9bf3c --- /dev/null +++ b/packages/usb/src/types/yargs.d.ts @@ -0,0 +1,9 @@ +// yargs 18 ships no typings and @types/yargs (17.x) does not match the scripts' untyped argv usage. +declare module 'yargs' { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export default function yargs(args?: string[]): any; +} + +declare module 'yargs/helpers' { + export function hideBin(argv: string[]): string[]; +} diff --git a/packages/usb/src/util/get-i2c-address-from-arg.ts b/packages/usb/src/util/get-i2c-address-from-arg.ts index 89163ba5677..db29cb4a270 100644 --- a/packages/usb/src/util/get-i2c-address-from-arg.ts +++ b/packages/usb/src/util/get-i2c-address-from-arg.ts @@ -1,4 +1,4 @@ -import { ModuleSlotToI2cAddress } from 'uhk-common'; +import { fromStringUnsafe, ModuleSlotToI2cAddress } from 'uhk-common'; import { InvalidArgumentError } from '../invalid-argument-error.js'; @@ -9,7 +9,7 @@ export function getI2cAddressArgs(): string { } export function getI2cAddressFromArg(arg: string): ModuleSlotToI2cAddress { - const i2cAddress = ModuleSlotToI2cAddress[arg]; + const i2cAddress = fromStringUnsafe(ModuleSlotToI2cAddress, arg); if (i2cAddress) { return i2cAddress; diff --git a/packages/usb/src/util/get-module-slot-id-from-arg.ts b/packages/usb/src/util/get-module-slot-id-from-arg.ts index 24db2787ada..99d4b454958 100644 --- a/packages/usb/src/util/get-module-slot-id-from-arg.ts +++ b/packages/usb/src/util/get-module-slot-id-from-arg.ts @@ -1,4 +1,4 @@ -import { ModuleSlotToId } from 'uhk-common'; +import { fromStringUnsafe, ModuleSlotToId } from 'uhk-common'; import { InvalidArgumentError } from '../invalid-argument-error.js'; @@ -9,7 +9,7 @@ export function getModuleSlotIdArgs(): string { } export function getModuleSlotIdFromArg(arg: string): ModuleSlotToId { - const moduleSlotToId = ModuleSlotToId[arg]; + const moduleSlotToId = fromStringUnsafe(ModuleSlotToId, arg); if (moduleSlotToId) { return moduleSlotToId; diff --git a/tsconfig.json b/tsconfig.json index da85c76719b..10c6983e064 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,8 @@ "experimentalDecorators": true, "target": "ES2024", "importHelpers": true, - "resolveJsonModule": true + "resolveJsonModule": true, + "noImplicitAny": true }, "ts-node": { "esm": true,