Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions packages/uhk-agent/src/services/logger.service.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -598,7 +598,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo
return macro;
});
this.keymaps = buffer.readArray<Keymap>(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo));
ConfigSerializer.resolveSwitchKeymapActions(this.keymaps);
resolveSwitchKeymapActions(this.keymaps);

}

Expand Down Expand Up @@ -641,7 +641,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo
return macro;
});
this.keymaps = buffer.readArray<Keymap>(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo));
ConfigSerializer.resolveSwitchKeymapActions(this.keymaps);
resolveSwitchKeymapActions(this.keymaps);

}

Expand Down Expand Up @@ -698,7 +698,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo
return macro;
});
this.keymaps = buffer.readArray<Keymap>(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo));
ConfigSerializer.resolveSwitchKeymapActions(this.keymaps);
resolveSwitchKeymapActions(this.keymaps);

}

Expand Down Expand Up @@ -770,7 +770,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo
return macro;
});
this.keymaps = buffer.readArray<Keymap>(uhkBuffer => new Keymap().fromBinary(uhkBuffer, this.macros, serialisationInfo));
ConfigSerializer.resolveSwitchKeymapActions(this.keymaps);
resolveSwitchKeymapActions(this.keymaps);

}

Expand Down Expand Up @@ -867,7 +867,7 @@ export class UserConfiguration implements AdvancedSecondaryRoleConfiguration, Mo
this.lastSaveFirmwareTag = buffer.readString();
}

ConfigSerializer.resolveSwitchKeymapActions(this.keymaps);
resolveSwitchKeymapActions(this.keymaps);

}

Expand Down
20 changes: 0 additions & 20 deletions packages/uhk-common/src/config-serializer/config-serializer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/uhk-common/src/config-serializer/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
}
}
6 changes: 2 additions & 4 deletions packages/uhk-common/src/log/log-reg-exps.ts
Original file line number Diff line number Diff line change
@@ -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]:/;
12 changes: 5 additions & 7 deletions packages/uhk-common/src/util/constants.ts
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<State>;
faSpinner = faSpinner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<AppState>) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions packages/uhk-web/src/app/store/effects/contributors.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -36,7 +36,7 @@ export class ContributorsEffect {
fetchContributors$: Observable<Action> = createEffect(() => this.actions$
.pipe(
ofType<FetchAgentContributorsAction>(ActionTypes.FetchAgentContributors),
mergeMap(() => this.http.get<UHKContributor[]>(Constants.AGENT_CONTRIBUTORS_GITHUB_API_URL)),
mergeMap(() => this.http.get<UHKContributor[]>(AGENT_CONTRIBUTORS_GITHUB_API_URL)),
switchMap((response: UHKContributor[]) => {
return from(response).pipe(
mergeMap(
Expand Down
6 changes: 3 additions & 3 deletions packages/uhk-web/src/app/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
AppTheme,
AppThemeSelect,
BacklightingMode,
Constants,
createMd5Hash,
createMd5Hash,
FirmwareRepoInfo,
getEmptyKeymap,
HardwareConfiguration,
Expand All @@ -21,6 +20,7 @@ import {
LEFT_HALF_MODULE,
LEFT_KEY_CLUSTER_MODULE,
LeftSlotModules,
MAX_ALLOWED_MACROS,
PlayMacroAction,
RIGHT_TRACKPOINT_MODULE,
RightSlotModules,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/uhk-web/src/app/store/reducers/user-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,6 +25,7 @@ import {
LeftSlotModules,
Macro,
MacroActionHelper,
MAX_ALLOWED_MACROS,
MODIFIER_LAYER_NAMES,
Module,
ModuleConfiguration,
Expand Down Expand Up @@ -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;
}
Expand Down
Loading