Skip to content

Commit

Permalink
feat: checksum tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
ert78gb committed Feb 23, 2025
1 parent 8a9bd03 commit 9fb7a1e
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 20 deletions.
51 changes: 45 additions & 6 deletions packages/uhk-agent/src/services/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ConfigurationReply,
convertBleAddressArrayToString,
convertBleStringToNumberArray,
CurrentlyUpdatingModuleInfo,
DeviceConnectionState,
disableAgentUpgradeProtection,
findUhkModuleById,
Expand Down Expand Up @@ -431,7 +432,11 @@ export class DeviceService {
deviceConfig.md5);

if (data.forceUpgrade || versionInfo.builtFirmwareChecksum !== deviceConfig.md5) {
event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, UHK_DONGLE.name);
event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, {
forceUpgraded: versionInfo.builtFirmwareChecksum === deviceConfig.md5,
moduleName: UHK_DONGLE.name,
newFirmwareChecksum: deviceConfig.md5,
} as CurrentlyUpdatingModuleInfo);
await dongleOperations.updateDeviceFirmware(dongleFirmwarePath, UHK_DONGLE);
this.logService.misc('[DeviceService] Waiting for keyboard');
await waitForDevices(UHK_DONGLE.keyboard);
Expand All @@ -446,6 +451,10 @@ export class DeviceService {
}
}
else {
event.sender.send(IpcEvents.device.moduleFirmwareUpgradeSkip, {
moduleName: UHK_DONGLE.name,
newFirmwareChecksum: deviceConfig?.md5,
} as CurrentlyUpdatingModuleInfo);
this.logService.misc('Skip dongle firmware upgrade.');
}
}
Expand All @@ -471,7 +480,11 @@ export class DeviceService {
deviceConfig.md5);

if (data.forceUpgrade || hardwareModules.rightModuleInfo.builtFirmwareChecksum !== deviceConfig.md5) {
event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, RIGHT_HALF_FIRMWARE_UPGRADE_MODULE_NAME);
event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, {
forceUpgraded: hardwareModules.rightModuleInfo.builtFirmwareChecksum === deviceConfig.md5,
newFirmwareChecksum: deviceConfig.md5,
moduleName: RIGHT_HALF_FIRMWARE_UPGRADE_MODULE_NAME,
} as CurrentlyUpdatingModuleInfo);
await this.operations.updateDeviceFirmware(deviceFirmwarePath, uhkDeviceProduct);
this.logService.misc('[DeviceService] Waiting for keyboard');
await waitForDevices(uhkDeviceProduct.keyboard);
Expand All @@ -490,6 +503,10 @@ export class DeviceService {
response.userConfigSaved = true;
}
} else {
event.sender.send(IpcEvents.device.moduleFirmwareUpgradeSkip, {
moduleName: RIGHT_HALF_FIRMWARE_UPGRADE_MODULE_NAME,
newFirmwareChecksum: deviceConfig?.md5,
} as CurrentlyUpdatingModuleInfo);
this.logService.misc('Skip right firmware upgrade.');
}

Expand All @@ -515,7 +532,13 @@ export class DeviceService {
);

if (data.forceUpgrade || !isLeftModuleFirmwareSame) {
event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, leftModuleInfo.module.name);
const moduleConfig = packageJson.modules.find(firmwareDevice => firmwareDevice.moduleId === leftModuleInfo.module.id);

event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, {
forceUpgraded: isLeftModuleFirmwareSame,
moduleName: leftModuleInfo.module.name,
newFirmwareChecksum: moduleConfig.md5,
} as CurrentlyUpdatingModuleInfo);

if(uhkDeviceProduct.firmwareUpgradeMethod === FIRMWARE_UPGRADE_METHODS.MCUBOOT) {
if (!(await isUhkDeviceConnected(UHK_80_DEVICE_LEFT))) {
Expand All @@ -542,7 +565,12 @@ export class DeviceService {
);
}
} else {
event.sender.send(IpcEvents.device.moduleFirmwareUpgradeSkip, leftModuleInfo.module.name);
const moduleConfig = packageJson.modules.find(firmwareDevice => firmwareDevice.moduleId === leftModuleInfo.module.id);

event.sender.send(IpcEvents.device.moduleFirmwareUpgradeSkip, {
moduleName: leftModuleInfo.module.name,
newFirmwareChecksum: moduleConfig?.md5,
} as CurrentlyUpdatingModuleInfo);
this.logService.misc('[DeviceService] Skip left firmware upgrade.');
}

Expand Down Expand Up @@ -572,7 +600,13 @@ export class DeviceService {
);

if (data.forceUpgrade || !isModuleFirmwareSame) {
event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, moduleInfo.module.name);
const moduleConfig = packageJson.modules.find(firmwareDevice => firmwareDevice.moduleId === moduleInfo.module.id);

event.sender.send(IpcEvents.device.moduleFirmwareUpgrading, {
forceUpgraded: isModuleFirmwareSame,
moduleName: moduleInfo.module.name,
newFirmwareChecksum: moduleConfig.md5,
} as CurrentlyUpdatingModuleInfo);
await this.operations
.updateModuleWithKboot(
getModuleFirmwarePath(moduleInfo.module, packageJson),
Expand All @@ -581,7 +615,12 @@ export class DeviceService {
);
this.logService.misc(`[DeviceService] "${moduleInfo.module.name}" firmware update done.`);
} else {
event.sender.send(IpcEvents.device.moduleFirmwareUpgradeSkip, moduleInfo.module.name);
const moduleConfig = packageJson.modules.find(firmwareDevice => firmwareDevice.moduleId === moduleInfo.module.id);

event.sender.send(IpcEvents.device.moduleFirmwareUpgradeSkip, {
moduleName: moduleInfo.module.name,
newFirmwareChecksum: moduleConfig?.md5,
} as CurrentlyUpdatingModuleInfo);
this.logService.misc(`[DeviceService] Skip "${moduleInfo.module.name}" firmware upgrade.`);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CurrentlyUpdatingModuleInfo {
forceUpgraded: boolean;
moduleName: string;
newFirmwareChecksum: string;
}
1 change: 1 addition & 0 deletions packages/uhk-common/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './backup-user-configuration-info.js';
export * from './ble-address-pair.js';
export * from './command-line-args.js';
export * from './config-sizes-info.js';
export * from './currently-updating-module-info.js';
export * from './device-module-record.js';
export * from './device-version-information.js';
export * from './dongle.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ <h1>

<ul class="list-unstyled">
<li *ngFor="let state of firmwareUpgradeStates.modules; trackBy:firmwareUpgradeStateTrackByFn;">
<span class="upgrading">
<ng-template #htmlTooltipTemplate>
<div [innerHTML]="checksumTooltip(state)"></div>
</ng-template>
<span class="upgrading"
[ngbTooltip]="htmlTooltipTemplate"
tooltipClass="tooltip-firmware-checksum"
>
<fa-icon *ngIf="state.state === 'Upgrading'" [icon]="faSpinner" animation="spin" [fixedWidth]="true"></fa-icon>
<fa-icon *ngIf="state.state === 'Failed'" [icon]="faExclamation" class="text-danger" [fixedWidth]="true"></fa-icon>
<fa-icon *ngIf="state.state === 'Success'" [icon]="faCheck" [fixedWidth]="true"></fa-icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChangeDetectorRef, Component, OnDestroy, ViewChild } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Store } from '@ngrx/store';
import { Observable, Subscription } from 'rxjs';
import {
Expand All @@ -25,7 +26,7 @@ import {
import { RecoveryModuleAction, UpdateFirmwareAction, UpdateFirmwareWithAction } from '../../../store/actions/device';
import { XtermLog } from '../../../models/xterm-log';
import { XtermComponent } from '../../xterm/xterm.component';
import { FirmwareUpgradeState, ModuleFirmwareUpgradeState, UpdateFirmwareWithPayload } from '../../../models';
import { FirmwareUpgradeState, ModuleFirmwareUpgradeState, ModuleFirmwareUpgradeStates, UpdateFirmwareWithPayload } from '../../../models';

@Component({
selector: 'device-firmware',
Expand Down Expand Up @@ -60,7 +61,8 @@ export class DeviceFirmwareComponent implements OnDestroy {
private subscription = new Subscription();

constructor(private store: Store<AppState>,
private cdRef: ChangeDetectorRef) {
private cdRef: ChangeDetectorRef,
private sanitizer: DomSanitizer) {
this.flashFirmwareButtonDisabled$ = store.select(flashFirmwareButtonDisabled);
this.xtermLog$ = store.select(xtermLog);
this.getAgentVersionInfo$ = store.select(getAgentVersionInfo);
Expand Down Expand Up @@ -125,6 +127,42 @@ export class DeviceFirmwareComponent implements OnDestroy {
return '#' + gitTag;
}

checksumTooltip(upgradeState: ModuleFirmwareUpgradeState): SafeHtml {
return this.sanitizer.bypassSecurityTrustHtml(this.calculateChecksumTooltip(upgradeState));
}

private calculateChecksumTooltip(upgradeState: ModuleFirmwareUpgradeState): string {
if (upgradeState.state === ModuleFirmwareUpgradeStates.Upgrading) {
if (upgradeState.forceUpgraded) {
return `Force upgrading, even though expected checksum (${upgradeState.newFirmwareChecksum}) is equal with actual (${upgradeState.currentFirmwareChecksum})`
}
else {
return `Upgrading, because expected checksum (${upgradeState.newFirmwareChecksum}) is not equal with actual (${upgradeState.currentFirmwareChecksum})`
}
}
else if (upgradeState.state === ModuleFirmwareUpgradeStates.Skipped) {
return `Not upgraded, because expected checksum (${upgradeState.newFirmwareChecksum}) was equal with actual (${upgradeState.currentFirmwareChecksum})`
}
else if (upgradeState.state === ModuleFirmwareUpgradeStates.Success) {
if (upgradeState.forceUpgraded) {
return `Force upgraded, even though expected checksum (${upgradeState.newFirmwareChecksum}) was equal with actual (${upgradeState.currentFirmwareChecksum})`
}
else {
return `Upgraded, because expected checksum (${upgradeState.newFirmwareChecksum}) was not equal with actual (${upgradeState.currentFirmwareChecksum})`
}
}
else if (upgradeState.state === ModuleFirmwareUpgradeStates.Failed) {
if (upgradeState.forceUpgraded) {
return `Force upgrade failed, expected checksum (${upgradeState.newFirmwareChecksum}) is equal with actual (${upgradeState.currentFirmwareChecksum})`
}
else {
return `Upgrade failed, expected checksum (${upgradeState.newFirmwareChecksum}) is not equal with actual (${upgradeState.currentFirmwareChecksum})`
}
}

return ''
}

private scrollToTheEndOfTheLogs(): void {
if (this.xtermRef) {
this.xtermRef.scrollToTheEnd();
Expand Down
3 changes: 3 additions & 0 deletions packages/uhk-web/src/app/models/firmware-upgrade-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export enum ModuleFirmwareUpgradeStates {

export interface ModuleFirmwareUpgradeState {
firmwareUpgradeSupported: boolean;
forceUpgraded: boolean;
isOfficialFirmware?: boolean;
gitRepo?: string;
gitTag?: string;
moduleName: string;
currentFirmwareChecksum: string;
currentFirmwareVersion: string;
newFirmwareVersion?: string;
newFirmwareChecksum?: string;
state: ModuleFirmwareUpgradeStates;
tooltip?: string;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/uhk-web/src/app/services/device-renderer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Action, Store } from '@ngrx/store';

import {
ChangeKeyboardLayoutIpcResponse,
CurrentlyUpdatingModuleInfo,
DeviceConnectionState,
DeviceVersionInformation,
FirmwareJson,
Expand Down Expand Up @@ -193,11 +194,11 @@ export class DeviceRendererService {
this.dispachStoreAction(new UpdateFirmwareJsonAction(data));
});

this.ipcRenderer.on(IpcEvents.device.moduleFirmwareUpgradeSkip, (event: string, response: string) => {
this.ipcRenderer.on(IpcEvents.device.moduleFirmwareUpgradeSkip, (event: string, response: CurrentlyUpdatingModuleInfo) => {
this.dispachStoreAction(new CurrentlyUpdateSkipModuleAction(response));
});

this.ipcRenderer.on(IpcEvents.device.moduleFirmwareUpgrading, (event: string, response: string) => {
this.ipcRenderer.on(IpcEvents.device.moduleFirmwareUpgrading, (event: string, response: CurrentlyUpdatingModuleInfo) => {
this.dispachStoreAction(new CurrentlyUpdatingModuleAction(response));
});

Expand Down
5 changes: 3 additions & 2 deletions packages/uhk-web/src/app/store/actions/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BackupUserConfiguration,
ChangeKeyboardLayoutIpcResponse,
ConfigSizesInfo,
CurrentlyUpdatingModuleInfo,
DeviceConnectionState,
DeviceVersionInformation,
FirmwareJson,
Expand Down Expand Up @@ -136,14 +137,14 @@ export class ResetUserConfigurationAction implements Action {
export class CurrentlyUpdatingModuleAction implements Action {
type = ActionTypes.CurrentlyUpdatingModule;

constructor(public payload: string) {
constructor(public payload: CurrentlyUpdatingModuleInfo) {
}
}

export class CurrentlyUpdateSkipModuleAction implements Action {
type = ActionTypes.CurrentlyUpdateSkipModule;

constructor(public payload: string) {
constructor(public payload: CurrentlyUpdatingModuleInfo) {
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/uhk-web/src/app/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,9 @@ export const getFirmwareUpgradeState = createSelector(runningInElectron, getStat
firmwareUpgradeSupported: true,
gitRepo: UHK_OFFICIAL_FIRMWARE_REPO,
isOfficialFirmware: true,
currentFirmwareChecksum: '',
currentFirmwareVersion: agentVersionInfo.firmwareVersion,
forceUpgraded: false,
newFirmwareVersion: undefined,
state: ModuleFirmwareUpgradeStates.Idle
},
Expand All @@ -720,7 +722,9 @@ export const getFirmwareUpgradeState = createSelector(runningInElectron, getStat
firmwareUpgradeSupported: true,
gitRepo: UHK_OFFICIAL_FIRMWARE_REPO,
isOfficialFirmware: true,
currentFirmwareChecksum: '',
currentFirmwareVersion: agentVersionInfo.firmwareVersion,
forceUpgraded: false,
newFirmwareVersion: undefined,
state: ModuleFirmwareUpgradeStates.Idle
}
Expand Down
Loading

0 comments on commit 9fb7a1e

Please sign in to comment.