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
@@ -0,0 +1,47 @@
import { Injectable } from '@angular/core';
import { Action } from '@ngrx/store';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/first';
import { NotificationType } from 'uhk-common';
import { ActionTypes } from '../actions/app-update.action';
import { ActionTypes as AutoUpdateActionTypes } from '../actions/auto-update-settings';
import { ShowNotificationAction } from '../actions/app';
import { AppUpdateRendererService } from '../../services/app-update-renderer.service';
@Injectable()
export class AppUpdateEffect {
@Effect({ dispatch: false })
appStart$: Observable<Action> = this.actions$
.ofType(ActionTypes.UPDATE_APP)
.first()
.do(() => {
this.appUpdateRendererService.sendUpdateAndRestartApp();
});
@Effect({ dispatch: false }) checkForUpdate$: Observable<Action> = this.actions$
.ofType(AutoUpdateActionTypes.CHECK_FOR_UPDATE_NOW)
.do(() => {
this.appUpdateRendererService.checkForUpdate();
});
@Effect() handleError$: Observable<Action> = this.actions$
.ofType(ActionTypes.UPDATE_ERROR)
.map(toPayload)
.map((message: string) => {
return new ShowNotificationAction({
type: NotificationType.Error,
message
});
});
constructor(private actions$: Actions,
private appUpdateRendererService: AppUpdateRendererService) {
}
}
@@ -0,0 +1,67 @@
import { Injectable } from '@angular/core';
import { Action } from '@ngrx/store';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import { NotifierService } from 'angular-notifier';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
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 { AppRendererService } from '../../services/app-renderer.service';
import { AppUpdateRendererService } from '../../services/app-update-renderer.service';
import { ConnectionStateChangedAction, PermissionStateChangedAction } from '../actions/device';
@Injectable()
export class ApplicationEffects {
@Effect()
appStart$: Observable<Action> = this.actions$
.ofType(ActionTypes.APP_BOOTSRAPPED)
.startWith(new AppStartedAction())
.do(() => {
this.logService.info('Renderer appStart effect start');
this.appUpdateRendererService.sendAppStarted();
this.appRendererService.getAppStartInfo();
this.logService.info('Renderer appStart effect end');
});
@Effect({ dispatch: false })
showNotification$: Observable<Action> = this.actions$
.ofType(ActionTypes.APP_SHOW_NOTIFICATION)
.map(toPayload)
.do((notification: Notification) => {
if (notification.type === NotificationType.Undoable) {
return;
}
this.notifierService.notify(notification.type, notification.message);
});
@Effect()
processStartInfo$: Observable<Action> = this.actions$
.ofType(ActionTypes.APP_PROCESS_START_INFO)
.map(toPayload)
.mergeMap((appInfo: AppStartInfo) => {
this.logService.debug('[AppEffect][processStartInfo] payload:', appInfo);
return [
new ToggleAddonMenuAction(appInfo.commandLineArgs.addons),
new ConnectionStateChangedAction(appInfo.deviceConnected),
new PermissionStateChangedAction(appInfo.hasPermission)
];
});
@Effect() undoLastNotification$: Observable<Action> = this.actions$
.ofType(ActionTypes.UNDO_LAST)
.map(toPayload)
.mergeMap((action: Action) => [action, new DismissUndoNotificationAction()]);
constructor(private actions$: Actions,
private notifierService: NotifierService,
private appUpdateRendererService: AppUpdateRendererService,
private appRendererService: AppRendererService,
private logService: LogService) { }
}
@@ -0,0 +1,61 @@
import { Injectable } from '@angular/core';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import { Action, Store } from '@ngrx/store';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/operator/map';
import { NotificationType } from 'uhk-common';
import {
ActionTypes,
LoadAutoUpdateSettingsAction,
LoadAutoUpdateSettingsSuccessAction,
SaveAutoUpdateSettingsSuccessAction
} from '../actions/auto-update-settings';
import { DataStorageRepositoryService } from '../../services/datastorage-repository.service';
import { AppState, getAutoUpdateSettings } from '../index';
import { initialState } from '../reducers/auto-update-settings';
import { AutoUpdateSettings } from '../../models/auto-update-settings';
import { ShowNotificationAction } from '../actions/app';
@Injectable()
export class AutoUpdateSettingsEffects {
@Effect() loadUserConfig$: Observable<Action> = this.actions$
.ofType(ActionTypes.LOAD_AUTO_UPDATE_SETTINGS)
.startWith(new LoadAutoUpdateSettingsAction())
.switchMap(() => {
let settings: AutoUpdateSettings = this.dataStorageRepository.getAutoUpdateSettings();
if (!settings) {
settings = initialState;
}
return Observable.of(new LoadAutoUpdateSettingsSuccessAction(settings));
});
@Effect() saveAutoUpdateConfig$: Observable<Action> = this.actions$
.ofType(ActionTypes.TOGGLE_CHECK_FOR_UPDATE_ON_STARTUP, ActionTypes.TOGGLE_PRE_RELEASE_FLAG)
.withLatestFrom(this.store.select(getAutoUpdateSettings))
.map(([action, config]) => {
this.dataStorageRepository.saveAutoUpdateSettings(config);
return new SaveAutoUpdateSettingsSuccessAction();
});
@Effect() sendNotification$: Observable<Action> = this.actions$
.ofType(ActionTypes.CHECK_FOR_UPDATE_FAILED, ActionTypes.CHECK_FOR_UPDATE_SUCCESS)
.map(toPayload)
.map((message: string) => {
return new ShowNotificationAction({
type: NotificationType.Info,
message
});
});
constructor(private actions$: Actions,
private dataStorageRepository: DataStorageRepositoryService,
private store: Store<AppState>) {
}
}
@@ -0,0 +1,101 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Action } from '@ngrx/store';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import { NotificationType, IpcResponse } from 'uhk-common';
import { ActionTypes, ConnectionStateChangedAction, PermissionStateChangedAction } from '../actions/device';
import { DeviceRendererService } from '../../services/device-renderer.service';
import { ShowNotificationAction } from '../actions/app';
@Injectable()
export class DeviceEffects {
@Effect({ dispatch: false })
deviceConnectionStateChange$: Observable<Action> = this.actions$
.ofType(ActionTypes.CONNECTION_STATE_CHANGED)
.map(toPayload)
.do((connected: boolean) => {
if (connected) {
this.router.navigate(['/']);
}
else {
this.router.navigate(['/detection']);
}
});
@Effect({ dispatch: false })
permissionStateChange$: Observable<Action> = this.actions$
.ofType(ActionTypes.PERMISSION_STATE_CHANGED)
.map(toPayload)
.do((hasPermission: boolean) => {
if (hasPermission) {
this.router.navigate(['/detection']);
}
else {
this.router.navigate(['/privilege']);
}
});
@Effect({ dispatch: false })
setPrivilegeOnLinux$: Observable<Action> = this.actions$
.ofType(ActionTypes.SET_PRIVILEGE_ON_LINUX)
.do(() => {
this.deviceRendererService.setPrivilegeOnLinux();
});
@Effect()
setPrivilegeOnLinuxReply$: Observable<Action> = this.actions$
.ofType(ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY)
.map(toPayload)
.mergeMap((response: any) => {
if (response.success) {
return [
new ConnectionStateChangedAction(true),
new PermissionStateChangedAction(true)
];
}
return [
<any>new ShowNotificationAction({
type: NotificationType.Error,
message: response.error.message
})
];
});
@Effect({ dispatch: false })
saveConfiguration$: Observable<Action> = this.actions$
.ofType(ActionTypes.SAVE_CONFIGURATION)
.map(toPayload)
.do((buffer: Buffer) => {
this.deviceRendererService.saveUserConfiguration(buffer);
});
@Effect()
saveConfigurationReply$: Observable<Action> = this.actions$
.ofType(ActionTypes.SAVE_CONFIGURATION_REPLY)
.map(toPayload)
.map((response: IpcResponse) => {
if (response.success) {
return new ShowNotificationAction({
type: NotificationType.Success,
message: 'Save configuration successful.'
});
}
return new ShowNotificationAction({
type: NotificationType.Error,
message: response.error.message
});
});
constructor(private actions$: Actions,
private router: Router,
private deviceRendererService: DeviceRendererService) {
}
}
@@ -0,0 +1,5 @@
export * from './keymap';
export * from './macro';
export * from './user-config';
export * from './auto-update-settings';
export * from './app';
@@ -0,0 +1,68 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Actions, Effect } from '@ngrx/effects';
import { Action, Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/observable/of';
import { KeymapActions } from '../actions';
import { AppState } from '../index';
import { Keymap } from '../../config-serializer/config-items/keymap';
@Injectable()
export class KeymapEffects {
@Effect() loadKeymaps$: Observable<Action> = this.actions$
.ofType(KeymapActions.LOAD_KEYMAPS)
.startWith(KeymapActions.loadKeymaps())
.switchMap(() => {
const presetsRequireContext = (<any>require).context('../../../res/presets', false, /.json$/);
const uhkPresets = presetsRequireContext.keys().map(presetsRequireContext) // load the presets into an array
.map((keymap: any) => new Keymap().fromJsonObject(keymap));
return Observable.of(KeymapActions.loadKeymapsSuccess(uhkPresets));
});
@Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$
.ofType(KeymapActions.ADD, KeymapActions.DUPLICATE)
.withLatestFrom(this.store)
.map(latest => latest[1].userConfiguration.keymaps)
.do(keymaps => {
this.router.navigate(['/keymap', keymaps[keymaps.length - 1].abbreviation]);
});
@Effect({ dispatch: false }) remove$: any = this.actions$
.ofType(KeymapActions.REMOVE)
.withLatestFrom(this.store)
.map(latest => latest[1].userConfiguration.keymaps)
.do(keymaps => {
if (keymaps.length === 0) {
this.router.navigate(['/keymap/add']);
} else {
const favourite: Keymap = keymaps.find(keymap => keymap.isDefault);
this.router.navigate(['/keymap', favourite.abbreviation]);
}
});
@Effect({ dispatch: false }) editAbbr$: any = this.actions$
.ofType(KeymapActions.EDIT_ABBR)
.withLatestFrom(this.store)
.do(([action, store]) => {
for (const keymap of store.userConfiguration.keymaps) {
if (keymap.name === action.payload.name && keymap.abbreviation === action.payload.newAbbr) {
this.router.navigate(['/keymap', action.payload.newAbbr]);
return;
}
}
});
constructor(private actions$: Actions, private router: Router, private store: Store<AppState>) { }
}
@@ -0,0 +1,49 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Actions, Effect } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/withLatestFrom';
import { KeymapActions, MacroActions } from '../actions';
import { AppState } from '../index';
@Injectable()
export class MacroEffects {
@Effect({ dispatch: false }) remove$: any = this.actions$
.ofType(MacroActions.REMOVE)
.map(action => this.store.dispatch(KeymapActions.checkMacro(action.payload)))
.withLatestFrom(this.store)
.map(([action, state]) => state.userConfiguration.macros)
.do(macros => {
if (macros.length === 0) {
this.router.navigate(['/macro']);
} else {
this.router.navigate(['/macro', macros[0].id]);
}
});
@Effect({ dispatch: false }) add$: any = this.actions$
.ofType(MacroActions.ADD)
.withLatestFrom(this.store)
.map(([action, state]) => state.userConfiguration.macros)
.map(macros => macros[macros.length - 1])
.do(lastMacro => {
this.router.navigate(['/macro', lastMacro.id, 'new']);
});
@Effect({ dispatch: false }) duplicate: any = this.actions$
.ofType(MacroActions.DUPLICATE)
.withLatestFrom(this.store)
.map(([action, state]) => state.userConfiguration.macros)
.map(macros => macros[macros.length - 1])
.do(lastMacro => {
this.router.navigate(['/macro', lastMacro.id]);
});
constructor(private actions$: Actions, private router: Router, private store: Store<AppState>) {}
}
@@ -0,0 +1,106 @@
import { Injectable } from '@angular/core';
import { go } from '@ngrx/router-store';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import { Action, Store } from '@ngrx/store';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/observable/of';
import { NotificationType } from 'uhk-common';
import {
ActionTypes,
LoadUserConfigAction,
LoadUserConfigSuccessAction,
SaveUserConfigSuccessAction
} from '../actions/user-config';
import { UserConfiguration } from '../../config-serializer/config-items/user-configuration';
import { DataStorageRepositoryService } from '../../services/datastorage-repository.service';
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
import { AppState, getPrevUserConfiguration, getUserConfiguration } from '../index';
import { KeymapActions } from '../actions/keymap';
import { MacroActions } from '../actions/macro';
import { UndoUserConfigData } from '../../models/undo-user-config-data';
import { ShowNotificationAction, DismissUndoNotificationAction } from '../actions/app';
@Injectable()
export class UserConfigEffects {
@Effect() loadUserConfig$: Observable<Action> = this.actions$
.ofType(ActionTypes.LOAD_USER_CONFIG)
.startWith(new LoadUserConfigAction())
.switchMap(() => Observable.of(new LoadUserConfigSuccessAction(this.getUserConfiguration())));
@Effect() saveUserConfig$: Observable<Action> = this.actions$
.ofType(
KeymapActions.ADD, KeymapActions.DUPLICATE, KeymapActions.EDIT_NAME, KeymapActions.EDIT_ABBR,
KeymapActions.SET_DEFAULT, KeymapActions.REMOVE, KeymapActions.SAVE_KEY,
MacroActions.ADD, MacroActions.DUPLICATE, MacroActions.EDIT_NAME, MacroActions.REMOVE, MacroActions.ADD_ACTION,
MacroActions.SAVE_ACTION, MacroActions.DELETE_ACTION, MacroActions.REORDER_ACTION)
.withLatestFrom(this.store.select(getUserConfiguration), this.store.select(getPrevUserConfiguration))
.mergeMap(([action, config, prevUserConfiguration]) => {
this.dataStorageRepository.saveConfig(config);
if (action.type === KeymapActions.REMOVE || action.type === MacroActions.REMOVE) {
const text = action.type === KeymapActions.REMOVE ? 'Keymap' : 'Macro';
const pathPrefix = action.type === KeymapActions.REMOVE ? 'keymap' : 'macro';
const payload: UndoUserConfigData = {
path: `/${pathPrefix}/${action.payload}`,
config: prevUserConfiguration.toJsonObject()
};
return [
new SaveUserConfigSuccessAction(config),
new ShowNotificationAction({
type: NotificationType.Undoable,
message: `${text} has been deleted`,
extra: {
payload,
type: KeymapActions.UNDO_LAST_ACTION
}
})
];
}
return [new SaveUserConfigSuccessAction(config), new DismissUndoNotificationAction()];
});
@Effect() undoUserConfig$: Observable<Action> = this.actions$
.ofType(KeymapActions.UNDO_LAST_ACTION)
.map(toPayload)
.mergeMap((payload: UndoUserConfigData) => {
const config = new UserConfiguration().fromJsonObject(payload.config);
this.dataStorageRepository.saveConfig(config);
return [new LoadUserConfigSuccessAction(config), go(payload.path)];
});
constructor(private actions$: Actions,
private dataStorageRepository: DataStorageRepositoryService,
private store: Store<AppState>,
private defaultUserConfigurationService: DefaultUserConfigurationService) {
}
private getUserConfiguration() {
const configJsonObject = this.dataStorageRepository.getConfig();
let config: UserConfiguration;
if (configJsonObject) {
if (configJsonObject.dataModelVersion === this.defaultUserConfigurationService.getDefault().dataModelVersion) {
config = new UserConfiguration().fromJsonObject(configJsonObject);
}
}
if (!config) {
config = this.defaultUserConfigurationService.getDefault();
}
return config;
}
}