feat: device recovery mode (#642)
* add new page and ipc processing * refactor: remove unused references from uhk.js * feat: add device recovery route * refactor: device permission * feat: write firmware update log to the screen * fix: xterm height * feat: add reload button to the recovery page * refactor: deviceConnectionState.hasPermission in appStartInfo * refactor: use correct imports * refactor: move .ok-button css class to the main style.scss * feat: add bootload active route guard * style: move RecoveryDeviceAction into new line * feat: delete reload button * feat: start device polling after device recovery
This commit is contained in:
committed by
László Monda
parent
2cf8044987
commit
653465f0e0
@@ -1,6 +1,7 @@
|
||||
export namespace Constants {
|
||||
export const VENDOR_ID = 0x1D50;
|
||||
export const PRODUCT_ID = 0x6122;
|
||||
export const BOOTLOADER_ID = 0x6120;
|
||||
export const MAX_PAYLOAD_SIZE = 64;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cloneDeep, isEqual } from 'lodash';
|
||||
import { Device, devices, HID } from 'node-hid';
|
||||
import { CommandLineArgs, LogService } from 'uhk-common';
|
||||
import { CommandLineArgs, DeviceConnectionState, LogService } from 'uhk-common';
|
||||
|
||||
import {
|
||||
ConfigBufferId,
|
||||
@@ -50,12 +50,10 @@ export class UhkHidDevice {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.deviceConnected()) {
|
||||
return true;
|
||||
}
|
||||
const devs = devices();
|
||||
|
||||
this._hasPermission = this.getDevice() !== null;
|
||||
this.close();
|
||||
this._hasPermission = devs.some((x: Device) => x.vendorId === Constants.VENDOR_ID &&
|
||||
(x.productId === Constants.PRODUCT_ID || x.productId === Constants.BOOTLOADER_ID));
|
||||
|
||||
return this._hasPermission;
|
||||
} catch (err) {
|
||||
@@ -69,15 +67,25 @@ export class UhkHidDevice {
|
||||
* Return with true is an UHK Device is connected to the computer.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public deviceConnected(): boolean {
|
||||
const connected = devices().some((dev: Device) => dev.vendorId === Constants.VENDOR_ID &&
|
||||
dev.productId === Constants.PRODUCT_ID);
|
||||
public getDeviceConnectionState(): DeviceConnectionState {
|
||||
const devs = devices();
|
||||
const result: DeviceConnectionState = {
|
||||
bootloaderActive: false,
|
||||
connected: false,
|
||||
hasPermission: this.hasPermission()
|
||||
};
|
||||
|
||||
if (!connected) {
|
||||
this._hasPermission = false;
|
||||
for (const dev of devs) {
|
||||
if (dev.vendorId === Constants.VENDOR_ID &&
|
||||
dev.productId === Constants.PRODUCT_ID) {
|
||||
result.connected = true;
|
||||
} else if (dev.vendorId === Constants.VENDOR_ID &&
|
||||
dev.productId === Constants.BOOTLOADER_ID) {
|
||||
result.bootloaderActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
return connected;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Constants, UsbCommand } from './constants';
|
||||
import { LogService } from 'uhk-common';
|
||||
import { DeviceConnectionState, LogService } from 'uhk-common';
|
||||
|
||||
export const snooze = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
@@ -95,3 +95,9 @@ export async function retry(command: Function, maxTry = 3, logService?: LogServi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const deviceConnectionStateComparer = (a: DeviceConnectionState, b: DeviceConnectionState): boolean => {
|
||||
return a.hasPermission === b.hasPermission
|
||||
&& a.connected === b.connected
|
||||
&& a.bootloaderActive === b.bootloaderActive;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user