diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/keymap.spec.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/keymap.spec.ts index 02b09d7a..9be3c18b 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/keymap.spec.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/keymap.spec.ts @@ -4,6 +4,7 @@ describe('keymap', () => { it('should normalize SwitchLayerAction if non base layer action is not SwitchLayerAction', () => { const inputJsonConfig = { dataModelVersion: 1, + deviceName: 'My UHK', moduleConfigurations: [], macros: [], keymaps: [ @@ -63,6 +64,7 @@ describe('keymap', () => { }; const expectedJsonConfig = { dataModelVersion: 1, + deviceName: 'My UHK', moduleConfigurations: [], macros: [], keymaps: [ @@ -131,6 +133,7 @@ describe('keymap', () => { it('should normalize SwitchLayerAction if non base layer action is other SwitchLayerAction', () => { const inputJsonConfig = { dataModelVersion: 1, + deviceName: 'My UHK', moduleConfigurations: [], macros: [], keymaps: [ @@ -190,6 +193,7 @@ describe('keymap', () => { }; const expectedJsonConfig = { dataModelVersion: 1, + deviceName: 'My UHK', moduleConfigurations: [], macros: [], keymaps: [ 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 ce0bcf20..e75e0556 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 @@ -9,6 +9,7 @@ describe('user-configuration', () => { it('should transform an empty config', () => { jsonTester({ dataModelVersion: 1, + deviceName: 'My UHK', moduleConfigurations: [], macros: [], keymaps: [] @@ -18,6 +19,7 @@ describe('user-configuration', () => { it('should transform a null keyActionType ', () => { jsonTester({ dataModelVersion: 1, + deviceName: 'My UHK', moduleConfigurations: [], macros: [], keymaps: [ @@ -39,6 +41,21 @@ describe('user-configuration', () => { ] }); }); + + it('Should set the device name to "My UHK" if not exists in the config', () => { + const original = { + dataModelVersion: 1, + moduleConfigurations: [], + macros: [], + keymaps: [] + }; + + const config = new UserConfiguration(); + config.fromJsonObject(original); + + expect(config.deviceName).toEqual('My UHK'); + }); + }); function jsonTester(json: any): void { 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 a79a7cdb..a7305e40 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 @@ -10,14 +10,22 @@ export class UserConfiguration { @assertUInt16 dataModelVersion: number; + deviceName: string; + moduleConfigurations: ModuleConfiguration[] = []; keymaps: Keymap[] = []; macros: Macro[] = []; + constructor() { + this.setDefaultDeviceName(); + } + fromJsonObject(jsonObject: any): UserConfiguration { this.dataModelVersion = jsonObject.dataModelVersion; + this.deviceName = jsonObject.deviceName; + this.setDefaultDeviceName(); this.moduleConfigurations = jsonObject.moduleConfigurations.map((moduleConfiguration: any) => { return new ModuleConfiguration().fromJsonObject(moduleConfiguration); }); @@ -32,6 +40,8 @@ export class UserConfiguration { fromBinary(buffer: UhkBuffer): UserConfiguration { this.dataModelVersion = buffer.readUInt16(); + this.deviceName = buffer.readString(); + this.setDefaultDeviceName(); this.moduleConfigurations = buffer.readArray(uhkBuffer => { return new ModuleConfiguration().fromBinary(uhkBuffer); }); @@ -48,6 +58,7 @@ export class UserConfiguration { toJsonObject(): any { return { dataModelVersion: this.dataModelVersion, + deviceName: this.deviceName, moduleConfigurations: this.moduleConfigurations.map(moduleConfiguration => moduleConfiguration.toJsonObject()), keymaps: this.keymaps.map(keymap => keymap.toJsonObject(this.macros)), macros: this.macros.map(macro => macro.toJsonObject()) @@ -56,6 +67,7 @@ export class UserConfiguration { toBinary(buffer: UhkBuffer): void { buffer.writeUInt16(this.dataModelVersion); + buffer.writeString(this.deviceName); buffer.writeArray(this.moduleConfigurations); buffer.writeArray(this.macros); buffer.writeArray(this.keymaps, (uhkBuffer: UhkBuffer, keymap: Keymap) => { @@ -75,4 +87,9 @@ export class UserConfiguration { return this.macros.find(macro => macroId === macro.id); } + private setDefaultDeviceName(): void { + if (!this.deviceName || this.deviceName.trim().length === 0) { + this.deviceName = 'My UHK'; + } + } } diff --git a/packages/uhk-usb/src/uhk-hid-device.ts b/packages/uhk-usb/src/uhk-hid-device.ts index ad833e2b..2826d49b 100644 --- a/packages/uhk-usb/src/uhk-hid-device.ts +++ b/packages/uhk-usb/src/uhk-hid-device.ts @@ -143,7 +143,7 @@ export class UhkHidDevice { }); const sendData = UhkHidDevice.getTransferData(buffer); - this.logService.debug('[UhkHidDevice] USB[W]:', UhkHidDevice.bufferToString(sendData)); + this.logService.debug('[UhkHidDevice] USB[W]:', UhkHidDevice.bufferToString(sendData).substr(3)); device.write(sendData); }); } diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts index 1835c19a..fb8d4d40 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts @@ -139,5 +139,5 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit default: return true; } - }; + } } diff --git a/packages/uhk-web/src/app/components/side-menu/side-menu.component.html b/packages/uhk-web/src/app/components/side-menu/side-menu.component.html index b2f18ae1..ced53890 100644 --- a/packages/uhk-web/src/app/components/side-menu/side-menu.component.html +++ b/packages/uhk-web/src/app/components/side-menu/side-menu.component.html @@ -1,7 +1,13 @@