refactore: create feature modules (#387)

* add @angular/cli to the project

* increase nodejs version -> 8.2.1

* add lerna

* merge web and shared module

* move electron module into packages as uhk-agent

Electron agent functionality is not working

* delete symlinker

* convert private properties to public of component if used in html

* revert uhk-message.component

* fix component path

* fix the correct name of the uhk-message.component.scss

* building web and electron module

* delete uhk-renderer package

* handle device connect disconnect state

* add privilege detection

* fix set privilege functionality

* turn back download keymap functionality

* add bootstrap, select2 js and fix null pointer exception

* turn back upload data to keyboard

* fix send keymap

* fix test-serializer

* add missing package.json

* merging

* fix appveyor build

* fix linting

* turn back electron storage service

* commit the missing electron-datastorage-repository

* update node to 8.3.0 in .nvmrc and log node version in appveyor build

* set exact version number in appveyor build

* vertical align privilege and missing device components

* set back node version to 8 in appveyor

* move node-usb dependency from usb dir to root

maybe it is fix the appveyor build

* revert usb to root

* fix electron builder script

* fix electron builder script

* turn off electron devtools

* remove CTRL+U functionality

* fix CTRL+o

* fix lint error

* turnoff store freeze

* start process when got `Error: EPERM: operation not permitted` error

* move files from root usb dir -> packages/usb
This commit is contained in:
Róbert Kiss
2017-08-19 20:02:17 +02:00
committed by László Monda
parent 97770f67c0
commit 0f558e4132
524 changed files with 25606 additions and 5036 deletions

View File

@@ -0,0 +1,34 @@
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 { IpcCommonRenderer } from './ipc-common-renderer';
@Injectable()
export class AppRendererService {
constructor(private store: Store<AppState>,
private zone: NgZone,
private ipcRenderer: IpcCommonRenderer,
private logService: LogService) {
this.registerEvents();
this.logService.info('[AppRendererService] init success ');
}
getAppStartInfo() {
this.logService.info('[AppRendererService] getAppStartInfo');
this.ipcRenderer.send(IpcEvents.app.getAppStartInfo);
}
private registerEvents() {
this.ipcRenderer.on(IpcEvents.app.getAppStartInfoReply, (event: string, arg: AppStartInfo) => {
this.dispachStoreAction(new ProcessAppStartInfoAction(arg));
});
}
private dispachStoreAction(action: Action) {
this.logService.info('[AppRendererService] dispatch action', action);
this.zone.run(() => this.store.dispatch(action));
}
}

View File

@@ -0,0 +1,76 @@
import { Injectable, NgZone } from '@angular/core';
import { Action, Store } from '@ngrx/store';
import { IpcEvents } from 'uhk-common';
import { AppState } from '../store/index';
import { UpdateDownloadedAction, UpdateErrorAction } from '../store/actions/app-update.action';
import { CheckForUpdateFailedAction, CheckForUpdateSuccessAction } from '../store/actions/auto-update-settings';
import { IpcCommonRenderer } from './ipc-common-renderer';
/**
* This service handle the application update events in the electron renderer process.
*
* The class contains parameters with 'any' type, because the relevant type definitions in
* import { ProgressInfo } from 'electron-builder-http/out/ProgressCallbackTransform';
* import { VersionInfo } from 'electron-builder-http/out/publishOptions';
* but, typescript allow import these if import 'electron-updater' too, but I i don't want to import
* the updater in renderer process.
*/
@Injectable()
export class AppUpdateRendererService {
constructor(private store: Store<AppState>,
private zone: NgZone,
private ipcRenderer: IpcCommonRenderer) {
this.registerEvents();
}
sendAppStarted() {
this.ipcRenderer.send(IpcEvents.app.appStarted);
}
sendUpdateAndRestartApp() {
this.ipcRenderer.send(IpcEvents.autoUpdater.updateAndRestart);
}
checkForUpdate() {
this.ipcRenderer.send(IpcEvents.autoUpdater.checkForUpdate);
}
private registerEvents() {
this.ipcRenderer.on(IpcEvents.autoUpdater.updateAvailable, (event: string, arg: any) => {
this.writeUpdateState(IpcEvents.autoUpdater.updateAvailable, arg);
});
this.ipcRenderer.on(IpcEvents.autoUpdater.updateNotAvailable, () => {
this.writeUpdateState(IpcEvents.autoUpdater.updateNotAvailable);
this.dispachStoreAction(new CheckForUpdateSuccessAction('No update available'));
});
this.ipcRenderer.on(IpcEvents.autoUpdater.autoUpdateError, (event: string, arg: any) => {
this.writeUpdateState(IpcEvents.autoUpdater.autoUpdateError, arg);
this.dispachStoreAction(new UpdateErrorAction(arg));
});
this.ipcRenderer.on(IpcEvents.autoUpdater.autoUpdateDownloadProgress, (event: string, arg: any) => {
this.writeUpdateState(IpcEvents.autoUpdater.autoUpdateDownloadProgress, arg);
});
this.ipcRenderer.on(IpcEvents.autoUpdater.autoUpdateDownloaded, (event: string, arg: any) => {
this.writeUpdateState(IpcEvents.autoUpdater.autoUpdateDownloaded, arg);
this.dispachStoreAction(new UpdateDownloadedAction());
});
this.ipcRenderer.on(IpcEvents.autoUpdater.checkForUpdateNotAvailable, (event: string, arg: any) => {
this.writeUpdateState(IpcEvents.autoUpdater.checkForUpdateNotAvailable, arg);
this.dispachStoreAction(new CheckForUpdateFailedAction(arg));
});
}
private dispachStoreAction(action: Action) {
this.zone.run(() => this.store.dispatch(action));
}
private writeUpdateState(event: any, arg?: any) {
console.log({ event, arg });
}
}

View File

@@ -0,0 +1,143 @@
import { Injectable } from '@angular/core';
@Injectable()
export class CaptureService {
private mapping: Map<number, number>;
private leftModifiers: Map<number, boolean>;
private rightModifiers: Map<number, boolean>;
constructor() {
this.leftModifiers = new Map<number, boolean>();
this.rightModifiers = new Map<number, boolean>();
this.mapping = new Map<number, number>();
}
public getMap(code: number) {
return this.mapping.get(code);
}
public hasMap(code: number) {
return this.mapping.has(code);
}
public setModifier(left: boolean, code: number) {
return left ? this.leftModifiers.set(code, true) : this.rightModifiers.set(code, true);
}
public getModifiers(left: boolean) {
return left ? this.reMap(this.leftModifiers) : this.reMap(this.rightModifiers);
}
public initModifiers() {
this.leftModifiers.set(16, false); // Shift
this.leftModifiers.set(17, false); // Ctrl
this.leftModifiers.set(18, false); // Alt
this.leftModifiers.set(91, false); // Super
this.rightModifiers.set(16, false); // Shift
this.rightModifiers.set(17, false); // Ctrl
this.rightModifiers.set(18, false); // Alt
this.rightModifiers.set(91, false); // Super
}
public populateMapping () {
this.mapping.set(8, 42); // Backspace
this.mapping.set(9, 43); // Tab
this.mapping.set(13, 40); // Enter
this.mapping.set(19, 72); // Pause/break
this.mapping.set(20, 57); // Caps lock
this.mapping.set(27, 41); // Escape
this.mapping.set(32, 44); // (space)
this.mapping.set(33, 75); // Page up
this.mapping.set(34, 78); // Page down
this.mapping.set(35, 77); // End
this.mapping.set(36, 74); // Home
this.mapping.set(37, 80); // Left arrow
this.mapping.set(38, 82); // Up arrow
this.mapping.set(39, 79); // Right arrow
this.mapping.set(40, 81); // Down arrow
this.mapping.set(45, 73); // Insert
this.mapping.set(46, 76); // Delete
this.mapping.set(48, 39); // 0
this.mapping.set(49, 30); // 1
this.mapping.set(50, 31); // 2
this.mapping.set(51, 32); // 3
this.mapping.set(52, 33); // 4
this.mapping.set(53, 34); // 5
this.mapping.set(54, 35); // 6
this.mapping.set(55, 36); // 7
this.mapping.set(56, 37); // 8
this.mapping.set(57, 38); // 9
this.mapping.set(65, 4); // A
this.mapping.set(66, 5); // B
this.mapping.set(67, 6); // C
this.mapping.set(68, 7); // D
this.mapping.set(69, 8); // E
this.mapping.set(70, 9); // F
this.mapping.set(71, 10); // G
this.mapping.set(72, 11); // H
this.mapping.set(73, 12); // I
this.mapping.set(74, 13); // J
this.mapping.set(75, 14); // K
this.mapping.set(76, 15); // L
this.mapping.set(77, 16); // M
this.mapping.set(78, 17); // N
this.mapping.set(79, 18); // O
this.mapping.set(80, 19); // P
this.mapping.set(81, 20); // Q
this.mapping.set(82, 21); // R
this.mapping.set(83, 22); // S
this.mapping.set(84, 23); // T
this.mapping.set(85, 24); // U
this.mapping.set(86, 25); // V
this.mapping.set(87, 26); // W
this.mapping.set(88, 27); // X
this.mapping.set(89, 28); // Y
this.mapping.set(90, 29); // Z
this.mapping.set(93, 118); // Menu
this.mapping.set(96, 98); // Num pad 0
this.mapping.set(97, 89); // Num pad 1
this.mapping.set(98, 90); // Num pad 2
this.mapping.set(99, 91); // Num pad 3
this.mapping.set(100, 92); // Num pad 4
this.mapping.set(101, 93); // Num pad 5
this.mapping.set(102, 94); // Num pad 6
this.mapping.set(103, 95); // Num pad 7
this.mapping.set(104, 96); // Num pad 8
this.mapping.set(105, 97); // Num pad 9
this.mapping.set(106, 85); // Multiply
this.mapping.set(107, 87); // Add
this.mapping.set(109, 86); // Subtract
this.mapping.set(110, 99); // Decimal point
this.mapping.set(111, 84); // Divide
this.mapping.set(112, 58); // F1
this.mapping.set(113, 59); // F2
this.mapping.set(114, 60); // F3
this.mapping.set(115, 61); // F4
this.mapping.set(116, 62); // F5
this.mapping.set(117, 63); // F6
this.mapping.set(118, 64); // F7
this.mapping.set(119, 65); // F8
this.mapping.set(120, 66); // F9
this.mapping.set(121, 67); // F10
this.mapping.set(122, 68); // F11
this.mapping.set(123, 69); // F12
this.mapping.set(144, 83); // Num lock
this.mapping.set(145, 71); // Scroll lock
this.mapping.set(186, 51); // Semi-colon
this.mapping.set(187, 46); // Equal sign
this.mapping.set(188, 54); // Comma
this.mapping.set(189, 45); // Dash
this.mapping.set(190, 55); // Period
this.mapping.set(191, 56); // Forward slash
this.mapping.set(192, 53); // Grave accent
this.mapping.set(219, 47); // Open bracket
this.mapping.set(220, 49); // Back slash
this.mapping.set(221, 48); // Close bracket
this.mapping.set(222, 52); // Single quote
}
private reMap(value: Map<number, boolean>): boolean[] {
return [value.get(16), value.get(17), value.get(91), value.get(18)];
}
}

View File

@@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';
import { UserConfiguration } from '../config-serializer/config-items/user-configuration';
import { AutoUpdateSettings } from '../models/auto-update-settings';
@Injectable()
export class DataStorageRepositoryService {
getConfig(): UserConfiguration {
return JSON.parse(localStorage.getItem('config'));
}
saveConfig(config: UserConfiguration): void {
localStorage.setItem('config', JSON.stringify(config.toJsonObject()));
}
getAutoUpdateSettings(): AutoUpdateSettings {
return JSON.parse(localStorage.getItem('auto-update-settings'));
}
saveAutoUpdateSettings(settings: AutoUpdateSettings): void {
localStorage.setItem('auto-update-settings', JSON.stringify(settings));
}
}

View File

@@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { UserConfiguration } from '../config-serializer/config-items/user-configuration';
@Injectable()
export class DefaultUserConfigurationService {
private _defaultConfig: UserConfiguration;
constructor() {
this._defaultConfig = new UserConfiguration()
.fromJsonObject(require('../config-serializer/user-config.json'));
}
getDefault(): UserConfiguration {
return this._defaultConfig;
}
}

View File

@@ -0,0 +1,49 @@
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 { IpcCommonRenderer } from './ipc-common-renderer';
import {
ConnectionStateChangedAction,
SaveConfigurationReplyAction,
SetPrivilegeOnLinuxReplyAction
} from '../store/actions/device';
@Injectable()
export class DeviceRendererService {
constructor(private store: Store<AppState>,
private zone: NgZone,
private ipcRenderer: IpcCommonRenderer,
private logService: LogService) {
this.registerEvents();
this.logService.info('[DeviceRendererService] init success ');
}
setPrivilegeOnLinux(): void {
this.ipcRenderer.send(IpcEvents.device.setPrivilegeOnLinux);
}
saveUserConfiguration(buffer: Buffer): void {
this.ipcRenderer.send(IpcEvents.device.saveUserConfiguration, JSON.stringify(buffer));
}
private registerEvents(): void {
this.ipcRenderer.on(IpcEvents.device.deviceConnectionStateChanged, (event: string, arg: boolean) => {
this.dispachStoreAction(new ConnectionStateChangedAction(arg));
});
this.ipcRenderer.on(IpcEvents.device.setPrivilegeOnLinuxReply, (event: string, response: IpcResponse) => {
this.dispachStoreAction(new SetPrivilegeOnLinuxReplyAction(response));
});
this.ipcRenderer.on(IpcEvents.device.saveUserConfigurationReply, (event: string, response: IpcResponse) => {
this.dispachStoreAction(new SaveConfigurationReplyAction(response));
});
}
private dispachStoreAction(action: Action): void {
this.logService.info('[DeviceRendererService] dispatch action', action);
this.zone.run(() => this.store.dispatch(action));
}
}

View File

@@ -0,0 +1,9 @@
export class IpcCommonRenderer {
send(channel: string, ...args: any[]): void {
}
on(channel: string, listener: Function): this {
return this;
}
}

View File

@@ -0,0 +1,276 @@
import { Injectable } from '@angular/core';
import { KeystrokeType } from '../config-serializer/config-items/key-action/keystroke-type';
@Injectable()
export class MapperService {
private basicScanCodeTextMap: Map<number, string[]>;
private mediaScanCodeTextMap: Map<number, string[]>;
private sytemScanCodeTextMap: Map<number, string[]>;
private basicScancodeIcons: Map<number, string>;
private mediaScancodeIcons: Map<number, string>;
private systemScancodeIcons: Map<number, string>;
private nameToFileName: Map<string, string>;
constructor() {
this.initScanCodeTextMap();
this.initScancodeIcons();
this.initNameToFileNames();
}
public scanCodeToText(scanCode: number, type: KeystrokeType = KeystrokeType.basic): string[] {
let map: Map<number, string[]>;
switch (type) {
case KeystrokeType.shortMedia:
case KeystrokeType.longMedia:
map = this.mediaScanCodeTextMap;
break;
case KeystrokeType.system:
map = this.sytemScanCodeTextMap;
break;
default:
map = this.basicScanCodeTextMap;
break;
}
return map.get(scanCode);
}
public hasScancodeIcon(scancode: number, type = KeystrokeType.basic): boolean {
let map: Map<number, string>;
switch (type) {
case KeystrokeType.basic:
map = this.basicScancodeIcons;
break;
case KeystrokeType.shortMedia:
case KeystrokeType.longMedia:
map = this.mediaScancodeIcons;
break;
case KeystrokeType.system:
map = this.systemScancodeIcons;
break;
default:
map = new Map<number, string>();
}
return map.has(scancode);
}
public scanCodeToSvgImagePath(scanCode: number, type = KeystrokeType.basic): string {
let map: Map<number, string>;
switch (type) {
case KeystrokeType.basic:
map = this.basicScancodeIcons;
break;
case KeystrokeType.shortMedia:
case KeystrokeType.longMedia:
map = this.mediaScancodeIcons;
break;
case KeystrokeType.system:
map = this.systemScancodeIcons;
break;
default:
return undefined;
}
return 'assets/compiled_sprite.svg#' + map.get(scanCode);
}
public getIcon(iconName: string): string {
return 'assets/compiled_sprite.svg#' + this.nameToFileName.get(iconName);
}
public modifierMapper(x: number) {
if (x < 8) {
return Math.floor(x / 2) * 4 + 1 - x; // 1, 0, 3, 2, 5, 4, 7, 6
} else {
return x;
}
}
// TODO: read the mapping from JSON
private initScanCodeTextMap(): void {
this.basicScanCodeTextMap = new Map<number, string[]>();
this.basicScanCodeTextMap.set(4, ['A']);
this.basicScanCodeTextMap.set(5, ['B']);
this.basicScanCodeTextMap.set(6, ['C']);
this.basicScanCodeTextMap.set(7, ['D']);
this.basicScanCodeTextMap.set(8, ['E']);
this.basicScanCodeTextMap.set(9, ['F']);
this.basicScanCodeTextMap.set(10, ['G']);
this.basicScanCodeTextMap.set(11, ['H']);
this.basicScanCodeTextMap.set(12, ['I']);
this.basicScanCodeTextMap.set(13, ['J']);
this.basicScanCodeTextMap.set(14, ['K']);
this.basicScanCodeTextMap.set(15, ['L']);
this.basicScanCodeTextMap.set(16, ['M']);
this.basicScanCodeTextMap.set(17, ['N']);
this.basicScanCodeTextMap.set(18, ['O']);
this.basicScanCodeTextMap.set(19, ['P']);
this.basicScanCodeTextMap.set(20, ['Q']);
this.basicScanCodeTextMap.set(21, ['R']);
this.basicScanCodeTextMap.set(22, ['S']);
this.basicScanCodeTextMap.set(23, ['T']);
this.basicScanCodeTextMap.set(24, ['U']);
this.basicScanCodeTextMap.set(25, ['V']);
this.basicScanCodeTextMap.set(26, ['W']);
this.basicScanCodeTextMap.set(27, ['X']);
this.basicScanCodeTextMap.set(28, ['Y']);
this.basicScanCodeTextMap.set(29, ['Z']);
this.basicScanCodeTextMap.set(30, ['1', '!']);
this.basicScanCodeTextMap.set(31, ['2', '@']);
this.basicScanCodeTextMap.set(32, ['3', '#']);
this.basicScanCodeTextMap.set(33, ['4', '$']);
this.basicScanCodeTextMap.set(34, ['5', '%']);
this.basicScanCodeTextMap.set(35, ['6', '^']);
this.basicScanCodeTextMap.set(36, ['7', '&']);
this.basicScanCodeTextMap.set(37, ['8', '*']);
this.basicScanCodeTextMap.set(38, ['9', '(']);
this.basicScanCodeTextMap.set(39, ['0', ')']);
this.basicScanCodeTextMap.set(40, ['Enter']);
this.basicScanCodeTextMap.set(41, ['Esc']);
this.basicScanCodeTextMap.set(42, ['Backspace']);
this.basicScanCodeTextMap.set(43, ['Tab']);
this.basicScanCodeTextMap.set(44, ['Space']);
this.basicScanCodeTextMap.set(45, ['-', '_']);
this.basicScanCodeTextMap.set(46, ['=', '+']);
this.basicScanCodeTextMap.set(47, ['[', '{']);
this.basicScanCodeTextMap.set(48, [']', '}']);
this.basicScanCodeTextMap.set(49, ['\\', '|']);
this.basicScanCodeTextMap.set(50, ['NON_US_HASHMARK_AND_TILDE']);
this.basicScanCodeTextMap.set(51, [';', ':']);
this.basicScanCodeTextMap.set(52, ['\'', '"']);
this.basicScanCodeTextMap.set(53, ['`', '~']);
this.basicScanCodeTextMap.set(54, [',', '<']);
this.basicScanCodeTextMap.set(55, ['.', '>']);
this.basicScanCodeTextMap.set(56, ['/', '?']);
this.basicScanCodeTextMap.set(57, ['Caps Lock']);
this.basicScanCodeTextMap.set(58, ['F1']);
this.basicScanCodeTextMap.set(59, ['F2']);
this.basicScanCodeTextMap.set(60, ['F3']);
this.basicScanCodeTextMap.set(61, ['F4']);
this.basicScanCodeTextMap.set(62, ['F5']);
this.basicScanCodeTextMap.set(63, ['F6']);
this.basicScanCodeTextMap.set(64, ['F7']);
this.basicScanCodeTextMap.set(65, ['F8']);
this.basicScanCodeTextMap.set(66, ['F9']);
this.basicScanCodeTextMap.set(67, ['F10']);
this.basicScanCodeTextMap.set(68, ['F11']);
this.basicScanCodeTextMap.set(69, ['F12']);
this.basicScanCodeTextMap.set(70, ['PrtScn']);
this.basicScanCodeTextMap.set(71, ['Scroll Lock']);
this.basicScanCodeTextMap.set(72, ['Pause']);
this.basicScanCodeTextMap.set(73, ['Insert']);
this.basicScanCodeTextMap.set(74, ['Home']);
this.basicScanCodeTextMap.set(75, ['PgUp']);
this.basicScanCodeTextMap.set(76, ['Del']);
this.basicScanCodeTextMap.set(77, ['End']);
this.basicScanCodeTextMap.set(78, ['PgDn']);
this.basicScanCodeTextMap.set(79, ['Right Arrow']);
this.basicScanCodeTextMap.set(80, ['Left Arrow']);
this.basicScanCodeTextMap.set(81, ['Down Arrow']);
this.basicScanCodeTextMap.set(82, ['Up Arrow']);
this.basicScanCodeTextMap.set(83, ['Num Lock']);
this.basicScanCodeTextMap.set(84, ['/']);
this.basicScanCodeTextMap.set(85, ['*']);
this.basicScanCodeTextMap.set(86, ['-']);
this.basicScanCodeTextMap.set(87, ['+']);
this.basicScanCodeTextMap.set(88, ['Enter']);
this.basicScanCodeTextMap.set(89, ['end', '1']);
this.basicScanCodeTextMap.set(90, ['2']);
this.basicScanCodeTextMap.set(91, ['pgdn', '3']);
this.basicScanCodeTextMap.set(92, ['4']);
this.basicScanCodeTextMap.set(93, ['5']);
this.basicScanCodeTextMap.set(94, ['6']);
this.basicScanCodeTextMap.set(95, ['home', '7']);
this.basicScanCodeTextMap.set(96, ['8']);
this.basicScanCodeTextMap.set(97, ['pgup', '9']);
this.basicScanCodeTextMap.set(98, ['Insert', '0']);
this.basicScanCodeTextMap.set(99, ['Del', '.']);
this.basicScanCodeTextMap.set(104, ['F13']);
this.basicScanCodeTextMap.set(105, ['F14']);
this.basicScanCodeTextMap.set(106, ['F15']);
this.basicScanCodeTextMap.set(107, ['F16']);
this.basicScanCodeTextMap.set(108, ['F17']);
this.basicScanCodeTextMap.set(109, ['F18']);
this.basicScanCodeTextMap.set(110, ['F19']);
this.basicScanCodeTextMap.set(111, ['F20']);
this.basicScanCodeTextMap.set(112, ['F21']);
this.basicScanCodeTextMap.set(113, ['F22']);
this.basicScanCodeTextMap.set(114, ['F23']);
this.basicScanCodeTextMap.set(115, ['F24']);
this.basicScanCodeTextMap.set(118, ['Menu']);
this.basicScanCodeTextMap.set(176, ['00']);
this.basicScanCodeTextMap.set(177, ['000']);
this.mediaScanCodeTextMap = new Map<number, string[]>();
this.mediaScanCodeTextMap.set(138, ['WWW']);
this.mediaScanCodeTextMap.set(176, ['Play']);
this.mediaScanCodeTextMap.set(177, ['Pause']);
this.mediaScanCodeTextMap.set(181, ['Next']);
this.mediaScanCodeTextMap.set(182, ['Prev']);
this.mediaScanCodeTextMap.set(183, ['Stop']);
this.mediaScanCodeTextMap.set(184, ['Eject']);
this.mediaScanCodeTextMap.set(204, ['Eject', 'Stop']);
this.mediaScanCodeTextMap.set(205, ['Pause', 'Play']);
this.mediaScanCodeTextMap.set(226, ['Mute']);
this.mediaScanCodeTextMap.set(233, ['Vol +']);
this.mediaScanCodeTextMap.set(234, ['Vol -']);
this.mediaScanCodeTextMap.set(406, ['Launch Web Browser']);
this.mediaScanCodeTextMap.set(394, ['Launch Email Client']);
this.mediaScanCodeTextMap.set(402, ['Launch Calculator']);
this.sytemScanCodeTextMap = new Map<number, string[]>();
this.sytemScanCodeTextMap.set(129, ['Power Down']);
this.sytemScanCodeTextMap.set(130, ['Sleep']);
this.sytemScanCodeTextMap.set(131, ['Wake Up']);
}
private initScancodeIcons(): void {
this.basicScancodeIcons = new Map<number, string>();
this.basicScancodeIcons.set(79, 'icon-kbd__mod--arrow-right');
this.basicScancodeIcons.set(80, 'icon-kbd__mod--arrow-left');
this.basicScancodeIcons.set(81, 'icon-kbd__mod--arrow-down');
this.basicScancodeIcons.set(82, 'icon-kbd__mod--arrow-up');
this.basicScancodeIcons.set(118, 'icon-kbd__mod--menu');
this.mediaScancodeIcons = new Map<number, string>();
this.mediaScancodeIcons.set(138, 'icon-kbd__fn--browser');
this.mediaScancodeIcons.set(176, 'icon-kbd__media--play');
this.mediaScancodeIcons.set(177, 'icon-kbd__media--pause');
this.mediaScancodeIcons.set(181, 'icon-kbd__media--next');
this.mediaScancodeIcons.set(182, 'icon-kbd__media--prev');
this.mediaScancodeIcons.set(184, 'icon-kbd__fn--eject');
this.mediaScancodeIcons.set(226, 'icon-kbd__media--mute');
this.mediaScancodeIcons.set(233, 'icon-kbd__media--vol-up');
this.mediaScancodeIcons.set(234, 'icon-kbd__media--vol-down');
this.mediaScancodeIcons.set(406, 'icon-kbd__media--web-browser');
this.mediaScancodeIcons.set(394, 'icon-kbd__media--email-client');
this.mediaScancodeIcons.set(402, 'icon-kbd__media--calculator');
this.systemScancodeIcons = new Map<number, string>();
this.systemScancodeIcons.set(129, 'icon-kbd__system_power_down');
this.systemScancodeIcons.set(130, 'icon-kbd__system_sleep');
this.systemScancodeIcons.set(131, 'icon-kbd__system_wake_up');
}
private initNameToFileNames(): void {
this.nameToFileName = new Map<string, string>();
this.nameToFileName.set('toggle', 'icon-kbd__fn--toggle');
this.nameToFileName.set('switch-keymap', 'icon-kbd__mod--switch-keymap');
this.nameToFileName.set('macro', 'icon-icon__macro');
this.nameToFileName.set('shift', 'icon-kbd__default--modifier-shift');
this.nameToFileName.set('option', 'icon-kbd__default--modifier-option');
this.nameToFileName.set('command', 'icon-kbd__default--modifier-command');
this.nameToFileName.set('mouse', 'icon-kbd__mouse');
this.nameToFileName.set('left-arrow', 'icon-kbd__mod--arrow-left');
this.nameToFileName.set('right-arrow', 'icon-kbd__mod--arrow-right');
this.nameToFileName.set('down-arrow', 'icon-kbd__mod--arrow-down');
this.nameToFileName.set('up-arrow', 'icon-kbd__mod--arrow-up');
this.nameToFileName.set('scroll-left', 'icon-kbd__mouse--scroll-left');
this.nameToFileName.set('scroll-right', 'icon-kbd__mouse--scroll-right');
this.nameToFileName.set('scroll-down', 'icon-kbd__mouse--scroll-down');
this.nameToFileName.set('scroll-up', 'icon-kbd__mouse--scroll-up');
}
}

View File

@@ -0,0 +1,37 @@
import { Injectable } from '@angular/core';
import { SvgModule } from '../components/svg/module';
import { KeyboardLayout } from '../keyboard/keyboard-layout.enum';
@Injectable()
export class SvgModuleProviderService {
private ansiLeft: SvgModule;
private isoLeft: SvgModule;
private right: SvgModule;
getSvgModules(layout = KeyboardLayout.ANSI): SvgModule[] {
return [this.getRightModule(), this.getLeftModule(layout)];
}
private getLeftModule(layout = KeyboardLayout.ANSI): SvgModule {
if (layout === KeyboardLayout.ISO) {
if (!this.isoLeft) {
this.isoLeft = new SvgModule(require('xml-loader!../../modules/uhk60-left-half/layout-iso.xml').svg);
}
return this.isoLeft;
}
if (!this.ansiLeft) {
this.ansiLeft = new SvgModule(require('xml-loader!../../modules/uhk60-left-half/layout-ansi.xml').svg);
}
return this.ansiLeft;
}
private getRightModule(): SvgModule {
if (!this.right) {
this.right = new SvgModule(require('xml-loader!../../modules/uhk60-right-half/layout.xml').svg);
}
return this.right;
}
}

View File

@@ -0,0 +1,24 @@
import { CanActivate, Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import { AppState, deviceConnected } from '../store/index';
@Injectable()
export class UhkDeviceConnectedGuard implements CanActivate {
constructor(private store: Store<AppState>, private router: Router) { }
canActivate(): Observable<boolean> {
return this.store.select(deviceConnected)
.do(connected => {
if (connected) {
this.router.navigate(['/']);
}
})
.map(connected => !connected);
}
}

View File

@@ -0,0 +1,24 @@
import { CanActivate, Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import { AppState, deviceConnected } from '../store/index';
import { Store } from '@ngrx/store';
@Injectable()
export class UhkDeviceDisconnectedGuard implements CanActivate {
constructor(private store: Store<AppState>, private router: Router) { }
canActivate(): Observable<boolean> {
return this.store.select(deviceConnected)
.do(connected => {
if (!connected) {
this.router.navigate(['/detection']);
}
});
}
}

View File

@@ -0,0 +1,25 @@
import { CanActivate, Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import { AppState, hasDevicePermission } from '../store/index';
@Injectable()
export class UhkDeviceInitializedGuard implements CanActivate {
constructor(private store: Store<AppState>, private router: Router) { }
canActivate(): Observable<boolean> {
return this.store.select(hasDevicePermission)
.do(hasPermission => {
if (hasPermission) {
this.router.navigate(['/detection']);
}
})
.map(hasPermission => !hasPermission);
}
}

View File

@@ -0,0 +1,24 @@
import { CanActivate, Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import { AppState, hasDevicePermission } from '../store/index';
@Injectable()
export class UhkDeviceUninitializedGuard implements CanActivate {
constructor(private store: Store<AppState>, private router: Router) { }
canActivate(): Observable<boolean> {
return this.store.select(hasDevicePermission)
.do(hasPermission => {
if (!hasPermission) {
this.router.navigate(['/privilege']);
}
});
}
}