diff --git a/eslint.config.mjs b/eslint.config.mjs index 58e7c9e46db..a317a5e9cb1 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -14,7 +14,6 @@ export const typescriptRules = { '@typescript-eslint/no-empty-object-type': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-misused-promises': 'off', - '@typescript-eslint/no-namespace': 'off', '@typescript-eslint/no-redundant-type-constituents': 'off', '@typescript-eslint/no-unnecessary-type-assertion': 'off', '@typescript-eslint/no-unsafe-argument': 'off', diff --git a/packages/uhk-agent/src/services/logger.service.ts b/packages/uhk-agent/src/services/logger.service.ts index 5e1a71bf700..8a17e03c791 100644 --- a/packages/uhk-agent/src/services/logger.service.ts +++ b/packages/uhk-agent/src/services/logger.service.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import * as log from 'electron-log/main'; -import { logUserConfigHelper, LogService, LogRegExps, UserConfiguration } from 'uhk-common'; +import { logUserConfigHelper, LogService, LOG_READ_REG_EXP, LOG_WRITE_REG_EXP, UserConfiguration } from 'uhk-common'; /** * This service use the electron-log package to write log in file. @@ -46,9 +46,9 @@ export class ElectronLogService extends LogService { return; } - if (LogRegExps.writeRegExp.test(args[0])) { + if (LOG_WRITE_REG_EXP.test(args[0])) { this.log('%c' + args.join(' '), 'color:blue'); - } else if (LogRegExps.readRegExp.test(args[0])) { + } else if (LOG_READ_REG_EXP.test(args[0])) { let errorCodeStartIndex = 0; let errorCodeEndIndex = 2; 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 83a471aea0d..4d99d1f5b7e 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,5 @@ import { assertEnum, assertFloat, assertInt16, assertUInt16, assertUInt32, assertUInt8 } from '../assert.js'; -import { ConfigSerializer } from '../config-serializer.js'; +import { resolveSwitchKeymapActions } from '../resolve-switch-keymap-actions.js'; import { UhkBuffer } from '../uhk-buffer.js'; import { AdvancedSecondaryRoleConfiguration } from './advanced-secondary-role-configuration.js'; import { BacklightingMode } from './backlighting-mode.js'; @@ -598,7 +598,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo return macro; }); this.keymaps = buffer.readArray(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo)); - ConfigSerializer.resolveSwitchKeymapActions(this.keymaps); + resolveSwitchKeymapActions(this.keymaps); } @@ -641,7 +641,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo return macro; }); this.keymaps = buffer.readArray(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo)); - ConfigSerializer.resolveSwitchKeymapActions(this.keymaps); + resolveSwitchKeymapActions(this.keymaps); } @@ -698,7 +698,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo return macro; }); this.keymaps = buffer.readArray(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo)); - ConfigSerializer.resolveSwitchKeymapActions(this.keymaps); + resolveSwitchKeymapActions(this.keymaps); } @@ -770,7 +770,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo return macro; }); this.keymaps = buffer.readArray(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo)); - ConfigSerializer.resolveSwitchKeymapActions(this.keymaps); + resolveSwitchKeymapActions(this.keymaps); } @@ -867,7 +867,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo this.lastSaveFirmwareTag = buffer.readString(); } - ConfigSerializer.resolveSwitchKeymapActions(this.keymaps); + resolveSwitchKeymapActions(this.keymaps); } diff --git a/packages/uhk-common/src/config-serializer/config-serializer.ts b/packages/uhk-common/src/config-serializer/config-serializer.ts deleted file mode 100644 index c76647754cf..00000000000 --- a/packages/uhk-common/src/config-serializer/config-serializer.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Keymap } from './config-items/keymap.js'; -import { UnresolvedSwitchKeymapAction } from './config-items/key-action/switch-keymap-action.js'; - -export namespace ConfigSerializer { - - export function resolveSwitchKeymapActions(keymaps: Keymap[]) { - for (const keymap of keymaps) { - for (const layer of keymap.layers) { - for (const module of layer.modules) { - for (let i = 0; i < module.keyActions.length; ++i) { - const keyAction = module.keyActions[i]; - if (keyAction instanceof UnresolvedSwitchKeymapAction) { - module.keyActions[i] = keyAction.resolve(keymaps); - } - } - } - } - } - } -} diff --git a/packages/uhk-common/src/config-serializer/index.ts b/packages/uhk-common/src/config-serializer/index.ts index 7123cdd483b..528e5ea9082 100644 --- a/packages/uhk-common/src/config-serializer/index.ts +++ b/packages/uhk-common/src/config-serializer/index.ts @@ -1,4 +1,4 @@ export * from './config-items/index.js'; export * from './assert.js'; -export * from './config-serializer.js'; +export * from './resolve-switch-keymap-actions.js'; export * from './uhk-buffer.js'; diff --git a/packages/uhk-common/src/config-serializer/resolve-switch-keymap-actions.ts b/packages/uhk-common/src/config-serializer/resolve-switch-keymap-actions.ts new file mode 100644 index 00000000000..ecba1ba7bb4 --- /dev/null +++ b/packages/uhk-common/src/config-serializer/resolve-switch-keymap-actions.ts @@ -0,0 +1,17 @@ +import { Keymap } from './config-items/keymap.js'; +import { UnresolvedSwitchKeymapAction } from './config-items/key-action/switch-keymap-action.js'; + +export function resolveSwitchKeymapActions(keymaps: Keymap[]) { + for (const keymap of keymaps) { + for (const layer of keymap.layers) { + for (const module of layer.modules) { + for (let i = 0; i < module.keyActions.length; ++i) { + const keyAction = module.keyActions[i]; + if (keyAction instanceof UnresolvedSwitchKeymapAction) { + module.keyActions[i] = keyAction.resolve(keymaps); + } + } + } + } + } +} diff --git a/packages/uhk-common/src/log/log-reg-exps.ts b/packages/uhk-common/src/log/log-reg-exps.ts index 1f7131b1700..34f4fcdc3cb 100644 --- a/packages/uhk-common/src/log/log-reg-exps.ts +++ b/packages/uhk-common/src/log/log-reg-exps.ts @@ -1,4 +1,2 @@ -export namespace LogRegExps { - export const writeRegExp = /USB\[W]:/; - export const readRegExp = /USB\[R]:/; -} +export const LOG_WRITE_REG_EXP = /USB\[W]:/; +export const LOG_READ_REG_EXP = /USB\[R]:/; diff --git a/packages/uhk-common/src/util/constants.ts b/packages/uhk-common/src/util/constants.ts index 7ccfc0dfa20..5e78ec0019e 100644 --- a/packages/uhk-common/src/util/constants.ts +++ b/packages/uhk-common/src/util/constants.ts @@ -1,10 +1,8 @@ -export namespace Constants { - export const AGENT_GITHUB_URL = 'https://github.com/UltimateHackingKeyboard/agent'; - export const AGENT_CONTRIBUTORS_GITHUB_PAGE_URL = 'https://github.com/UltimateHackingKeyboard/agent/graphs/contributors'; - export const AGENT_CONTRIBUTORS_GITHUB_API_URL = 'https://api.github.com/repos/UltimateHackingKeyboard/agent/contributors'; - export const MAX_ALLOWED_MACROS = 255; - export const MAX_ALLOWED_MACROS_TOOLTIP = `No more than ${MAX_ALLOWED_MACROS} macros are supported.`; -} +export const AGENT_GITHUB_URL = 'https://github.com/UltimateHackingKeyboard/agent'; +export const AGENT_CONTRIBUTORS_GITHUB_PAGE_URL = 'https://github.com/UltimateHackingKeyboard/agent/graphs/contributors'; +export const AGENT_CONTRIBUTORS_GITHUB_API_URL = 'https://api.github.com/repos/UltimateHackingKeyboard/agent/contributors'; +export const MAX_ALLOWED_MACROS = 255; +export const MAX_ALLOWED_MACROS_TOOLTIP = `No more than ${MAX_ALLOWED_MACROS} macros are supported.`; export const UHK_EEPROM_SIZE = 32768; export const ERR_UPDATER_INVALID_SIGNATURE = 'ERR_UPDATER_INVALID_SIGNATURE' diff --git a/packages/uhk-web/src/app/components/agent/about/about.component.ts b/packages/uhk-web/src/app/components/agent/about/about.component.ts index 55adda59829..30a1d9174cf 100644 --- a/packages/uhk-web/src/app/components/agent/about/about.component.ts +++ b/packages/uhk-web/src/app/components/agent/about/about.component.ts @@ -3,7 +3,7 @@ import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { faSpinner } from '@fortawesome/free-solid-svg-icons'; -import { Constants, VERSIONS } from 'uhk-common'; +import { AGENT_CONTRIBUTORS_GITHUB_PAGE_URL, AGENT_GITHUB_URL, VERSIONS } from 'uhk-common'; import { AppState, contributors } from '../../../store'; import { State } from '../../../store/reducers/contributors.reducer'; @@ -21,8 +21,8 @@ import { GetAgentContributorsAction } from '../../../store/actions/contributors. }) export class AboutComponent implements OnInit { version: string = VERSIONS.version; - agentGithubUrl: string = Constants.AGENT_GITHUB_URL; - agentContributorsUrl: string = Constants.AGENT_CONTRIBUTORS_GITHUB_PAGE_URL; + agentGithubUrl: string = AGENT_GITHUB_URL; + agentContributorsUrl: string = AGENT_CONTRIBUTORS_GITHUB_PAGE_URL; logoClickCounter = 0; state$: Observable; faSpinner = faSpinner; diff --git a/packages/uhk-web/src/app/components/macro/header/macro-header.component.ts b/packages/uhk-web/src/app/components/macro/header/macro-header.component.ts index 8cccd599c05..d200421df63 100644 --- a/packages/uhk-web/src/app/components/macro/header/macro-header.component.ts +++ b/packages/uhk-web/src/app/components/macro/header/macro-header.component.ts @@ -8,7 +8,7 @@ import { } from '@angular/core'; import { Store } from '@ngrx/store'; import { faCopy, faPlay, faTrash } from '@fortawesome/free-solid-svg-icons'; -import { Constants, Macro } from 'uhk-common'; +import { Macro, MAX_ALLOWED_MACROS_TOOLTIP } from 'uhk-common'; import { DuplicateMacroAction, EditMacroNameAction, RemoveMacroAction } from '../../../store/actions/macro'; import { AppState } from '../../../store'; @@ -32,7 +32,7 @@ export class MacroHeaderComponent implements OnChanges { faCopy = faCopy; faPlay = faPlay; faTrash = faTrash; - maxAllowedMacrosTooltip = Constants.MAX_ALLOWED_MACROS_TOOLTIP; + maxAllowedMacrosTooltip = MAX_ALLOWED_MACROS_TOOLTIP; constructor(private store: Store) { } diff --git a/packages/uhk-web/src/app/components/side-menu/side-menu.component.ts b/packages/uhk-web/src/app/components/side-menu/side-menu.component.ts index 01704f88f2c..73a732cd3df 100644 --- a/packages/uhk-web/src/app/components/side-menu/side-menu.component.ts +++ b/packages/uhk-web/src/app/components/side-menu/side-menu.component.ts @@ -28,7 +28,7 @@ import { import { Store } from '@ngrx/store'; import { Subscription } from 'rxjs'; -import { Constants, UHK_80_DEVICE } from 'uhk-common'; +import { MAX_ALLOWED_MACROS_TOOLTIP, UHK_80_DEVICE } from 'uhk-common'; import { AppState, getSideMenuPageState } from '../../store'; import { AddMacroAction } from '../../store/actions/macro'; @@ -109,7 +109,7 @@ export class SideMenuComponent implements OnChanges, OnInit, OnDestroy { faPuzzlePiece = faPuzzlePiece; faSlidersH = faSlidersH; faStar = faStar; - maxAllowedMacrosTooltip = Constants.MAX_ALLOWED_MACROS_TOOLTIP; + maxAllowedMacrosTooltip = MAX_ALLOWED_MACROS_TOOLTIP; private stateSubscription: Subscription; diff --git a/packages/uhk-web/src/app/store/effects/contributors.effect.ts b/packages/uhk-web/src/app/store/effects/contributors.effect.ts index d5941f481f2..52dab04e175 100644 --- a/packages/uhk-web/src/app/store/effects/contributors.effect.ts +++ b/packages/uhk-web/src/app/store/effects/contributors.effect.ts @@ -6,7 +6,7 @@ import { Action, Store } from '@ngrx/store'; import { from, Observable, of } from 'rxjs'; import { map, switchMap, catchError, reduce, mergeMap, withLatestFrom } from 'rxjs/operators'; -import { Constants } from 'uhk-common'; +import { AGENT_CONTRIBUTORS_GITHUB_API_URL } from 'uhk-common'; import { AppState, contributors } from '../index'; import { UHKContributor } from '../../models/uhk-contributor'; @@ -36,7 +36,7 @@ export class ContributorsEffect { fetchContributors$: Observable = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.FetchAgentContributors), - mergeMap(() => this.http.get(Constants.AGENT_CONTRIBUTORS_GITHUB_API_URL)), + mergeMap(() => this.http.get(AGENT_CONTRIBUTORS_GITHUB_API_URL)), switchMap((response: UHKContributor[]) => { return from(response).pipe( mergeMap( diff --git a/packages/uhk-web/src/app/store/index.ts b/packages/uhk-web/src/app/store/index.ts index 979c0057c61..4182404524a 100644 --- a/packages/uhk-web/src/app/store/index.ts +++ b/packages/uhk-web/src/app/store/index.ts @@ -7,8 +7,7 @@ import { AppTheme, AppThemeSelect, BacklightingMode, - Constants, - createMd5Hash, + createMd5Hash, FirmwareRepoInfo, getEmptyKeymap, HardwareConfiguration, @@ -21,6 +20,7 @@ import { LEFT_HALF_MODULE, LEFT_KEY_CLUSTER_MODULE, LeftSlotModules, + MAX_ALLOWED_MACROS, PlayMacroAction, RIGHT_TRACKPOINT_MODULE, RightSlotModules, @@ -594,7 +594,7 @@ export const getSideMenuPageState = createSelector( layer: selectedLayerOption.id }, macros, - maxMacroCountReached: macros.length >= Constants.MAX_ALLOWED_MACROS, + maxMacroCountReached: macros.length >= MAX_ALLOWED_MACROS, restoreUserConfiguration, deviceUiState: runningInElectronValue ? uiState : DeviceUiStates.UserConfigLoaded, selectedKeymap: routerState?.state?.url?.startsWith('/keymap') ? selectedKeymap : undefined, 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 434ecae27df..0678ecdc8c8 100644 --- a/packages/uhk-web/src/app/store/reducers/user-configuration.ts +++ b/packages/uhk-web/src/app/store/reducers/user-configuration.ts @@ -7,7 +7,6 @@ import { BUILTIN_ADVANCED_SECONDARY_ROLE_CONFIGURATION_PRESETS, BacklightingMode, ConnectionsAction, - Constants, CUSTOM_ADVANCED_SECONDARY_ROLE_CONFIGURATION_PRESET_NAME, CUSTOM_ADVANCED_SECONDARY_ROLE_TOOLTIP, emptyHostConnection, @@ -26,6 +25,7 @@ import { LeftSlotModules, Macro, MacroActionHelper, + MAX_ALLOWED_MACROS, MODIFIER_LAYER_NAMES, Module, ModuleConfiguration, @@ -1436,10 +1436,10 @@ function generateMacroId(macros: Macro[]) { newId += 1; - if (newId <= Constants.MAX_ALLOWED_MACROS) + if (newId <= MAX_ALLOWED_MACROS) return newId; - for (let i = 0; i <= Constants.MAX_ALLOWED_MACROS; i++) { + for (let i = 0; i <= MAX_ALLOWED_MACROS; i++) { if (!usedMacroIds.has(i)) { return i; }