* feat: Make saving the configuration more robust * parse backup user config before return * fix some bug * Add write-userconfig.js and invalid-config.bin * throw exception if failed user config parsing * Merge branch 'master' into feat-467-make-save-more-robust * hide keymaps and macros if agent in restore mode * fix Device name settings
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { HardwareConfiguration, UhkBuffer, UserConfiguration } from '../../index';
|
|
|
|
export const getHardwareConfigFromDeviceResponse = (json: string): HardwareConfiguration => {
|
|
const data = JSON.parse(json);
|
|
const hardwareConfig = new HardwareConfiguration();
|
|
hardwareConfig.fromBinary(UhkBuffer.fromArray(data));
|
|
|
|
if (hardwareConfig.uniqueId > 0) {
|
|
return hardwareConfig;
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export const getUserConfigFromDeviceResponse = (json: string): UserConfiguration => {
|
|
const data = JSON.parse(json);
|
|
const userConfig = new UserConfiguration();
|
|
userConfig.fromBinary(UhkBuffer.fromArray(data));
|
|
|
|
if (userConfig.userConfigMajorVersion > 0) {
|
|
return userConfig;
|
|
}
|
|
|
|
throw Error('Invalid user configuration');
|
|
};
|
|
|
|
export const mapObjectToUserConfigBinaryBuffer = (obj: any): Buffer => {
|
|
const configuration = new UserConfiguration();
|
|
configuration.fromJsonObject(obj);
|
|
const buffer = new UhkBuffer();
|
|
configuration.toBinary(buffer);
|
|
|
|
return buffer.getBufferContent();
|
|
};
|