fix: write agent version into the log when upgrade firmware (#802)
This commit is contained in:
committed by
László Monda
parent
8afdeac306
commit
edcff069fd
@@ -9,7 +9,8 @@ import {
|
||||
IpcResponse,
|
||||
LogService,
|
||||
mapObjectToUserConfigBinaryBuffer,
|
||||
SaveUserConfigurationData
|
||||
SaveUserConfigurationData,
|
||||
UpdateFirmwareData
|
||||
} from 'uhk-common';
|
||||
import { deviceConnectionStateComparer, snooze, UhkHidDevice, UhkOperations } from 'uhk-usb';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
@@ -31,7 +32,6 @@ import {
|
||||
getPackageJsonFromPathAsync,
|
||||
saveTmpFirmware
|
||||
} from '../util';
|
||||
import { getVersions } from '../../../uhk-web/src/app/util';
|
||||
|
||||
/**
|
||||
* IpcMain pair of the UHK Communication
|
||||
@@ -158,11 +158,12 @@ export class DeviceService {
|
||||
|
||||
public async updateFirmware(event: Electron.Event, args?: Array<string>): Promise<void> {
|
||||
const response = new FirmwareUpgradeIpcResponse();
|
||||
const data: UpdateFirmwareData = JSON.parse(args[0]);
|
||||
|
||||
let firmwarePathData: TmpFirmware;
|
||||
|
||||
try {
|
||||
this.logService.debug('Agent version:', getVersions().version);
|
||||
this.logService.debug('Agent version:', data.versionInformation.version);
|
||||
const hardwareModules = await this.getHardwareModules(false);
|
||||
this.logService.debug('Device right firmware version:', hardwareModules.rightModuleInfo.firmwareVersion);
|
||||
this.logService.debug('Device left firmware version:', hardwareModules.leftModuleInfo.firmwareVersion);
|
||||
@@ -170,8 +171,8 @@ export class DeviceService {
|
||||
this.device.resetDeviceCache();
|
||||
this.stopPollTimer();
|
||||
|
||||
if (args && args.length > 0) {
|
||||
firmwarePathData = await saveTmpFirmware(args[0]);
|
||||
if (data.firmware) {
|
||||
firmwarePathData = await saveTmpFirmware(data.firmware);
|
||||
|
||||
const packageJson = await getPackageJsonFromPathAsync(firmwarePathData.packageJsonPath);
|
||||
this.logService.debug('New firmware version:', packageJson.firmwareVersion);
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as decompressTarbz from 'decompress-tarbz2';
|
||||
|
||||
import { TmpFirmware } from '../models/tmp-firmware';
|
||||
|
||||
export async function saveTmpFirmware(data: string): Promise<TmpFirmware> {
|
||||
export async function saveTmpFirmware(data: Array<number>): Promise<TmpFirmware> {
|
||||
const tmpDirectory = dirSync();
|
||||
const zipFilePath = path.join(tmpDirectory.name, 'firmware.bz2');
|
||||
|
||||
@@ -21,10 +21,9 @@ export async function saveTmpFirmware(data: string): Promise<TmpFirmware> {
|
||||
};
|
||||
}
|
||||
|
||||
function writeDataToFile(data: string, filePath: string): Promise<void> {
|
||||
function writeDataToFile(data: Array<number>, filePath: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const array: Array<number> = JSON.parse(data);
|
||||
const buffer = new Buffer(array);
|
||||
const buffer = new Buffer(data);
|
||||
|
||||
fs.writeFile(filePath, buffer, err => {
|
||||
if (err) {
|
||||
|
||||
@@ -8,3 +8,4 @@ export * from './device-connection-state';
|
||||
export * from './hardware-modules';
|
||||
export * from './hardware-module-info';
|
||||
export * from './save-user-configuration-data';
|
||||
export * from './update-firmware-data';
|
||||
|
||||
6
packages/uhk-common/src/models/update-firmware-data.ts
Normal file
6
packages/uhk-common/src/models/update-firmware-data.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { VersionInformation } from './version-information';
|
||||
|
||||
export interface UpdateFirmwareData {
|
||||
versionInformation: VersionInformation;
|
||||
firmware?: Array<number>;
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
import { Injectable, NgZone } from '@angular/core';
|
||||
import { Action, Store } from '@ngrx/store';
|
||||
|
||||
import { DeviceConnectionState, IpcEvents, IpcResponse, LogService, SaveUserConfigurationData } from 'uhk-common';
|
||||
import {
|
||||
DeviceConnectionState,
|
||||
IpcEvents,
|
||||
IpcResponse,
|
||||
LogService,
|
||||
SaveUserConfigurationData,
|
||||
UpdateFirmwareData
|
||||
} from 'uhk-common';
|
||||
import { AppState } from '../store';
|
||||
import { IpcCommonRenderer } from './ipc-common-renderer';
|
||||
import {
|
||||
@@ -34,12 +41,8 @@ export class DeviceRendererService {
|
||||
this.ipcRenderer.send(IpcEvents.device.loadConfigurations);
|
||||
}
|
||||
|
||||
updateFirmware(data?: Array<number>): void {
|
||||
if (data) {
|
||||
this.ipcRenderer.send(IpcEvents.device.updateFirmware, JSON.stringify(data));
|
||||
} else {
|
||||
this.ipcRenderer.send(IpcEvents.device.updateFirmware);
|
||||
}
|
||||
updateFirmware(data: UpdateFirmwareData): void {
|
||||
this.ipcRenderer.send(IpcEvents.device.updateFirmware, JSON.stringify(data));
|
||||
}
|
||||
|
||||
startConnectionPoller(): void {
|
||||
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
} from '../actions/user-config';
|
||||
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
|
||||
import { DataStorageRepositoryService } from '../../services/datastorage-repository.service';
|
||||
import { getVersions } from '../../util';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceEffects {
|
||||
@@ -201,12 +202,17 @@ export class DeviceEffects {
|
||||
|
||||
@Effect({dispatch: false}) updateFirmware$ = this.actions$
|
||||
.ofType<UpdateFirmwareAction>(ActionTypes.UPDATE_FIRMWARE)
|
||||
.do(() => this.deviceRendererService.updateFirmware());
|
||||
.do(() => this.deviceRendererService.updateFirmware({
|
||||
versionInformation: getVersions()
|
||||
}));
|
||||
|
||||
@Effect({dispatch: false}) updateFirmwareWith$ = this.actions$
|
||||
.ofType<UpdateFirmwareWithAction>(ActionTypes.UPDATE_FIRMWARE_WITH)
|
||||
.map(action => action.payload)
|
||||
.do(data => this.deviceRendererService.updateFirmware(data));
|
||||
.do(data => this.deviceRendererService.updateFirmware({
|
||||
versionInformation: getVersions(),
|
||||
firmware: data
|
||||
}));
|
||||
|
||||
@Effect() updateFirmwareReply$ = this.actions$
|
||||
.ofType<UpdateFirmwareReplyAction>(ActionTypes.UPDATE_FIRMWARE_REPLY)
|
||||
|
||||
Reference in New Issue
Block a user