feat(device): flash device firmware from Agent (#499)

* add dataModelVersion, usbProtocolVersion, slaveProtocolVersion

* read the package.json at appstart

* flash firmware

* update firmware

* fix extra resource path

* fix import modules

* update lock files

* fix imports

* terminal window

* exclude tmp folder from git repo

* ok button

* auto scroll in xterm

* fix maxTry count calculation

* optimize logging

* optimize timeout

* readSync

* Add extra delay

* fix async call

* fix error message in log

* fix ok button disable state

* retry

* list devices

* close device after reenumeration

* retry snooze

* kboot maxtry 10

* retry 100

* remove deprecated toPayload ngrx helper

* flash firmware with custom file

* fix tslint
This commit is contained in:
Róbert Kiss
2017-11-27 22:12:43 +01:00
committed by László Monda
parent f608791a09
commit 297fd3be79
52 changed files with 3914 additions and 894 deletions

View File

@@ -1,7 +1,40 @@
<h1>
<i class="fa fa-sliders"></i>
<span>Firmware</span>
</h1>
<p>
Coming soon ...
</p>
<div class="full-height">
<div class="flex-container">
<div>
<h1>
<i class="fa fa-sliders"></i>
<span>Firmware</span>
</h1>
<p>
Flash firmware {{ (getAgentVersionInfo$ | async).firmwareVersion }} (bundled with Agent)
<button class="btn btn-primary"
[disabled]="flashFirmwareButtonDisbabled$ | async"
(click)="onUpdateFirmware()">Flash firmware
</button>
</p>
<p>
Flash firmware file <input id="firmware-file-select"
type="file"
[disabled]="flashFirmwareButtonDisbabled$ | async"
(change)="changeFile($event)">
<button class="btn btn-primary"
[disabled]="flashFirmwareButtonDisbabled$ | async"
(click)="onUpdateFirmwareWithFile()">Flash firmware
</button>
</p>
</div>
<div class="flex-grow" #scrollMe>
<xterm [logs]="xtermLog$ | async"></xterm>
</div>
<div class="footer">
<button type="button"
class="btn btn-primary ok-button"
[disabled]="firmwareOkButtonDisabled$ | async"
(click)="onOkButtonClick()">OK
</button>
</div>
</div>
</div>

View File

@@ -3,3 +3,25 @@
display: block;
height: 100%;
}
.flex-container {
height: 100%;
max-height: 100%;
display: flex;
flex-direction: column;
}
.flex-grow {
background-color: black;
overflow: auto;
flex: 1;
}
.footer {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.ok-button {
min-width: 100px;
}

View File

@@ -1,4 +1,12 @@
import { Component } from '@angular/core';
import { Component, ElementRef, OnDestroy, ViewChild } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { VersionInformation } from 'uhk-common';
import { AppState, firmwareOkButtonDisabled, flashFirmwareButtonDisbabled, getAgentVersionInfo, xtermLog } from '../../../store';
import { UpdateFirmwareAction, UpdateFirmwareOkButtonAction, UpdateFirmwareWithAction } from '../../../store/actions/device';
import { XtermLog } from '../../../models/xterm-log';
@Component({
selector: 'device-firmware',
@@ -8,5 +16,63 @@ import { Component } from '@angular/core';
'class': 'container-fluid'
}
})
export class DeviceFirmwareComponent {
export class DeviceFirmwareComponent implements OnDestroy {
flashFirmwareButtonDisbabled$: Observable<boolean>;
xtermLog$: Observable<Array<XtermLog>>;
xtermLogSubscription: Subscription;
getAgentVersionInfo$: Observable<VersionInformation>;
firmwareOkButtonDisabled$: Observable<boolean>;
arrayBuffer: Uint8Array;
@ViewChild('scrollMe') divElement: ElementRef;
constructor(private store: Store<AppState>) {
this.flashFirmwareButtonDisbabled$ = store.select(flashFirmwareButtonDisbabled);
this.xtermLog$ = store.select(xtermLog);
this.xtermLogSubscription = this.xtermLog$.subscribe(() => {
if (this.divElement && this.divElement.nativeElement) {
setTimeout(() => {
this.divElement.nativeElement.scrollTop = this.divElement.nativeElement.scrollHeight;
});
}
});
this.getAgentVersionInfo$ = store.select(getAgentVersionInfo);
this.firmwareOkButtonDisabled$ = store.select(firmwareOkButtonDisabled);
}
ngOnDestroy(): void {
this.xtermLogSubscription.unsubscribe();
}
onUpdateFirmware(): void {
this.store.dispatch(new UpdateFirmwareAction());
}
onUpdateFirmwareWithFile(): void {
if (!this.arrayBuffer) {
return;
}
this.store.dispatch(new UpdateFirmwareWithAction(Array.prototype.slice.call(this.arrayBuffer)));
}
onOkButtonClick(): void {
this.store.dispatch(new UpdateFirmwareOkButtonAction());
}
changeFile(event): void {
const files = event.srcElement.files;
if (files.length === 0) {
this.arrayBuffer = null;
return;
}
const fileReader = new FileReader();
fileReader.onloadend = function () {
this.arrayBuffer = new Uint8Array(fileReader.result);
}.bind(this);
fileReader.readAsArrayBuffer(files[0]);
}
}

View File

@@ -19,17 +19,20 @@
<ul [@toggler]="animation['configuration']">
<li class="sidebar__level-2--item">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/device/mouse-speed']">Mouse speed</a>
<a [routerLink]="['/device/mouse-speed']"
[class.disabled]="updatingFirmware$ | async">Mouse speed</a>
</div>
</li>
<li class="sidebar__level-2--item">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/device/configuration']">Configuration</a>
<a [routerLink]="['/device/configuration']"
[class.disabled]="updatingFirmware$ | async">Configuration</a>
</div>
</li>
<li class="sidebar__level-2--item">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/device/firmware']">Firmware</a>
<a [routerLink]="['/device/firmware']"
[class.disabled]="updatingFirmware$ | async">Firmware</a>
</div>
</li>
</ul>
@@ -37,17 +40,22 @@
<li class="sidebar__level-1--item">
<div class="sidebar__level-1">
<i class="fa fa-keyboard-o"></i> Keymaps
<a [routerLink]="['/keymap/add']" class="btn btn-default pull-right btn-sm">
<i class="fa fa-plus"></i>
</a>
<i class="fa fa-chevron-up pull-right" (click)="toggleHide($event, 'keymap')"></i>
<a [routerLink]="['/keymap/add']"
class="btn btn-default pull-right btn-sm"
[class.disabled]="updatingFirmware$ | async">
<i class="fa fa-plus"></i>
</a>
<i class="fa fa-chevron-up pull-right"
(click)="toggleHide($event, 'keymap')"></i>
</div>
<ul [@toggler]="animation['keymap']">
<li *ngFor="let keymap of keymaps$ | async" class="sidebar__level-2--item">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/keymap', keymap.abbreviation]">{{keymap.name}}</a>
<i *ngIf="keymap.isDefault" class="fa fa-star sidebar__fav" title="This is the default keymap which gets activated when powering the keyboard."
data-toggle="tooltip" data-placement="bottom"></i>
<a [routerLink]="['/keymap', keymap.abbreviation]"
[class.disabled]="updatingFirmware$ | async">{{keymap.name}}</a>
<i *ngIf="keymap.isDefault" class="fa fa-star sidebar__fav"
title="This is the default keymap which gets activated when powering the keyboard."
data-toggle="tooltip" data-placement="bottom"></i>
</div>
</li>
</ul>
@@ -55,15 +63,18 @@
<li class="sidebar__level-1--item">
<div class="sidebar__level-1">
<i class="fa fa-play"></i> Macros
<a (click)="addMacro()" class="btn btn-default pull-right btn-sm">
<i class="fa fa-plus"></i>
</a>
<a (click)="addMacro()"
class="btn btn-default pull-right btn-sm"
[class.disabled]="updatingFirmware$ | async">
<i class="fa fa-plus"></i>
</a>
<i class="fa fa-chevron-up pull-right" (click)="toggleHide($event, 'macro')"></i>
</div>
<ul [@toggler]="animation['macro']">
<li *ngFor="let macro of macros$ | async" class="sidebar__level-2--item">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/macro', macro.id]">{{macro.name}}</a>
<a [routerLink]="['/macro', macro.id]"
[class.disabled]="updatingFirmware$ | async">{{macro.name}}</a>
</div>
</li>
</ul>
@@ -76,22 +87,26 @@
<ul [@toggler]="animation['addon']">
<li class="sidebar__level-2--item" data-name="Key cluster" data-abbrev="">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/add-on', 'Key cluster']">Key cluster</a>
<a [routerLink]="['/add-on', 'Key cluster']"
[class.disabled]="updatingFirmware$ | async">Key cluster</a>
</div>
</li>
<li class="sidebar__level-2--item" data-name="Trackball" data-abbrev="">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/add-on', 'Trackball']">Trackball</a>
<a [routerLink]="['/add-on', 'Trackball']"
[class.disabled]="updatingFirmware$ | async">Trackball</a>
</div>
</li>
<li class="sidebar__level-2--item" data-name="Toucpad" data-abbrev="">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/add-on', 'Touchpad']">Touchpad</a>
<a [routerLink]="['/add-on', 'Touchpad']"
[class.disabled]="updatingFirmware$ | async">Touchpad</a>
</div>
</li>
<li class="sidebar__level-2--item" data-name="Trackpoint" data-abbrev="">
<div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/add-on', 'Trackpoint']">Trackpoint</a>
<a [routerLink]="['/add-on', 'Trackpoint']"
[class.disabled]="updatingFirmware$ | async">Trackpoint</a>
</div>
</li>
</ul>

View File

@@ -1,15 +1,16 @@
import { AfterContentInit, Component, ElementRef, Renderer2, ViewChild } from '@angular/core';
import { AfterContentInit, Component, ElementRef, OnDestroy, Renderer2, ViewChild } from '@angular/core';
import { animate, state, style, transition, trigger } from '@angular/animations';
import { Keymap, Macro } from 'uhk-common';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/let';
import { AppState, getDeviceName, showAddonMenu, runningInElectron } from '../../store';
import { AppState, getDeviceName, runningInElectron, showAddonMenu, updatingFirmware } from '../../store';
import { MacroActions } from '../../store/actions';
import { getKeymaps, getMacros } from '../../store/reducers/user-configuration';
import * as util from '../../util';
@@ -31,15 +32,19 @@ import { RenameUserConfigurationAction } from '../../store/actions/user-config';
templateUrl: './side-menu.component.html',
styleUrls: ['./side-menu.component.scss']
})
export class SideMenuComponent implements AfterContentInit {
export class SideMenuComponent implements AfterContentInit, OnDestroy {
showAddonMenu$: Observable<boolean>;
runInElectron$: Observable<boolean>;
updatingFirmware$: Observable<boolean>;
deviceName$: Observable<string>;
deviceNameSubscription: Subscription;
keymaps$: Observable<Keymap[]>;
macros$: Observable<Macro[]>;
animation: { [key: string]: 'active' | 'inactive' };
deviceNameValue: string;
updatingFirmware = false;
updatingFirmwareSubscription: Subscription;
@ViewChild('deviceName') deviceName: ElementRef;
constructor(private store: Store<AppState>, private renderer: Renderer2) {
@@ -66,17 +71,30 @@ export class SideMenuComponent implements AfterContentInit {
this.showAddonMenu$ = this.store.select(showAddonMenu);
this.runInElectron$ = this.store.select(runningInElectron);
this.deviceName$ = store.select(getDeviceName);
this.deviceName$.subscribe(name => {
this.deviceNameSubscription = this.deviceName$.subscribe(name => {
this.deviceNameValue = name;
this.setDeviceName();
});
this.updatingFirmware$ = store.select(updatingFirmware);
this.updatingFirmwareSubscription = this.updatingFirmware$.subscribe(updating => {
this.updatingFirmware = updating;
});
}
ngAfterContentInit(): void {
this.setDeviceName();
}
ngOnDestroy(): void {
this.deviceNameSubscription.unsubscribe();
this.updatingFirmwareSubscription.unsubscribe();
}
toggleHide(event: Event, type: string) {
if (this.updatingFirmware) {
return;
}
const header: DOMTokenList = (<Element>event.target).classList;
let show = false;

View File

@@ -0,0 +1,5 @@
<div class="wrapper">
<ul class="list-unstyled">
<li *ngFor="let log of logs" [ngClass]="log.cssClass"><span>{{ log.message }}</span></li>
</ul>
</div>

View File

@@ -0,0 +1,24 @@
:host {
background-color: yellow;
}
.wrapper {
background-color: black;
}
.xterm-standard {
color: white;
}
.xterm-error {
color: red;
}
ul {
li {
padding-left: 5px;
span:before {
content: '$ ';
}
}
}

View File

@@ -0,0 +1,12 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { XtermLog } from '../../models/xterm-log';
@Component({
selector: 'xterm',
templateUrl: './xterm.component.html',
styleUrls: ['./xterm.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class XtermComponent {
@Input() logs: Array<XtermLog> = [];
}

View File

@@ -0,0 +1,14 @@
export interface XtermLog {
message: string;
cssClass: XtermCssClass;
}
export enum XtermCssClass {
standard = 'xterm-standard',
error = 'xterm-error'
}
export interface ElectronLogEntry {
level: string;
message: string;
}

View File

@@ -2,7 +2,8 @@ import { Component } from '@angular/core';
@Component({
selector: 'main-page',
templateUrl: './main.page.html'
templateUrl: './main.page.html',
styles: [':host{height:100%; display: inline-block; width: 100%}']
})
export class MainPage {

View File

@@ -1,9 +1,9 @@
import { Injectable, NgZone } from '@angular/core';
import { Action, Store } from '@ngrx/store';
import { IpcEvents, AppStartInfo, LogService } from 'uhk-common';
import { AppState } from '../store/index';
import { ProcessAppStartInfoAction } from '../store/actions/app';
import { AppStartInfo, IpcEvents, LogService } from 'uhk-common';
import { AppState } from '../store';
import { ElectronMainLogReceivedAction, ProcessAppStartInfoAction } from '../store/actions/app';
import { IpcCommonRenderer } from './ipc-common-renderer';
@Injectable()
@@ -25,6 +25,10 @@ export class AppRendererService {
this.ipcRenderer.on(IpcEvents.app.getAppStartInfoReply, (event: string, arg: AppStartInfo) => {
this.dispachStoreAction(new ProcessAppStartInfoAction(arg));
});
this.ipcRenderer.on('__ELECTRON_LOG_RENDERER__', (event: string, level: string, message: string) => {
this.zone.run(() => this.store.dispatch(new ElectronMainLogReceivedAction({level, message})));
});
}
private dispachStoreAction(action: Action) {

View File

@@ -1,13 +1,14 @@
import { Injectable, NgZone } from '@angular/core';
import { Action, Store } from '@ngrx/store';
import { IpcEvents, LogService, IpcResponse } from 'uhk-common';
import { AppState } from '../store/index';
import { IpcEvents, IpcResponse, LogService } from 'uhk-common';
import { AppState } from '../store';
import { IpcCommonRenderer } from './ipc-common-renderer';
import {
ConnectionStateChangedAction,
SaveConfigurationReplyAction,
SetPrivilegeOnLinuxReplyAction
SetPrivilegeOnLinuxReplyAction,
UpdateFirmwareReplyAction
} from '../store/actions/device';
import { LoadConfigFromDeviceReplyAction } from '../store/actions/user-config';
@@ -33,6 +34,14 @@ export class DeviceRendererService {
this.ipcRenderer.send(IpcEvents.device.loadConfigurations);
}
updateFirmware(data?: Array<number>): void {
this.ipcRenderer.send(IpcEvents.device.updateFirmware, JSON.stringify(data));
}
startConnectionPoller(): void {
this.ipcRenderer.send(IpcEvents.device.startConnectionPoller);
}
private registerEvents(): void {
this.ipcRenderer.on(IpcEvents.device.deviceConnectionStateChanged, (event: string, arg: boolean) => {
this.dispachStoreAction(new ConnectionStateChangedAction(arg));
@@ -49,10 +58,14 @@ export class DeviceRendererService {
this.ipcRenderer.on(IpcEvents.device.loadConfigurationReply, (event: string, response: string) => {
this.dispachStoreAction(new LoadConfigFromDeviceReplyAction(JSON.parse(response)));
});
this.ipcRenderer.on(IpcEvents.device.updateFirmwareReply, (event: string, response: IpcResponse) => {
this.dispachStoreAction(new UpdateFirmwareReplyAction(response));
});
}
private dispachStoreAction(action: Action): void {
this.logService.info('[DeviceRendererService] dispatch action', action);
this.logService.info('[DeviceRendererService] dispatch action', JSON.stringify(action));
this.zone.run(() => this.store.dispatch(action));
}
}

View File

@@ -97,6 +97,7 @@ import { MainAppComponent } from './app.component';
import { LoadingDevicePageComponent } from './pages/loading-page/loading-device.page';
import { UhkDeviceLoadingGuard } from './services/uhk-device-loading.guard';
import { UhkDeviceLoadedGuard } from './services/uhk-device-loaded.guard';
import { XtermComponent } from './components/xterm/xterm.component';
@NgModule({
declarations: [
@@ -161,7 +162,8 @@ import { UhkDeviceLoadedGuard } from './services/uhk-device-loaded.guard';
PrivilegeCheckerComponent,
MainPage,
ProgressButtonComponent,
LoadingDevicePageComponent
LoadingDevicePageComponent,
XtermComponent
],
imports: [
CommonModule,

View File

@@ -1,7 +1,7 @@
import { Action } from '@ngrx/store';
import { type } from 'uhk-common';
import { AppStartInfo, HardwareConfiguration, Notification } from 'uhk-common';
import { AppStartInfo, HardwareConfiguration, Notification, type, VersionInformation } from 'uhk-common';
import { ElectronLogEntry } from '../../models/xterm-log';
const PREFIX = '[app] ';
@@ -15,7 +15,9 @@ export const ActionTypes = {
UNDO_LAST: type(PREFIX + 'undo last action'),
UNDO_LAST_SUCCESS: type(PREFIX + 'undo last action success'),
DISMISS_UNDO_NOTIFICATION: type(PREFIX + 'dismiss notification action'),
LOAD_HARDWARE_CONFIGURATION_SUCCESS: type(PREFIX + 'load hardware configuration success')
LOAD_HARDWARE_CONFIGURATION_SUCCESS: type(PREFIX + 'load hardware configuration success'),
UPDATE_AGENT_VERSION_INFORMATION: type(PREFIX + 'update agent version information'),
ELECTRON_MAIN_LOG_RECEIVED: type(PREFIX + 'Electron main log received')
};
export class AppBootsrappedAction implements Action {
@@ -64,6 +66,18 @@ export class LoadHardwareConfigurationSuccessAction implements Action {
constructor(public payload: HardwareConfiguration) {}
}
export class UpdateAgentVersionInformationAction implements Action {
type = ActionTypes.UPDATE_AGENT_VERSION_INFORMATION;
constructor(public payload: VersionInformation) {}
}
export class ElectronMainLogReceivedAction implements Action {
type = ActionTypes.ELECTRON_MAIN_LOG_RECEIVED;
constructor(public payload: ElectronLogEntry) {}
}
export type Actions
= AppStartedAction
| AppBootsrappedAction
@@ -74,4 +88,6 @@ export type Actions
| UndoLastSuccessAction
| DismissUndoNotificationAction
| LoadHardwareConfigurationSuccessAction
| UpdateAgentVersionInformationAction
| ElectronMainLogReceivedAction
;

View File

@@ -1,5 +1,5 @@
import { Action } from '@ngrx/store';
import { type, IpcResponse } from 'uhk-common';
import { IpcResponse, type } from 'uhk-common';
const PREFIX = '[device] ';
@@ -16,7 +16,13 @@ export const ActionTypes = {
SAVE_TO_KEYBOARD_SUCCESS: type(PREFIX + 'save to keyboard success'),
SAVE_TO_KEYBOARD_FAILED: type(PREFIX + 'save to keyboard failed'),
HIDE_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'hide save to keyboard button'),
RESET_USER_CONFIGURATION: type(PREFIX + 'reset user configuration')
RESET_USER_CONFIGURATION: type(PREFIX + 'reset user configuration'),
UPDATE_FIRMWARE: type(PREFIX + 'update firmware'),
UPDATE_FIRMWARE_WITH: type(PREFIX + 'update firmware with'),
UPDATE_FIRMWARE_REPLY: type(PREFIX + 'update firmware reply'),
UPDATE_FIRMWARE_SUCCESS: type(PREFIX + 'update firmware success'),
UPDATE_FIRMWARE_FAILED: type(PREFIX + 'update firmware failed'),
UPDATE_FIRMWARE_OK_BUTTON: type(PREFIX + 'update firmware ok button click')
};
export class SetPrivilegeOnLinuxAction implements Action {
@@ -26,31 +32,36 @@ export class SetPrivilegeOnLinuxAction implements Action {
export class SetPrivilegeOnLinuxReplyAction implements Action {
type = ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY;
constructor(public payload: IpcResponse) {}
constructor(public payload: IpcResponse) {
}
}
export class ConnectionStateChangedAction implements Action {
type = ActionTypes.CONNECTION_STATE_CHANGED;
constructor(public payload: boolean) {}
constructor(public payload: boolean) {
}
}
export class PermissionStateChangedAction implements Action {
type = ActionTypes.PERMISSION_STATE_CHANGED;
constructor(public payload: boolean) {}
constructor(public payload: boolean) {
}
}
export class SaveConfigurationAction implements Action {
type = ActionTypes.SAVE_CONFIGURATION;
constructor() {}
constructor() {
}
}
export class SaveConfigurationReplyAction implements Action {
type = ActionTypes.SAVE_CONFIGURATION_REPLY;
constructor(public payload: IpcResponse) {}
constructor(public payload: IpcResponse) {
}
}
export class ShowSaveToKeyboardButtonAction implements Action {
@@ -73,6 +84,39 @@ export class ResetUserConfigurationAction implements Action {
type = ActionTypes.RESET_USER_CONFIGURATION;
}
export class UpdateFirmwareAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE;
}
export class UpdateFirmwareWithAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_WITH;
constructor(public payload: Array<number>) {
}
}
export class UpdateFirmwareReplyAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_REPLY;
constructor(public payload: IpcResponse) {
}
}
export class UpdateFirmwareSuccessAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_SUCCESS;
}
export class UpdateFirmwareFailedAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_FAILED;
constructor(public payload: any) {
}
}
export class UpdateFirmwareOkButtonAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_OK_BUTTON;
}
export type Actions
= SetPrivilegeOnLinuxAction
| SetPrivilegeOnLinuxReplyAction
@@ -85,4 +129,10 @@ export type Actions
| SaveToKeyboardSuccessFailed
| HideSaveToKeyboardButton
| ResetUserConfigurationAction
| UpdateFirmwareAction
| UpdateFirmwareWithAction
| UpdateFirmwareReplyAction
| UpdateFirmwareSuccessAction
| UpdateFirmwareFailedAction
| UpdateFirmwareOkButtonAction
;

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Action } from '@ngrx/store';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Actions, Effect } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import { NotifierService } from 'angular-notifier';
@@ -10,8 +10,16 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/catch';
import { AppStartInfo, Notification, NotificationType, LogService } from 'uhk-common';
import { ActionTypes, AppStartedAction, DismissUndoNotificationAction, ToggleAddonMenuAction } from '../actions/app';
import { AppStartInfo, LogService, Notification, NotificationType } from 'uhk-common';
import {
ActionTypes,
AppStartedAction,
DismissUndoNotificationAction,
ProcessAppStartInfoAction,
ShowNotificationAction,
ToggleAddonMenuAction,
UndoLastAction, UpdateAgentVersionInformationAction
} from '../actions/app';
import { AppRendererService } from '../../services/app-renderer.service';
import { AppUpdateRendererService } from '../../services/app-update-renderer.service';
import { ConnectionStateChangedAction, PermissionStateChangedAction } from '../actions/device';
@@ -32,8 +40,8 @@ export class ApplicationEffects {
@Effect({dispatch: false})
showNotification$: Observable<Action> = this.actions$
.ofType(ActionTypes.APP_SHOW_NOTIFICATION)
.map(toPayload)
.ofType<ShowNotificationAction>(ActionTypes.APP_SHOW_NOTIFICATION)
.map(action => action.payload)
.do((notification: Notification) => {
if (notification.type === NotificationType.Undoable) {
return;
@@ -43,25 +51,27 @@ export class ApplicationEffects {
@Effect()
processStartInfo$: Observable<Action> = this.actions$
.ofType(ActionTypes.APP_PROCESS_START_INFO)
.map(toPayload)
.ofType<ProcessAppStartInfoAction>(ActionTypes.APP_PROCESS_START_INFO)
.map(action => action.payload)
.mergeMap((appInfo: AppStartInfo) => {
this.logService.debug('[AppEffect][processStartInfo] payload:', appInfo);
return [
new ToggleAddonMenuAction(appInfo.commandLineArgs.addons),
new ConnectionStateChangedAction(appInfo.deviceConnected),
new PermissionStateChangedAction(appInfo.hasPermission)
new PermissionStateChangedAction(appInfo.hasPermission),
new UpdateAgentVersionInformationAction(appInfo.agentVersionInfo)
];
});
@Effect() undoLastNotification$: Observable<Action> = this.actions$
.ofType(ActionTypes.UNDO_LAST)
.map(toPayload)
.ofType<UndoLastAction>(ActionTypes.UNDO_LAST)
.map(action => action.payload)
.mergeMap((action: Action) => [action, new DismissUndoNotificationAction()]);
constructor(private actions$: Actions,
private notifierService: NotifierService,
private appUpdateRendererService: AppUpdateRendererService,
private appRendererService: AppRendererService,
private logService: LogService) { }
private logService: LogService) {
}
}

View File

@@ -13,7 +13,7 @@ import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/operator/switchMap';
import { NotificationType, IpcResponse, UhkBuffer, UserConfiguration } from 'uhk-common';
import { IpcResponse, NotificationType, UhkBuffer, UserConfiguration } from 'uhk-common';
import {
ActionTypes,
ConnectionStateChangedAction,
@@ -21,15 +21,22 @@ import {
PermissionStateChangedAction,
SaveConfigurationAction,
SaveToKeyboardSuccessAction,
SaveToKeyboardSuccessFailed
SaveToKeyboardSuccessFailed,
SetPrivilegeOnLinuxReplyAction,
UpdateFirmwareAction,
UpdateFirmwareFailedAction,
UpdateFirmwareOkButtonAction,
UpdateFirmwareReplyAction,
UpdateFirmwareSuccessAction,
UpdateFirmwareWithAction
} from '../actions/device';
import { DeviceRendererService } from '../../services/device-renderer.service';
import { ShowNotificationAction } from '../actions/app';
import { AppState } from '../index';
import {
ActionTypes as UserConfigActions,
LoadConfigFromDeviceAction,
LoadResetUserConfigurationAction,
ActionTypes as UserConfigActions
LoadResetUserConfigurationAction
} from '../actions/user-config';
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
@@ -37,8 +44,8 @@ import { DefaultUserConfigurationService } from '../../services/default-user-con
export class DeviceEffects {
@Effect()
deviceConnectionStateChange$: Observable<Action> = this.actions$
.ofType(ActionTypes.CONNECTION_STATE_CHANGED)
.map(toPayload)
.ofType<ConnectionStateChangedAction>(ActionTypes.CONNECTION_STATE_CHANGED)
.map(action => action.payload)
.do((connected: boolean) => {
if (connected) {
this.router.navigate(['/']);
@@ -56,9 +63,9 @@ export class DeviceEffects {
});
@Effect({dispatch: false})
permissionStateChange$: Observable<Action> = this.actions$
.ofType(ActionTypes.PERMISSION_STATE_CHANGED)
.map(toPayload)
permissionStateChange$: Observable<boolean> = this.actions$
.ofType<PermissionStateChangedAction>(ActionTypes.PERMISSION_STATE_CHANGED)
.map(action => action.payload)
.do((hasPermission: boolean) => {
if (hasPermission) {
this.router.navigate(['/detection']);
@@ -77,8 +84,8 @@ export class DeviceEffects {
@Effect()
setPrivilegeOnLinuxReply$: Observable<Action> = this.actions$
.ofType(ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY)
.map(toPayload)
.ofType<SetPrivilegeOnLinuxReplyAction>(ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY)
.map(action => action.payload)
.mergeMap((response: any) => {
if (response.success) {
return [
@@ -142,6 +149,30 @@ export class DeviceEffects {
.ofType(UserConfigActions.LOAD_RESET_USER_CONFIGURATION)
.switchMap(() => Observable.of(new SaveConfigurationAction()));
@Effect({dispatch: false}) updateFirmware$ = this.actions$
.ofType<UpdateFirmwareAction>(ActionTypes.UPDATE_FIRMWARE)
.do(() => this.deviceRendererService.updateFirmware());
@Effect({dispatch: false}) updateFirmwareWith$ = this.actions$
.ofType<UpdateFirmwareWithAction>(ActionTypes.UPDATE_FIRMWARE_WITH)
.map(action => action.payload)
.do(data => this.deviceRendererService.updateFirmware(data));
@Effect() updateFirmwareReply$ = this.actions$
.ofType<UpdateFirmwareReplyAction>(ActionTypes.UPDATE_FIRMWARE_REPLY)
.map(action => action.payload)
.switchMap((response: IpcResponse) => {
if (response.success) {
return Observable.of(new UpdateFirmwareSuccessAction());
}
return Observable.of(new UpdateFirmwareFailedAction(response.error));
});
@Effect({dispatch: false}) updateFirmwareOkButton$ = this.actions$
.ofType<UpdateFirmwareOkButtonAction>(ActionTypes.UPDATE_FIRMWARE_OK_BUTTON)
.do(() => this.deviceRendererService.startConnectionPoller());
constructor(private actions$: Actions,
private router: Router,
private deviceRendererService: DeviceRendererService,

View File

@@ -49,6 +49,7 @@ export const runningInElectron = createSelector(appState, fromApp.runningInElect
export const getHardwareConfiguration = createSelector(appState, fromApp.getHardwareConfiguration);
export const getKeyboardLayout = createSelector(appState, fromApp.getKeyboardLayout);
export const deviceConfigurationLoaded = createSelector(appState, fromApp.deviceConfigurationLoaded);
export const getAgentVersionInfo = createSelector(appState, fromApp.getAgentVersionInfo);
export const appUpdateState = (state: AppState) => state.appUpdate;
export const getShowAppUpdateAvailable = createSelector(appUpdateState, fromAppUpdate.getShowAppUpdateAvailable);
@@ -70,3 +71,8 @@ export const saveToKeyboardStateSelector = createSelector(deviceState, fromDevic
export const saveToKeyboardState = createSelector(runningInElectron, saveToKeyboardStateSelector, (electron, state) => {
return electron ? state : initProgressButtonState;
});
export const updatingFirmware = createSelector(deviceState, fromDevice.updatingFirmware);
export const xtermLog = createSelector(deviceState, fromDevice.xtermLog);
export const firmwareOkButtonDisabled = createSelector(deviceState, fromDevice.firmwareOkButtonDisabled);
// tslint:disable-next-line: max-line-length
export const flashFirmwareButtonDisbabled = createSelector(runningInElectron, deviceState, (electron, state: fromDevice.State) => !electron || state.updatingFirmware);

View File

@@ -1,7 +1,8 @@
import { ROUTER_NAVIGATION } from '@ngrx/router-store';
import { Action } from '@ngrx/store';
import { VersionInformation } from 'uhk-common';
import { HardwareConfiguration, runInElectron, Notification, NotificationType, UserConfiguration } from 'uhk-common';
import { HardwareConfiguration, Notification, NotificationType, runInElectron, UserConfiguration } from 'uhk-common';
import { ActionTypes, ShowNotificationAction } from '../actions/app';
import { ActionTypes as UserConfigActionTypes } from '../actions/user-config';
import { ActionTypes as DeviceActionTypes } from '../actions/device';
@@ -16,6 +17,7 @@ export interface State {
runningInElectron: boolean;
configLoading: boolean;
hardwareConfig?: HardwareConfiguration;
agentVersionInfo?: VersionInformation;
}
export const initialState: State = {
@@ -99,7 +101,7 @@ export function reducer(state = initialState, action: Action & { payload: any })
hardwareConfig: action.payload
};
case DeviceActionTypes.CONNECTION_STATE_CHANGED:
case DeviceActionTypes.CONNECTION_STATE_CHANGED: {
if (action.payload === true) {
return state;
@@ -109,7 +111,13 @@ export function reducer(state = initialState, action: Action & { payload: any })
...state,
hardwareConfig: null
};
}
case ActionTypes.UPDATE_AGENT_VERSION_INFORMATION:
return {
...state,
agentVersionInfo: action.payload
};
default:
return state;
}
@@ -128,3 +136,4 @@ export const getKeyboardLayout = (state: State): KeyboardLayout => {
return KeyboardLayout.ANSI;
};
export const deviceConfigurationLoaded = (state: State) => !state.runningInElectron ? true : !!state.hardwareConfig;
export const getAgentVersionInfo = (state: State) => state.agentVersionInfo || {} as VersionInformation;

View File

@@ -1,21 +1,31 @@
import { Action } from '@ngrx/store';
import {
ActionTypes, ConnectionStateChangedAction, HideSaveToKeyboardButton, PermissionStateChangedAction,
SaveConfigurationAction
ActionTypes,
ConnectionStateChangedAction,
PermissionStateChangedAction,
SaveConfigurationAction, UpdateFirmwareFailedAction
} from '../actions/device';
import { ActionTypes as AppActions, ElectronMainLogReceivedAction } from '../actions/app';
import { initProgressButtonState, ProgressButtonState } from './progress-button-state';
import { XtermCssClass, XtermLog } from '../../models/xterm-log';
export interface State {
connected: boolean;
hasPermission: boolean;
saveToKeyboard: ProgressButtonState;
updatingFirmware: boolean;
firmwareUpdateFinished: boolean;
log: Array<XtermLog>;
}
export const initialState: State = {
connected: true,
hasPermission: true,
saveToKeyboard: initProgressButtonState
saveToKeyboard: initProgressButtonState,
updatingFirmware: false,
firmwareUpdateFinished: false,
log: [{message: '', cssClass: XtermCssClass.standard}]
};
export function reducer(state = initialState, action: Action) {
@@ -89,11 +99,66 @@ export function reducer(state = initialState, action: Action) {
saveToKeyboard: initProgressButtonState
};
}
case ActionTypes.UPDATE_FIRMWARE_WITH:
case ActionTypes.UPDATE_FIRMWARE:
return {
...state,
updatingFirmware: true,
firmwareUpdateFinished: false,
log: [{message: 'Start flashing firmware', cssClass: XtermCssClass.standard}]
};
case ActionTypes.UPDATE_FIRMWARE_SUCCESS:
return {
...state,
updatingFirmware: false,
firmwareUpdateFinished: true
};
case ActionTypes.UPDATE_FIRMWARE_FAILED: {
const logEntry = {
message: (action as UpdateFirmwareFailedAction).payload.message,
cssClass: XtermCssClass.error
};
return {
...state,
updatingFirmware: false,
firmwareUpdateFinished: true,
log: [...state.log, logEntry]
};
}
case AppActions.ELECTRON_MAIN_LOG_RECEIVED: {
if (!state.updatingFirmware) {
return state;
}
const payload = (action as ElectronMainLogReceivedAction).payload;
if (payload.message.indexOf('UHK Device not found:') > -1) {
return state;
}
const logEntry = {
message: payload.message,
cssClass: payload.level === 'error' ? XtermCssClass.error : XtermCssClass.standard
};
return {
...state,
log: [...state.log, logEntry]
};
}
default:
return state;
}
}
export const isDeviceConnected = (state: State) => state.connected;
export const updatingFirmware = (state: State) => state.updatingFirmware;
export const isDeviceConnected = (state: State) => state.connected || state.updatingFirmware;
export const hasDevicePermission = (state: State) => state.hasPermission;
export const getSaveToKeyboardState = (state: State) => state.saveToKeyboard;
export const xtermLog = (state: State) => state.log;
export const firmwareOkButtonDisabled = (state: State) => !state.firmwareUpdateFinished;

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import * as log from 'electron-log';
import * as util from 'util';
import { LogService, LogRegExps } from 'uhk-common';
import { LogRegExps, LogService } from 'uhk-common';
// https://github.com/megahertz/electron-log/issues/44
// console.debug starting with Chromium 58 this method is a no-op on Chromium browsers.
@@ -13,7 +13,7 @@ if (console.debug) {
console.log('%c' + args[0], 'color:green');
} else if (LogRegExps.errorRegExp.test(args[0])) {
console.log('%c' + args[0], 'color:red');
}else if (LogRegExps.transferRegExp.test(args[0])) {
} else if (LogRegExps.transferRegExp.test(args[0])) {
console.log('%c' + args[0], 'color:orange');
} else {
console.log(...args);

View File

@@ -4,8 +4,7 @@ import { LogService } from 'uhk-common';
import { ElectronDataStorageRepositoryService } from './services/electron-datastorage-repository.service';
import { ElectronLogService } from './services/electron-log.service';
import { ElectronErrorHandlerService } from './services/electron-error-handler.service';
import { routing } from '../../';
import { MainAppComponent } from '../../';
import { MainAppComponent, routing } from '../../';
import { IpcUhkRenderer } from './services/ipc-uhk-renderer';
import { IpcCommonRenderer } from '../app/services/ipc-common-renderer';
import { DataStorageRepositoryService } from '../app/services/datastorage-repository.service';

View File

@@ -5,6 +5,11 @@
@import './styles/tooltip';
@import './styles/uhk-icons/uhk-icon';
html, body {
width: 100%;
height: 100%;
}
.uhk-icon {
display: inline-block;
width: 1em;
@@ -30,6 +35,7 @@
.main-page-content {
margin-left: 250px;
overflow-x: hidden;
height: 99%;
}
.select2 {
@@ -69,3 +75,18 @@ ul.btn-list {
.h1, .h2, .h3, h1, h2, h3 {
margin-top: 10px;
}
input[type=file] {
display: inline-block;
}
a.disabled {
pointer-events: none;
cursor: default;
}
.full-height {
height: 100%;
width: 100%;
display: inline-block;
}