exit from app

This commit is contained in:
Róbert Kiss
2017-12-14 23:19:34 +01:00
parent 2bf7d545a2
commit 42b4465230
5 changed files with 39 additions and 9 deletions

View File

@@ -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();
}
}

View File

@@ -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 {

View File

@@ -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));

View File

@@ -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<SaveToKeyboardSuccessAction>(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<AppState>) {
}
}

View File

@@ -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<Action> = this.actions$
.ofType(ActionTypes.SAVE_CONFIGURATION_REPLY)
.map(toPayload)
.ofType<SaveConfigurationReplyAction>(ActionTypes.SAVE_CONFIGURATION_REPLY)
.map(action => action.payload)
.mergeMap((response: IpcResponse) => {
if (response.success) {
return [