diff --git a/packages/test-serializer/spec/test-serializer.spec.ts b/packages/test-serializer/spec/test-serializer.spec.ts index 9d72d9d49e0..0dd58204e1e 100644 --- a/packages/test-serializer/spec/test-serializer.spec.ts +++ b/packages/test-serializer/spec/test-serializer.spec.ts @@ -2,7 +2,7 @@ import { UhkBuffer, UserConfiguration } from '../../uhk-common/src/index.js'; import fs from 'fs'; -const userConfig = JSON.parse(fs.readFileSync('../uhk-web/src/app/services/user-config-80.json', { encoding: 'utf8' })); +const userConfig = JSON.parse(fs.readFileSync('../uhk-common/user-config-80.json', { encoding: 'utf8' })); describe('Test Serializer', () => { it('full config match', () => { diff --git a/packages/uhk-agent/src/electron-main.ts b/packages/uhk-agent/src/electron-main.ts index b7dcd62fc18..772faa70f3d 100644 --- a/packages/uhk-agent/src/electron-main.ts +++ b/packages/uhk-agent/src/electron-main.ts @@ -23,9 +23,18 @@ import { SudoService } from './services/sudo.service'; import { SmartMacroDocService } from './services/smart-macro-doc.service'; import isDev from 'electron-is-dev'; import { setMenu } from './electron-menu'; -import { printUsbDevices } from './util'; import { loadWindowState, saveWindowState } from './util/window'; -import { getWindowBackgroundColor, options, cliUsage, reenumerateAndExit } from './util'; +import { + getWindowBackgroundColor, + options, + cliUsage, + printStatusBuffer, + printUsbDevices, + printHardwareConfiguration, + reenumerateAndExit, + restoreUserConfiguration, + writeHardwareConfiguration, +} from './util'; if (options.help) { console.log(cliUsage); @@ -162,6 +171,10 @@ async function createWindow() { if (isSecondInstance) { app.quit(); +} else if (options['print-hardware-configuration']) { + printHardwareConfiguration({ logger, uhkOperations }) +} else if (options['print-status-buffer']) { + printStatusBuffer({ logger, uhkOperations }) } else if (options['print-usb-devices']) { printUsbDevices() .then(() => { @@ -187,6 +200,18 @@ if (isSecondInstance) { logger.misc('Reenumeration process finished with error. Please unplug and plug your UHK.'); process.exit(-1); }); +} else if (options['restore-user-configuration']) { + restoreUserConfiguration({ + logger, + uhkOperations, + commandLineArgs: options, + }) +} else if (options['write-hardware-configuration']) { + writeHardwareConfiguration({ + logger, + uhkOperations, + commandLineArgs: options, + }) } else { // This method will be called when Electron has finished diff --git a/packages/uhk-agent/src/util/command-line.ts b/packages/uhk-agent/src/util/command-line.ts index 57aa5bf0a6a..7338e54b613 100644 --- a/packages/uhk-agent/src/util/command-line.ts +++ b/packages/uhk-agent/src/util/command-line.ts @@ -13,7 +13,10 @@ const optionDefinitions: commandLineArgs.OptionDefinition[] = [ { name: 'pid', type: Number }, { name: 'no-report-id', type: Boolean }, { name: 'preserve-udev-rules', type: Boolean }, + { name: 'print-hardware-configuration', type: Boolean }, + { name: 'print-status-buffer', type: Boolean }, { name: 'print-usb-devices', type: Boolean }, + { name: 'restore-user-configuration', type: Boolean }, { name: 'reenumerate-and-exit', type: String }, { name: 'report-id', type: Number }, { name: 'serial-number', type: String }, @@ -21,6 +24,7 @@ const optionDefinitions: commandLineArgs.OptionDefinition[] = [ { name: 'usb-interface', type: Number }, { name: 'usb-non-blocking', type: Boolean }, { name: 'vid', type: Number }, + { name: 'write-hardware-configuration', type: String }, ]; export const options: CommandLineArgs = commandLineArgs(optionDefinitions, { partial: true }) as CommandLineArgs; @@ -74,6 +78,16 @@ const sections: commandLineUsage.Section[] = [ description: 'Don\'t force udev rule update', type: Boolean }, + { + name: 'print-hardware-configuration', + description: 'Print hardware configuration to the standard output and exit.', + type: Boolean + }, + { + name: 'print-status-buffer', + description: 'Print the status buffer of the keyboard to the standard output and exit.', + type: Boolean + }, { name: 'print-usb-devices', description: 'Print usb devices to the standard output and exit.', @@ -86,6 +100,11 @@ const sections: commandLineUsage.Section[] = [ 'Please provide the timeout in milliseconds.', typeLabel: '(bootloader|buspal),timeout' }, + { + name: 'restore-user-configuration', + description: 'Run restore user-configuration process and exit.', + type: Boolean, + }, { name: 'report-id', description: 'Report Id that used for USB communication. If the value is -1 then does not use report id. The default value depends from the UHK device. For UHK 60 is 0. For UHK 80 is 4', @@ -114,7 +133,12 @@ const sections: commandLineUsage.Section[] = [ name: 'vid', description: 'Use the specified USB vendor id. If you set it you have to set the pid too.', type: Number - } + }, + { + name: 'write-hardware-configuration', + description: 'Overwrite/reset the current hardware configuration and exit.', + typeLabel: 'ansi | iso' + }, ] } ]; diff --git a/packages/uhk-agent/src/util/index.ts b/packages/uhk-agent/src/util/index.ts index 143ad55eeca..63ed643287f 100644 --- a/packages/uhk-agent/src/util/index.ts +++ b/packages/uhk-agent/src/util/index.ts @@ -13,7 +13,11 @@ export * from './get-window-background-color'; export * from './load-user-config-from-binary-file'; export * from './load-user-config-history-async'; export * from './make-folder-writeable-to-user-on-linux'; +export * from './print-hardware-configuration'; +export * from './print-status-buffer'; export * from './print-usb-devices'; export * from './reenumerate-and-exit'; +export * from './restore-user-configuration'; export * from './save-extract-firmware'; export * from './save-user-config-history-async'; +export * from './write-hardware-configuration'; diff --git a/packages/uhk-agent/src/util/print-hardware-configuration.ts b/packages/uhk-agent/src/util/print-hardware-configuration.ts new file mode 100644 index 00000000000..c48e367ab11 --- /dev/null +++ b/packages/uhk-agent/src/util/print-hardware-configuration.ts @@ -0,0 +1,21 @@ +import process from 'node:process'; +import { UhkOperations } from 'uhk-usb'; + +import { ElectronLogService } from '../services/logger.service'; + +export interface PrintHardwareConfigurationOptions { + logger: ElectronLogService; + uhkOperations: UhkOperations; +} + +export async function printHardwareConfiguration({logger, uhkOperations}: PrintHardwareConfigurationOptions): Promise { + try { + const hardwareConfiguration = await uhkOperations.getHardwareConfiguration() + logger.misc(hardwareConfiguration.toJsonObject()); + process.exit(0); + } + catch (error) { + logger.error(error.message); + process.exit(-1); + } +} diff --git a/packages/uhk-agent/src/util/print-status-buffer.ts b/packages/uhk-agent/src/util/print-status-buffer.ts new file mode 100644 index 00000000000..7e0e75e0078 --- /dev/null +++ b/packages/uhk-agent/src/util/print-status-buffer.ts @@ -0,0 +1,21 @@ +import process from 'node:process'; +import { UhkOperations, UsbVariables } from 'uhk-usb'; + +import { ElectronLogService } from '../services/logger.service'; + +export interface PrintStatusBufferOptions { + logger: ElectronLogService; + uhkOperations: UhkOperations; +} + +export async function printStatusBuffer({logger, uhkOperations}: PrintStatusBufferOptions): Promise { + try { + const message = await uhkOperations.getVariable(UsbVariables.statusBuffer); + logger.misc(`Status buffer: ${message}`); + process.exit(0); + } + catch (error) { + logger.error(error.message); + process.exit(-1); + } +} diff --git a/packages/uhk-agent/src/util/restore-user-configuration.ts b/packages/uhk-agent/src/util/restore-user-configuration.ts new file mode 100644 index 00000000000..dd9be4a24fc --- /dev/null +++ b/packages/uhk-agent/src/util/restore-user-configuration.ts @@ -0,0 +1,53 @@ +import process from 'node:process'; +import { + CommandLineArgs, + mapObjectToUserConfigBinaryBuffer, + UHK_60_DEVICE, + UHK_60_V2_DEVICE, + UHK_60_USER_CONFIG, + UHK_80_DEVICE, + UHK_80_USER_CONFIG, +} from 'uhk-common'; +import { getCurrentUhkDeviceProduct, UhkOperations } from 'uhk-usb'; + +import { ElectronLogService } from '../services/logger.service'; + +export interface RestoreUserConfigurationOptions { + logger: ElectronLogService; + uhkOperations: UhkOperations; + commandLineArgs: CommandLineArgs; +} + +export async function restoreUserConfiguration(options: RestoreUserConfigurationOptions): Promise { + try { + const device = await getCurrentUhkDeviceProduct(options.commandLineArgs); + let userConfigJson: any; + + if (!device) { + options.logger.error('Cannot detect UHK device'); + process.exit(-1); + } + else if (device.id === UHK_60_DEVICE.id || device.id === UHK_60_V2_DEVICE.id) { + userConfigJson = UHK_60_USER_CONFIG; + } + else if (device.id === UHK_80_DEVICE.id) { + userConfigJson = UHK_80_USER_CONFIG; + } + else { + options.logger.error(`Unknow UHK device: ${JSON.stringify(device)}`); + process.exit(-1); + } + + const buffer = mapObjectToUserConfigBinaryBuffer(userConfigJson); + + options.logger.misc('Start restoring user configuration...'); + await options.uhkOperations.saveUserConfiguration(buffer) + options.logger.misc('User configuration restored.'); + + process.exit(0); + } + catch (error) { + options.logger.error(error.message); + process.exit(-1); + } +} diff --git a/packages/uhk-agent/src/util/write-hardware-configuration.ts b/packages/uhk-agent/src/util/write-hardware-configuration.ts new file mode 100644 index 00000000000..e1b411eaad3 --- /dev/null +++ b/packages/uhk-agent/src/util/write-hardware-configuration.ts @@ -0,0 +1,37 @@ +import process from 'node:process'; +import { CommandLineArgs } from 'uhk-common'; +import { + getCurrentUhkDeviceProduct, + UhkOperations, +} from 'uhk-usb'; + +import { ElectronLogService } from '../services/logger.service'; + +export interface WriteHardwareConfigurationOptions { + commandLineArgs: CommandLineArgs; + logger: ElectronLogService; + uhkOperations: UhkOperations; +} + +export async function writeHardwareConfiguration(options: WriteHardwareConfigurationOptions):Promise { + const layout = options.commandLineArgs['write-hardware-configuration']; + options.logger.misc(`[writeHardwareConfiguration] Command line argument: ${layout}`); + + if (!['ansi', 'iso'].includes(layout)) { + options.logger.misc('Invalid layout. Layout should be either iso or ansi'); + process.exit(-1); + } + + try { + const device = await getCurrentUhkDeviceProduct(options.commandLineArgs); + + await options.uhkOperations.saveHardwareConfiguration(layout === 'iso', device.id) + + options.logger.misc(`[writeHardwareConfiguration] finished successfully.`); + process.exit(0); + } catch (error) { + options.logger.error(error.message); + process.exit(-1); + } + +} diff --git a/packages/uhk-common/.gitignore b/packages/uhk-common/.gitignore index a8f914da7f1..bc5704ed996 100644 --- a/packages/uhk-common/.gitignore +++ b/packages/uhk-common/.gitignore @@ -1,3 +1,6 @@ .nyc_output/ coverage/ +user-config.json +src/user-config-60.ts +src/user-config-80.ts src/util/versions.ts diff --git a/packages/uhk-common/package.json b/packages/uhk-common/package.json index 68d03cdc057..fbbce3e3b48 100644 --- a/packages/uhk-common/package.json +++ b/packages/uhk-common/package.json @@ -12,10 +12,11 @@ "url": "git@github.com:UltimateHackingKeyboard/agent.git" }, "scripts": { - "build": "run-s -sn build:generate-versions build:tsc", + "build": "run-s -sn build:generate-versions build:user-config build:tsc", "build:generate-versions": "node ./scripts/generate-versions.mjs", "build:tsc": "tsc --project src/tsconfig.build.json", - "clean": "rimraf ./node_modules ./dist", + "build:user-config": "tsx ./scripts/generate-user-configs.ts", + "clean": "rimraf ./node_modules ./dist user-config.json", "test": "cross-env NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json", "coverage": "nyc npm test", "lint": "eslint" diff --git a/packages/uhk-web/scripts/generate-user-configs.mjs b/packages/uhk-common/scripts/generate-user-configs.ts similarity index 59% rename from packages/uhk-web/scripts/generate-user-configs.mjs rename to packages/uhk-common/scripts/generate-user-configs.ts index 2cb5ae3f455..cb2b33f5db5 100644 --- a/packages/uhk-web/scripts/generate-user-configs.mjs +++ b/packages/uhk-common/scripts/generate-user-configs.ts @@ -5,11 +5,14 @@ import { UHK_60_LEFT_MAX_KEY_ACTION_COUNT, UHK_60_RIGHT_MAX_KEY_ACTION_COUNT, UserConfiguration, -} from "uhk-common"; +} from '../src/config-serializer'; -const uhk80UserConfigPath = path.join(import.meta.dirname, '../src/app/services/user-config-80.json'); +const uhk80UserConfigPath = path.join(import.meta.dirname, '../user-config-80.json'); const uhk80UserConfigJson = JSON.parse(await fs.readFile(uhk80UserConfigPath, { encoding: 'utf8' })); const uhk60UserConfig = new UserConfiguration().fromJsonObject(uhk80UserConfigJson); +const uhk80UserConfigTsPath = path.join(import.meta.dirname, '../src/user-config-80.ts'); +const uhk80UserConfigContent = `export const UHK_80_USER_CONFIG = ${JSON.stringify(uhk80UserConfigJson, null, 2)}` +await fs.writeFile(uhk80UserConfigTsPath, uhk80UserConfigContent, { encoding: 'utf8' }); for (const keymap of uhk60UserConfig.keymaps) { const layers = []; @@ -35,5 +38,9 @@ for (const keymap of uhk60UserConfig.keymaps) { keymap.layers = layers; } -const uhk60UserConfigPath = path.join(import.meta.dirname, '../src/app/services/user-config.json'); +const uhk60UserConfigPath = path.join(import.meta.dirname, '../user-config.json'); await fs.writeFile(uhk60UserConfigPath, JSON.stringify(uhk60UserConfig.toJsonObject(), null, 2), { encoding: 'utf8' }); + +const uhk60UserConfigTsPath = path.join(import.meta.dirname, '../src/user-config-60.ts'); +const uhk60UserConfigContent = `export const UHK_60_USER_CONFIG = ${JSON.stringify(uhk60UserConfig.toJsonObject(), null, 2)}` +await fs.writeFile(uhk60UserConfigTsPath, uhk60UserConfigContent, { encoding: 'utf8' }); diff --git a/packages/uhk-web/scripts/migrate-uhk80-user-config.mjs b/packages/uhk-common/scripts/migrate-uhk80-user-config.mjs similarity index 99% rename from packages/uhk-web/scripts/migrate-uhk80-user-config.mjs rename to packages/uhk-common/scripts/migrate-uhk80-user-config.mjs index 0e287bbd48c..e0e1ea36cec 100644 --- a/packages/uhk-web/scripts/migrate-uhk80-user-config.mjs +++ b/packages/uhk-common/scripts/migrate-uhk80-user-config.mjs @@ -4,7 +4,7 @@ import { KeyActionHelper, Module, UserConfiguration, -} from "uhk-common"; +} from '../dist/index.js'; const sourceFile = process.argv[2] const destinationFile = process.argv[3] diff --git a/packages/uhk-common/src/config-serializer/README.md b/packages/uhk-common/src/config-serializer/README.md index ac25f1a1fe1..389d8069915 100644 --- a/packages/uhk-common/src/config-serializer/README.md +++ b/packages/uhk-common/src/config-serializer/README.md @@ -12,7 +12,7 @@ Given that the development dependencies are installed on your system you should There are 3 different representations of the configuration, each filling a specific purpose. -The **JavaScript representation** is optimally suited to be serialized as JSON, and saved to the file system, or transmitted over the network. As a plaintext format, it's human-readable and easily editable. See [user-config.json](../../../uhk-web/src/app/services/user-config-80.json) for an example configuration. +The **JavaScript representation** is optimally suited to be serialized as JSON, and saved to the file system, or transmitted over the network. As a plaintext format, it's human-readable and easily editable. See [user-config.json](../../user-config-80.json) for an example configuration. The **TypeScript representation** is structurally similar to the JavaScript representation, but it features strongly typed TypeScript objects instead of typeless JavaScript objects. This representation is meant to be used by Agent. Extensive, per-property [assertion](assert.ts) takes place upon initializing the TypeScript objects to ensure the integrity of the configuration. @@ -75,7 +75,7 @@ KeyActions.toJsObject: ## Testing the serializer -[test-serializer.ts](test-serializer.ts) is designed to test the serializer by taking [user-config.json](../../../uhk-web/src/app/services/user-config.-80json), and transforming it to TypeScript representation, then to binary representation, then finally back to JavaScript representation. This should exercise every major code path. +[test-serializer.ts](test-serializer.ts) is designed to test the serializer by taking [user-config.json](../../user-config-80.json), and transforming it to TypeScript representation, then to binary representation, then finally back to JavaScript representation. This should exercise every major code path. If the testing is successful the following should be displayed: diff --git a/packages/uhk-common/src/index.ts b/packages/uhk-common/src/index.ts index 663ba60129a..d42af083aeb 100644 --- a/packages/uhk-common/src/index.ts +++ b/packages/uhk-common/src/index.ts @@ -2,5 +2,7 @@ export { Buffer } from './buffer.js'; export * from './config-serializer/index.js'; export * from './log/index.js'; export * from './models/index.js'; +export { UHK_60_USER_CONFIG } from './user-config-60.js'; +export { UHK_80_USER_CONFIG } from './user-config-80.js'; export * from './util/index.js'; export const RIGHT_HALF_FIRMWARE_UPGRADE_MODULE_NAME = 'Right keyboard half'; diff --git a/packages/uhk-common/src/models/command-line-args.ts b/packages/uhk-common/src/models/command-line-args.ts index 87030ccf076..ae84476ee47 100644 --- a/packages/uhk-common/src/models/command-line-args.ts +++ b/packages/uhk-common/src/models/command-line-args.ts @@ -57,15 +57,23 @@ export interface CommandLineArgs extends DeviceIdentifier { * Agent not force the udev rule update */ 'preserve-udev-rules'?: boolean; - /** - * Agent not force the udev rule update - */ + + 'print-hardware-configuration'?: boolean; + + 'print-status-buffer'?: boolean; + 'print-usb-devices'?: boolean; /** * Reenumerate as the bootloader or BusPal, wait for the specified timeout and exit. * This may make Windows install the USB drivers needed for firmware update. */ 'reenumerate-and-exit'?: string; + + /** + * Run restore user-configuration process and exit. + */ + 'restore-user-configuration'?: boolean; + /** * Report Id that used for USB communication */ @@ -78,4 +86,10 @@ export interface CommandLineArgs extends DeviceIdentifier { * Use USB non-blocking communication */ 'usb-non-blocking'?: boolean; + + /** + * Overwrite/reset the current hardware configuration and exit. + * The argument is the keyboard layout {ansi|iso} + */ + 'write-hardware-configuration'?: string; } diff --git a/packages/uhk-web/src/app/services/user-config-80.json b/packages/uhk-common/user-config-80.json similarity index 100% rename from packages/uhk-web/src/app/services/user-config-80.json rename to packages/uhk-common/user-config-80.json diff --git a/packages/uhk-usb/src/uhk-operations.ts b/packages/uhk-usb/src/uhk-operations.ts index f036a699a63..f02d7798fd7 100644 --- a/packages/uhk-usb/src/uhk-operations.ts +++ b/packages/uhk-usb/src/uhk-operations.ts @@ -647,6 +647,14 @@ export class UhkOperations { }; } + public async getHardwareConfiguration(): Promise { + const buffer = await this.loadConfiguration(ConfigBufferId.hardwareConfig); + const hardwareConfiguration = new HardwareConfiguration(); + hardwareConfiguration.fromBinary(UhkBuffer.fromArray([...buffer])); + + return hardwareConfiguration; + } + public async getUptime(): Promise { this.logService.usbOps('[DeviceOperation] USB[T]: get uptime'); const buffer = Buffer.from([UsbCommand.GetProperty, DevicePropertyIds.Uptime]); diff --git a/packages/uhk-web/.gitignore b/packages/uhk-web/.gitignore index d7944acc807..98a47fa1885 100644 --- a/packages/uhk-web/.gitignore +++ b/packages/uhk-web/.gitignore @@ -1,2 +1 @@ .angular -src/app/services/user-config.json diff --git a/packages/uhk-web/package.json b/packages/uhk-web/package.json index f505f191ce0..367652cced5 100644 --- a/packages/uhk-web/package.json +++ b/packages/uhk-web/package.json @@ -5,8 +5,7 @@ "clean": "rimraf ./node_modules ./.angular", "ng": "ng", "start": "ng serve", - "build": "run-s -sn build:user-config build:renderer", - "build:user-config": "node ./scripts/generate-user-configs.mjs", + "build": "run-s -sn build:renderer", "build:web": "ng build --configuration=production --project=uhk-web", "build:renderer": "ng build --configuration=production --project=uhk-renderer", "server:renderer": "ng build --project=uhk-renderer --watch", diff --git a/packages/uhk-web/src/app/components/device/device.routes.ts b/packages/uhk-web/src/app/components/device/device.routes.ts index c2afa69ab5f..0668ce3db13 100644 --- a/packages/uhk-web/src/app/components/device/device.routes.ts +++ b/packages/uhk-web/src/app/components/device/device.routes.ts @@ -6,7 +6,7 @@ import { DeviceConfigurationComponent } from './configuration/device-configurati import { DeviceFirmwareComponent } from './firmware/device-firmware.component'; import { MouseSpeedComponent } from './mouse-speed/mouse-speed.component'; import { LEDSettingsComponent } from './led-settings/led-settings.component'; -import { RestoreConfigurationComponent } from './restore-configuration/restore-configuration.component'; +import { RestoreUserConfigurationComponent } from './restore-user-configuration/restore-user-configuration.component'; import { HostConnectionsComponent } from './host-connections/host-connections.component'; import { TypingBehaviorPage } from './typing-behavior-page/typing-behavior-page.component'; @@ -45,7 +45,7 @@ export const deviceRoutes: Routes = [ }, { path: 'restore-user-configuration', - component: RestoreConfigurationComponent + component: RestoreUserConfigurationComponent }, { path: 'host-connections', diff --git a/packages/uhk-web/src/app/components/device/index.ts b/packages/uhk-web/src/app/components/device/index.ts index 509c1c1fa85..cc1081723f4 100644 --- a/packages/uhk-web/src/app/components/device/index.ts +++ b/packages/uhk-web/src/app/components/device/index.ts @@ -5,7 +5,7 @@ export * from './firmware/device-firmware.component'; export * from './mouse-speed/mouse-speed.component'; export * from './led-settings/functional-backlight-color.component'; export * from './led-settings/led-settings.component'; -export * from './restore-configuration/restore-configuration.component'; +export * from './restore-user-configuration/restore-user-configuration.component'; export * from './recovery-mode/recovery-mode.component'; export * from './host-connections/host-connections.component'; export * from './typing-behavior-page/typing-behavior-page.component'; diff --git a/packages/uhk-web/src/app/components/device/restore-configuration/restore-configuration.component.html b/packages/uhk-web/src/app/components/device/restore-user-configuration/restore-user-configuration.component.html similarity index 100% rename from packages/uhk-web/src/app/components/device/restore-configuration/restore-configuration.component.html rename to packages/uhk-web/src/app/components/device/restore-user-configuration/restore-user-configuration.component.html diff --git a/packages/uhk-web/src/app/components/device/restore-configuration/restore-configuration.component.scss b/packages/uhk-web/src/app/components/device/restore-user-configuration/restore-user-configuration.component.scss similarity index 100% rename from packages/uhk-web/src/app/components/device/restore-configuration/restore-configuration.component.scss rename to packages/uhk-web/src/app/components/device/restore-user-configuration/restore-user-configuration.component.scss diff --git a/packages/uhk-web/src/app/components/device/restore-configuration/restore-configuration.component.ts b/packages/uhk-web/src/app/components/device/restore-user-configuration/restore-user-configuration.component.ts similarity index 86% rename from packages/uhk-web/src/app/components/device/restore-configuration/restore-configuration.component.ts rename to packages/uhk-web/src/app/components/device/restore-user-configuration/restore-user-configuration.component.ts index d3384a8ae4d..f921cca6da6 100644 --- a/packages/uhk-web/src/app/components/device/restore-configuration/restore-configuration.component.ts +++ b/packages/uhk-web/src/app/components/device/restore-user-configuration/restore-user-configuration.component.ts @@ -9,15 +9,15 @@ import { ResetUserConfigurationAction, RestoreUserConfigurationFromBackupAction import { RestoreConfigurationState } from '../../../models/restore-configuration-state'; @Component({ - selector: 'restore-configuration', - templateUrl: './restore-configuration.component.html', - styleUrls: ['./restore-configuration.component.scss'], + selector: 'restore-user-configuration', + templateUrl: './restore-user-configuration.component.html', + styleUrls: ['./restore-user-configuration.component.scss'], standalone: false, host: { 'class': 'container-fluid' } }) -export class RestoreConfigurationComponent implements OnInit, OnDestroy { +export class RestoreUserConfigurationComponent implements OnInit, OnDestroy { backupUserConfigurationInfo = BackupUserConfigurationInfo; state: RestoreConfigurationState; faExclamationCircle = faExclamationCircle; diff --git a/packages/uhk-web/src/app/services/default-user-configuration.service.ts b/packages/uhk-web/src/app/services/default-user-configuration.service.ts index 0ae4ed9406f..1a1260381ec 100644 --- a/packages/uhk-web/src/app/services/default-user-configuration.service.ts +++ b/packages/uhk-web/src/app/services/default-user-configuration.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { UhkDeviceProduct, UserConfiguration, UHK_80_DEVICE } from 'uhk-common'; +import { UhkDeviceProduct, UserConfiguration, UHK_80_DEVICE, UHK_60_USER_CONFIG, UHK_80_USER_CONFIG } from 'uhk-common'; @Injectable() export class DefaultUserConfigurationService { @@ -9,8 +9,7 @@ export class DefaultUserConfigurationService { getDefault60(): UserConfiguration { if (!this._defaultConfig60) { this._defaultConfig60 = new UserConfiguration() - // eslint-disable-next-line @typescript-eslint/no-require-imports - .fromJsonObject(require('./user-config.json')); + .fromJsonObject(UHK_60_USER_CONFIG); } return this._defaultConfig60; @@ -19,8 +18,7 @@ export class DefaultUserConfigurationService { getDefault80(): UserConfiguration { if (!this._defaultConfig80) { this._defaultConfig80 = new UserConfiguration() - // eslint-disable-next-line @typescript-eslint/no-require-imports - .fromJsonObject(require('./user-config-80.json')); + .fromJsonObject(UHK_80_USER_CONFIG); } return this._defaultConfig80; diff --git a/packages/uhk-web/src/app/shared.module.ts b/packages/uhk-web/src/app/shared.module.ts index cdaca82312a..b33893d1009 100644 --- a/packages/uhk-web/src/app/shared.module.ts +++ b/packages/uhk-web/src/app/shared.module.ts @@ -33,7 +33,7 @@ import { FunctionalBacklightColorComponent, MouseSpeedComponent, LEDSettingsComponent, - RestoreConfigurationComponent, + RestoreUserConfigurationComponent, RecoveryModeComponent, TypingBehaviorPage } from './components/device'; @@ -274,7 +274,7 @@ import appInitFactory from './services/app-init-factory'; EditableTextComponent, Autofocus, NgSelectMaxHeight, - RestoreConfigurationComponent, + RestoreUserConfigurationComponent, RecoveryModeComponent, FileUploadComponent, AutoGrowInputComponent, diff --git a/packages/usb/user-config-json-to-bin.ts b/packages/usb/user-config-json-to-bin.ts index 1b6bfe88126..4267bfa3c8c 100755 --- a/packages/usb/user-config-json-to-bin.ts +++ b/packages/usb/user-config-json-to-bin.ts @@ -23,7 +23,7 @@ if (userConfigType !== 'uhk60' && userConfigType !== 'uhk80') { } const inputFileName = userConfigType === 'uhk60' ? 'user-config.json' : 'user-config-80.json'; -const inputFile = join(import.meta.url, '..', 'uhk-web', 'src', 'app', 'services', inputFileName); +const inputFile = join(import.meta.url, '..', 'uhk-common', inputFileName); const config1Js = JSON.parse(fs.readFileSync(inputFile).toString()); const config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(config1Js); const config1Buffer = new UhkBuffer();