From 42b446523006546f7d4ed0cee33081bc09f64e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ro=CC=81bert=20Kiss?= Date: Thu, 14 Dec 2017 23:19:34 +0100 Subject: [PATCH] exit from app --- .../uhk-agent/src/services/app.service.ts | 8 +++++- packages/uhk-common/src/util/ipcEvents.ts | 1 + .../src/app/services/app-renderer.service.ts | 5 ++++ packages/uhk-web/src/app/store/effects/app.ts | 27 +++++++++++++++---- .../uhk-web/src/app/store/effects/device.ts | 7 ++--- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/uhk-agent/src/services/app.service.ts b/packages/uhk-agent/src/services/app.service.ts index 4492009a..e0b7e986 100644 --- a/packages/uhk-agent/src/services/app.service.ts +++ b/packages/uhk-agent/src/services/app.service.ts @@ -3,7 +3,7 @@ import { UhkHidDevice } from 'uhk-usb'; import { readFile } from 'fs'; import { join } from 'path'; -import { AppStartInfo, CommandLineArgs, IpcEvents, LogService } from 'uhk-common'; +import { AppStartInfo, IpcEvents, LogService } from 'uhk-common'; import { MainServiceBase } from './main-service-base'; import { DeviceService } from './device.service'; import { CommandLineInputs } from '../models/command-line-inputs'; @@ -17,6 +17,7 @@ export class AppService extends MainServiceBase { super(logService, win); ipcMain.on(IpcEvents.app.getAppStartInfo, this.handleAppStartInfo.bind(this)); + ipcMain.on(IpcEvents.app.exit, this.exit.bind(this)); logService.info('[AppService] init success'); } @@ -61,4 +62,9 @@ export class AppService extends MainServiceBase { }); }); } + + private exit() { + this.logService.info('[AppService] exit'); + this.win.close(); + } } diff --git a/packages/uhk-common/src/util/ipcEvents.ts b/packages/uhk-common/src/util/ipcEvents.ts index 974aa895..0ce2a7d6 100644 --- a/packages/uhk-common/src/util/ipcEvents.ts +++ b/packages/uhk-common/src/util/ipcEvents.ts @@ -2,6 +2,7 @@ class App { public static readonly appStarted = 'app-started'; public static readonly getAppStartInfo = 'app-get-start-info'; public static readonly getAppStartInfoReply = 'app-get-start-info-reply'; + public static readonly exit = 'app-exit'; } class AutoUpdate { diff --git a/packages/uhk-web/src/app/services/app-renderer.service.ts b/packages/uhk-web/src/app/services/app-renderer.service.ts index 4e3809e4..bcb44b10 100644 --- a/packages/uhk-web/src/app/services/app-renderer.service.ts +++ b/packages/uhk-web/src/app/services/app-renderer.service.ts @@ -21,6 +21,11 @@ export class AppRendererService { this.ipcRenderer.send(IpcEvents.app.getAppStartInfo); } + exit() { + this.logService.info('[AppRendererService] exit'); + this.ipcRenderer.send(IpcEvents.app.exit); + } + private registerEvents() { this.ipcRenderer.on(IpcEvents.app.getAppStartInfoReply, (event: string, arg: AppStartInfo) => { this.dispachStoreAction(new ProcessAppStartInfoAction(arg)); diff --git a/packages/uhk-web/src/app/store/effects/app.ts b/packages/uhk-web/src/app/store/effects/app.ts index 181dd01e..1ab1cddd 100644 --- a/packages/uhk-web/src/app/store/effects/app.ts +++ b/packages/uhk-web/src/app/store/effects/app.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { Action } from '@ngrx/store'; +import { Action, Store } from '@ngrx/store'; import { Actions, Effect } from '@ngrx/effects'; import { Observable } from 'rxjs/Observable'; import { NotifierService } from 'angular-notifier'; @@ -13,16 +13,23 @@ import 'rxjs/add/operator/catch'; import { AppStartInfo, LogService, Notification, NotificationType } from 'uhk-common'; import { ActionTypes, + ApplyCommandLineArgsAction, AppStartedAction, DismissUndoNotificationAction, ProcessAppStartInfoAction, ShowNotificationAction, - ApplyCommandLineArgsAction, - UndoLastAction, UpdateAgentVersionInformationAction + 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'; +import { + ActionTypes as DeviceActions, + ConnectionStateChangedAction, + PermissionStateChangedAction, + SaveToKeyboardSuccessAction +} from '../actions/device'; +import { AppState, autoWriteUserConfiguration } from '../index'; @Injectable() export class ApplicationEffects { @@ -68,10 +75,20 @@ export class ApplicationEffects { .map(action => action.payload) .mergeMap((action: Action) => [action, new DismissUndoNotificationAction()]); + @Effect({dispatch: false}) saveToKeyboardSuccess$ = this.actions$ + .ofType(DeviceActions.SAVE_TO_KEYBOARD_SUCCESS) + .withLatestFrom(this.store.select(autoWriteUserConfiguration)) + .do(([action, autoWriteUserConfig]) => { + if (autoWriteUserConfig) { + this.appRendererService.exit(); + } + }); + constructor(private actions$: Actions, private notifierService: NotifierService, private appUpdateRendererService: AppUpdateRendererService, private appRendererService: AppRendererService, - private logService: LogService) { + private logService: LogService, + private store: Store) { } } diff --git a/packages/uhk-web/src/app/store/effects/device.ts b/packages/uhk-web/src/app/store/effects/device.ts index cf4f3db3..82f1ef45 100644 --- a/packages/uhk-web/src/app/store/effects/device.ts +++ b/packages/uhk-web/src/app/store/effects/device.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Action, Store } from '@ngrx/store'; -import { Actions, Effect, toPayload } from '@ngrx/effects'; +import { Actions, Effect } from '@ngrx/effects'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/of'; @@ -20,6 +20,7 @@ import { HideSaveToKeyboardButton, PermissionStateChangedAction, SaveConfigurationAction, + SaveConfigurationReplyAction, SaveToKeyboardSuccessAction, SaveToKeyboardSuccessFailed, SetPrivilegeOnLinuxReplyAction, @@ -113,8 +114,8 @@ export class DeviceEffects { @Effect() saveConfigurationReply$: Observable = this.actions$ - .ofType(ActionTypes.SAVE_CONFIGURATION_REPLY) - .map(toPayload) + .ofType(ActionTypes.SAVE_CONFIGURATION_REPLY) + .map(action => action.payload) .mergeMap((response: IpcResponse) => { if (response.success) { return [