diff --git a/package.json b/package.json index f3cc11738a2..4ffe706fbc2 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "version": "8.0.1", "firmwareVersion": "15.3.0", "deviceProtocolVersion": "4.15.0", - "userConfigVersion": "12.1.0", + "userConfigVersion": "13.0.0", "hardwareConfigVersion": "1.0.0", "description": "Agent is the configuration application of the Ultimate Hacking Keyboard.", "repository": { diff --git a/packages/uhk-common/scripts/generate-versions.mjs b/packages/uhk-common/scripts/generate-versions.mjs index e834ceafbb7..58334d98628 100644 --- a/packages/uhk-common/scripts/generate-versions.mjs +++ b/packages/uhk-common/scripts/generate-versions.mjs @@ -1,6 +1,9 @@ +import { exec } from 'node:child_process'; import fs from 'node:fs/promises'; import path from 'node:path'; +import process from 'node:process'; +import getGithubTag from '../../../scripts/get-github-tag.mjs'; const rootPackageJsonPath = path.join(import.meta.dirname, '../../../package.json'); const packageJsonContent = await fs.readFile(rootPackageJsonPath, { encoding: 'utf8' }); const packageJson = JSON.parse(packageJsonContent) @@ -9,6 +12,8 @@ const versionsFileContent = `\ import { VersionInformation } from '../models/version-information.js'; export const VERSIONS: VersionInformation = { + agentRepo: ${writeValue(getGitRepo())}, + agentTag: ${writeValue(await getGitTag())}, version: ${writeValue(packageJson.version)}, firmwareVersion: ${writeValue(packageJson.firmwareVersion)}, deviceProtocolVersion: ${writeValue(packageJson.deviceProtocolVersion)}, @@ -17,6 +22,11 @@ export const VERSIONS: VersionInformation = { } ` +if (process.env.CI) { + console.log('versions.ts file content:') + console.log(versionsFileContent); +} + const versionsFilePath = path.join(import.meta.dirname, '../src/util/versions.ts') await fs.writeFile(versionsFilePath, versionsFileContent, { encoding: 'utf8' }); @@ -31,3 +41,50 @@ function writeValue(value) { return `'${value}'`; } + +function getGitRepo() { + if (process.env.CI) { + return process.env.GITHUB_REPOSITORY; + } + + return 'UltimateHackingKeyboard/agent' +} + +async function getGitTag() { + if (process.env.CI) { + const tag = getGithubTag(); + if (tag) { + return tag; + } + } + + try { + const tagResponse = await execAsync('git describe --exact-match --tags') + + if (tagResponse.stdout) { + return tagResponse.stdout.trim() + } + } catch (error) { + console.log('No Agent git tag fallback to sha') + } + + // fallback to git sha + const shaResponse = await execAsync('git rev-parse --verify --short HEAD') + + return shaResponse.stdout.trim() +} + +async function execAsync(command) { + return new Promise((resolve, reject) => { + exec(command, (error, stdout, stderr) => { + if (error) { + return reject(error); + } + + resolve({ + stdout, + stderr, + }); + }) + }) +} 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 427b8edc0b2..46319368722 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 @@ -74,6 +74,7 @@ export class HostConnection { case 9: case 11: case 12: + case 13: return this.fromJsonObjectV9(jsonObject, serialisationInfo); default: @@ -89,6 +90,7 @@ export class HostConnection { case 9: case 11: case 12: + case 13: return this.fromJsonBinaryV9(buffer, serialisationInfo); default: diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts index b22c505c204..083c36ad27c 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts @@ -40,6 +40,7 @@ export class Helper { case 9: case 11: case 12: + case 13: return this.fromUhkBufferV1(buffer, macros, serialisationInfo); default: @@ -128,6 +129,7 @@ export class Helper { case 9: case 11: case 12: + case 13: return this.fromJSONObjectV1(keyAction, macros, serialisationInfo); default: 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 6b3dbafe13a..1fc7fe9d6d2 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 @@ -85,6 +85,7 @@ export class KeystrokeAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV6(jsonObject, serialisationInfo); break; @@ -111,6 +112,7 @@ export class KeystrokeAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromBinaryV6(buffer, serialisationInfo); break; 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 ea26e47480f..fe34292d770 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 @@ -64,6 +64,7 @@ export class MouseAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV6(jsonObject, serialisationInfo); break; @@ -90,6 +91,7 @@ export class MouseAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromBinaryV6(buffer, serialisationInfo); break; 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 5073b56de29..fdfc705cdb0 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 @@ -95,6 +95,7 @@ export class PlayMacroAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV6(jsonObject, macros, serialisationInfo); break; @@ -121,6 +122,7 @@ export class PlayMacroAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromBinaryV6(buffer, macros, serialisationInfo); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/switch-keymap-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/switch-keymap-action.ts index cca3f45a819..aa2d3622954 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/switch-keymap-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/switch-keymap-action.ts @@ -43,6 +43,7 @@ export class SwitchKeymapAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV6(jsonObject, serialisationInfo); break; @@ -119,6 +120,7 @@ export class UnresolvedSwitchKeymapAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromBinaryV6(buffer, serialisationInfo); break; 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 d7620425e39..accc5211c13 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 @@ -73,6 +73,7 @@ export class SwitchLayerAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV6(jsonObject, serialisationInfo); break; @@ -99,6 +100,7 @@ export class SwitchLayerAction extends KeyAction { case 9: case 11: case 12: + case 13: this.fromBinaryV6(buffer, serialisationInfo); break; 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 5ef32089db0..f3cbdb06777 100644 --- a/packages/uhk-common/src/config-serializer/config-items/keymap.ts +++ b/packages/uhk-common/src/config-serializer/config-items/keymap.ts @@ -42,6 +42,7 @@ export class Keymap { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject, macros, serialisationInfo); break; @@ -67,6 +68,7 @@ export class Keymap { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer, macros, serialisationInfo); break; 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 3c1b95cc3d0..ea18d841994 100644 --- a/packages/uhk-common/src/config-serializer/config-items/layer.ts +++ b/packages/uhk-common/src/config-serializer/config-items/layer.ts @@ -41,6 +41,7 @@ export class Layer { case 9: case 11: case 12: + case 13: this.fromJsonObjectV5(jsonObject, macros, serialisationInfo); break; @@ -67,6 +68,7 @@ export class Layer { case 9: case 11: case 12: + case 13: this.fromBinaryV5(buffer, macros, serialisationInfo); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/command-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/command-macro-action.ts index d191432a8f0..8221437fe3f 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/command-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/command-macro-action.ts @@ -27,6 +27,7 @@ export class CommandMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject); break; @@ -50,6 +51,7 @@ export class CommandMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/delay-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/delay-macro-action.ts index e2fdffe22dd..78c6202174a 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/delay-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/delay-macro-action.ts @@ -28,6 +28,7 @@ export class DelayMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject); break; @@ -51,6 +52,7 @@ export class DelayMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer); break; 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 01b21773887..1607dbf4c7a 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 @@ -60,6 +60,7 @@ export class KeyMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject); break; @@ -83,6 +84,7 @@ export class KeyMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer); break; 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 580b705489b..014458ff7bd 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 @@ -42,6 +42,7 @@ export class MouseButtonMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject); break; @@ -65,6 +66,7 @@ export class MouseButtonMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/move-mouse-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/move-mouse-macro-action.ts index c3a71bb50a6..95c9ded53c3 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/move-mouse-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/move-mouse-macro-action.ts @@ -31,6 +31,7 @@ export class MoveMouseMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject); break; @@ -54,6 +55,7 @@ export class MoveMouseMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/scroll-mouse-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/scroll-mouse-macro-action.ts index 8487dede1df..e5637b212a0 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/scroll-mouse-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/scroll-mouse-macro-action.ts @@ -31,6 +31,7 @@ export class ScrollMouseMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject); break; @@ -54,6 +55,7 @@ export class ScrollMouseMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/text-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/text-macro-action.ts index f1d0a840d7a..1859ba33e7d 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/text-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/text-macro-action.ts @@ -27,6 +27,7 @@ export class TextMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject); break; @@ -50,6 +51,7 @@ export class TextMacroAction extends MacroAction { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer); break; 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 502f9e5f237..88ece98f1ba 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro.ts @@ -40,6 +40,7 @@ export class Macro { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject, serialisationInfo); break; @@ -63,6 +64,7 @@ export class Macro { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer, serialisationInfo); break; 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 700f723d954..072614e7d36 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 @@ -95,6 +95,7 @@ export class ModuleConfiguration { case 9: case 11: case 12: + case 13: this.fromJsonObjectV7(jsonObject); break; @@ -120,6 +121,7 @@ export class ModuleConfiguration { case 9: case 11: case 12: + case 13: this.fromBinaryV7(buffer); break; 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 938041d4391..6d187b5654b 100644 --- a/packages/uhk-common/src/config-serializer/config-items/module.ts +++ b/packages/uhk-common/src/config-serializer/config-items/module.ts @@ -44,6 +44,7 @@ export class Module { case 9: case 11: case 12: + case 13: this.fromJsonObjectV1(jsonObject, macros, serialisationInfo); break; @@ -67,6 +68,7 @@ export class Module { case 9: case 11: case 12: + case 13: this.fromBinaryV1(buffer, macros, serialisationInfo); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/rgb-color.ts b/packages/uhk-common/src/config-serializer/config-items/rgb-color.ts index 64600f06d9c..7e1608d06c4 100644 --- a/packages/uhk-common/src/config-serializer/config-items/rgb-color.ts +++ b/packages/uhk-common/src/config-serializer/config-items/rgb-color.ts @@ -37,6 +37,7 @@ export class RgbColor { case 9: case 11: case 12: + case 13: this.fromJsonV6(jsonObject); break; @@ -62,6 +63,7 @@ export class RgbColor { case 9: case 11: case 12: + case 13: this.fromBinaryV6(buffer); break; diff --git a/packages/uhk-common/src/config-serializer/config-items/user-configuration.spec.ts b/packages/uhk-common/src/config-serializer/config-items/user-configuration.spec.ts index 75ff412d594..b4af6c05884 100644 --- a/packages/uhk-common/src/config-serializer/config-items/user-configuration.spec.ts +++ b/packages/uhk-common/src/config-serializer/config-items/user-configuration.spec.ts @@ -8,9 +8,11 @@ describe('user-configuration', () => { it('should transform an empty config', () => { jsonTester({ - userConfigMajorVersion: 12, - userConfigMinorVersion: 1, + userConfigMajorVersion: 13, + userConfigMinorVersion: 0, userConfigPatchVersion: 0, + lastSaveAgentTag: '', + lastSaveFirmwareTag: '', deviceName: 'My UHK', doubleTapSwitchLayerTimeout: 250, perKeyRgbPresent: false, 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 006cddf6199..03c51cfae86 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 @@ -34,6 +34,10 @@ export class UserConfiguration implements MouseSpeedConfiguration { @assertUInt16 userConfigPatchVersion: number; + lastSaveAgentTag : string; + + lastSaveFirmwareTag : string; + @assertUInt32 userConfigurationLength: number; deviceName: string; @@ -176,6 +180,11 @@ export class UserConfiguration implements MouseSpeedConfiguration { this.userConfigMinorVersion = jsonObject.userConfigMinorVersion; this.userConfigPatchVersion = jsonObject.userConfigPatchVersion; + if (this.userConfigMajorVersion >= 13) { + this.lastSaveAgentTag = jsonObject.lastSaveAgentTag ; + this.lastSaveFirmwareTag = jsonObject.lastSaveFirmwareTag; + } + switch (this.userConfigMajorVersion) { case 1: case 2: @@ -200,6 +209,7 @@ export class UserConfiguration implements MouseSpeedConfiguration { case 9: case 11: case 12: + case 13: this.fromJsonObjectV9(jsonObject); break; @@ -222,6 +232,7 @@ export class UserConfiguration implements MouseSpeedConfiguration { this.migrateToV11(); this.migrateToV12(); this.migrateToV12_1(); + this.migrateToV13(); this.recalculateConfigurationLength(); @@ -233,6 +244,11 @@ export class UserConfiguration implements MouseSpeedConfiguration { this.userConfigMinorVersion = buffer.readUInt16(); this.userConfigPatchVersion = buffer.readUInt16(); + if (this.userConfigMajorVersion >= 13) { + this.lastSaveAgentTag = buffer.readString(); + this.lastSaveFirmwareTag = buffer.readString(); + } + switch (this.userConfigMajorVersion) { case 1: case 2: @@ -257,6 +273,7 @@ export class UserConfiguration implements MouseSpeedConfiguration { case 9: case 11: case 12: + case 13: this.fromBinaryV9(buffer); break; @@ -321,6 +338,10 @@ export class UserConfiguration implements MouseSpeedConfiguration { this.userConfigurationLength = 0; } + if (this.migrateToV13()) { + this.userConfigurationLength = 0; + } + if (this.userConfigurationLength === 0) { this.recalculateConfigurationLength(); } @@ -333,6 +354,8 @@ export class UserConfiguration implements MouseSpeedConfiguration { userConfigMajorVersion: this.userConfigMajorVersion, userConfigMinorVersion: this.userConfigMinorVersion, userConfigPatchVersion: this.userConfigPatchVersion, + lastSaveAgentTag: this.lastSaveAgentTag, + lastSaveFirmwareTag: this.lastSaveFirmwareTag, deviceName: this.deviceName, doubleTapSwitchLayerTimeout: this.doubleTapSwitchLayerTimeout, perKeyRgbPresent: this.perKeyRgbPresent, @@ -392,6 +415,8 @@ export class UserConfiguration implements MouseSpeedConfiguration { buffer.writeUInt16(this.userConfigMajorVersion); buffer.writeUInt16(this.userConfigMinorVersion); buffer.writeUInt16(this.userConfigPatchVersion); + buffer.writeString(this.lastSaveAgentTag); + buffer.writeString(this.lastSaveFirmwareTag); buffer.writeUInt32(this.userConfigurationLength); buffer.writeString(this.deviceName); buffer.writeUInt16(this.doubleTapSwitchLayerTimeout); @@ -476,6 +501,12 @@ export class UserConfiguration implements MouseSpeedConfiguration { this.userConfigurationLength = buffer.offset; } + setAgentAndFirmwareVersion(agentTag: string, firmwareTag: string): void { + this.lastSaveAgentTag = agentTag; + this.lastSaveFirmwareTag = firmwareTag; + this.recalculateConfigurationLength() + } + private setDefaultDeviceName(): void { if (!this.deviceName || this.deviceName.trim().length === 0) { this.deviceName = 'My UHK'; @@ -1378,6 +1409,19 @@ export class UserConfiguration implements MouseSpeedConfiguration { return true; } + private migrateToV13(): boolean { + if (this.userConfigMajorVersion > 12) { + return false; + } + + this.userConfigMajorVersion = 13; + this.userConfigMinorVersion = 0; + this.userConfigPatchVersion = 0; + // We don't know it. We will update it before save user config to the keyboard + this.lastSaveAgentTag = ''; + this.lastSaveFirmwareTag = ''; + } + private getSerialisationInfo(): SerialisationInfo { return { isUserConfigContainsRgbColors: this.perKeyRgbPresent, diff --git a/packages/uhk-common/src/models/version-information.ts b/packages/uhk-common/src/models/version-information.ts index b423d776931..ef27b8b059e 100644 --- a/packages/uhk-common/src/models/version-information.ts +++ b/packages/uhk-common/src/models/version-information.ts @@ -1,4 +1,6 @@ export interface VersionInformation { + agentRepo: string; + agentTag: string; version: string; firmwareVersion: string; deviceProtocolVersion: string; diff --git a/packages/uhk-common/src/util/constants.ts b/packages/uhk-common/src/util/constants.ts index b21ff12ffee..2f0586ce904 100644 --- a/packages/uhk-common/src/util/constants.ts +++ b/packages/uhk-common/src/util/constants.ts @@ -5,3 +5,5 @@ export namespace Constants { 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; diff --git a/packages/uhk-common/src/util/helpers.ts b/packages/uhk-common/src/util/helpers.ts index 3372d69fe28..71468bc63d7 100644 --- a/packages/uhk-common/src/util/helpers.ts +++ b/packages/uhk-common/src/util/helpers.ts @@ -2,6 +2,7 @@ import { Buffer } from '../buffer.js'; import { HardwareConfiguration, UhkBuffer, UserConfiguration } from '../config-serializer/index.js'; +import { UHK_EEPROM_SIZE } from './constants.js'; import { shouldUpgradeAgent } from './should-upgrade-agent.js'; export const getHardwareConfigFromDeviceResponse = (json: string): HardwareConfiguration => { @@ -85,7 +86,7 @@ export const getUserConfigFromJsonObject = (data: any): UserConfiguration => { export const mapObjectToUserConfigBinaryBuffer = (obj: any): Buffer => { const configuration = new UserConfiguration(); configuration.fromJsonObject(obj); - const buffer = new UhkBuffer(32768); + const buffer = new UhkBuffer(UHK_EEPROM_SIZE); configuration.toBinary(buffer); return buffer.getBufferContent(); diff --git a/packages/uhk-common/user-config-80.json b/packages/uhk-common/user-config-80.json index c4bbdbd958d..48cad8c363c 100644 --- a/packages/uhk-common/user-config-80.json +++ b/packages/uhk-common/user-config-80.json @@ -1,7 +1,9 @@ { - "userConfigMajorVersion": 12, - "userConfigMinorVersion": 1, + "userConfigMajorVersion": 13, + "userConfigMinorVersion": 0, "userConfigPatchVersion": 0, + "lastSaveAgentTag": "", + "lastSaveFirmwareTag": "", "deviceName": "My UHK", "doubleTapSwitchLayerTimeout": 250, "perKeyRgbPresent": false, diff --git a/packages/uhk-usb/src/uhk-operations.ts b/packages/uhk-usb/src/uhk-operations.ts index 428c3af3008..fe5575f2831 100644 --- a/packages/uhk-usb/src/uhk-operations.ts +++ b/packages/uhk-usb/src/uhk-operations.ts @@ -22,10 +22,13 @@ import { OLED_DISPLAY_WIDTH, UhkBuffer, UhkDeviceProduct, + UHK_EEPROM_SIZE, UhkModule, UHK_MODULE_IDS_TYPE, UHK_MODULE_IDS, UNKNOWN_DEVICE, + UserConfiguration, + VERSIONS, } from 'uhk-common'; import { promisify } from 'util'; import semver from 'semver'; @@ -394,7 +397,33 @@ export class UhkOperations { public async saveUserConfiguration(buffer: Buffer): Promise { try { this.logService.usbOps('[DeviceOperation] USB[T]: Write user configuration to keyboard'); - await this.sendConfigToKeyboard(buffer, true); + let shouldRecalculateLength = false; + const uhkBuffer = UhkBuffer.fromArray(buffer as any) + const userConfiguration = new UserConfiguration() + userConfiguration.fromBinary(uhkBuffer) + + const agentTag = `${VERSIONS.agentRepo}/${VERSIONS.agentTag}`; + if (userConfiguration.lastSaveAgentTag !== agentTag) { + this.logService.misc(`[DeviceOperation] Update userConfig.lastSaveAgentTag. ${userConfiguration.lastSaveAgentTag} => ${agentTag}`); + userConfiguration.lastSaveAgentTag = agentTag; + shouldRecalculateLength = true; + } + + const deviceVersionInfo = await this.getDeviceVersionInfo() + const firmwareTag = `${deviceVersionInfo.firmwareGitRepo}/${deviceVersionInfo.firmwareGitTag}`; + if (userConfiguration.lastSaveFirmwareTag !== firmwareTag) { + this.logService.misc(`[DeviceOperation] Update userConfig.lastSaveFirmwareTag. ${userConfiguration.lastSaveFirmwareTag} => ${firmwareTag}`); + userConfiguration.lastSaveFirmwareTag = firmwareTag; + shouldRecalculateLength = true; + } + + if (shouldRecalculateLength) { + userConfiguration.recalculateConfigurationLength(); + } + + const resultBuffer = new UhkBuffer(UHK_EEPROM_SIZE) + userConfiguration.toBinary(resultBuffer) + await this.sendConfigToKeyboard(resultBuffer.getBufferContent(), true); await this.applyConfiguration(); this.logService.usbOps('[DeviceOperation] USB[T]: Write user configuration to EEPROM'); await this.writeConfigToEeprom(ConfigBufferId.validatedUserConfig); diff --git a/packages/uhk-web/src/app/store/effects/user-config.ts b/packages/uhk-web/src/app/store/effects/user-config.ts index 4adbcf99f65..26f65151c76 100644 --- a/packages/uhk-web/src/app/store/effects/user-config.ts +++ b/packages/uhk-web/src/app/store/effects/user-config.ts @@ -15,11 +15,13 @@ import { ConfigurationReply, LogService, NotificationType, + RightModuleInfo, UHK_60_DEVICE, UhkBuffer, UhkDeviceProduct, UHK_MODULES, - UserConfiguration + UserConfiguration, + VERSIONS, } from 'uhk-common'; import { EmptyAction } from '../actions/app'; @@ -42,6 +44,7 @@ import { Uhk80MigratorService } from '../../services/uhk80-migrator.service'; import { AppState, getConnectedDevice, + getHardwareModules, getPrevUserConfiguration, getRouterState, getUserConfiguration, @@ -283,9 +286,10 @@ export class UserConfigEffects { saveUserConfigInJsonFile$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SaveUserConfigInJsonFile), - withLatestFrom(this.store.select(getUserConfiguration)), - tap(([action, userConfiguration]) => { - const asString = JSON.stringify(userConfiguration.toJsonObject(), null, 2); + withLatestFrom(this.store.select(getUserConfiguration), this.store.select(getHardwareModules)), + tap(([action, userConfiguration, hardwareModules]) => { + const newUserConfiguration= updateUserConfigurationWithLastSaveInfo(userConfiguration, hardwareModules.rightModuleInfo); + const asString = JSON.stringify(newUserConfiguration.toJsonObject(), null, 2); const asBlob = new Blob([asString], { type: 'text/plain' }); saveAs(asBlob, 'UserConfiguration.json'); }) @@ -296,10 +300,11 @@ export class UserConfigEffects { saveUserConfigInBinFile$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SaveUserConfigInBinFile), - withLatestFrom(this.store.select(getUserConfiguration)), - tap(([action, userConfiguration]) => { + withLatestFrom(this.store.select(getUserConfiguration), this.store.select(getHardwareModules)), + tap(([action, userConfiguration, hardwareModules]) => { + const newUserConfiguration= updateUserConfigurationWithLastSaveInfo(userConfiguration, hardwareModules.rightModuleInfo); const uhkBuffer = new UhkBuffer(); - userConfiguration.toBinary(uhkBuffer); + newUserConfiguration.toBinary(uhkBuffer); const blob = new Blob([uhkBuffer.getBufferContent()]); saveAs(blob, 'UserConfiguration.bin'); }) @@ -446,3 +451,12 @@ export class UserConfigEffects { ); } } + +function updateUserConfigurationWithLastSaveInfo(userConfiguration: UserConfiguration, rightModuleInfo: RightModuleInfo) { + const newUserConfiguration = userConfiguration.clone() + newUserConfiguration.lastSaveAgentTag = `${VERSIONS.agentRepo}/${VERSIONS.agentTag}`; + newUserConfiguration.lastSaveFirmwareTag = `${rightModuleInfo.firmwareGitRepo}/${rightModuleInfo.firmwareGitTag}` + newUserConfiguration.recalculateConfigurationLength(); + + return newUserConfiguration; +} diff --git a/scripts/get-github-tag.mjs b/scripts/get-github-tag.mjs new file mode 100644 index 00000000000..6e4ecfe6376 --- /dev/null +++ b/scripts/get-github-tag.mjs @@ -0,0 +1,8 @@ +/** + * @returns {string} + */ +export default function getGithubTag() { + const result = /^refs\/tags\/(v\d+\.\d+\.\d+)$/.exec(process.env.GITHUB_REF); + + return result && result[1]; +} diff --git a/scripts/release.mjs b/scripts/release.mjs index 7fccc45b394..917d0204b74 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -1,5 +1,7 @@ import { exec, execSync } from 'node:child_process'; +import getGithubTag from './get-github-tag.mjs'; + const __dirname = import.meta.dirname; const TEST_BUILD = process.env.TEST_BUILD; // set true if you would like to test on your local machine @@ -156,12 +158,6 @@ async function afterPack(context) { fs.chmodSync(chromeSandbox, '4755') } -function getGithubTag() { - const result = /^refs\/tags\/(v\d+\.\d+\.\d+)$/.exec(process.env.GITHUB_REF); - - return result && result[1]; -} - async function getReleaseNotes() { if(!gitTag) { return