feat(agent): automatically write user configuration after app started (#516)

* auto write userconfig

* fix load success action

* exit from app

* add electron:auto-write-config script
This commit is contained in:
Róbert Kiss
2017-12-14 23:36:43 +01:00
committed by László Monda
parent e8a1814d89
commit b32c93f0f8
15 changed files with 90 additions and 38 deletions

View File

@@ -10,7 +10,7 @@ import * as url from 'url';
import * as commandLineArgs from 'command-line-args';
import { UhkHidDevice, UhkOperations } from 'uhk-usb';
// import { ElectronDataStorageRepositoryService } from './services/electron-datastorage-repository.service';
import { CommandLineArgs, LogRegExps } from 'uhk-common';
import { LogRegExps } from 'uhk-common';
import { DeviceService } from './services/device.service';
import { logger } from './services/logger.service';
import { AppUpdateService } from './services/app-update.service';
@@ -18,12 +18,14 @@ import { AppService } from './services/app.service';
import { SudoService } from './services/sudo.service';
import { UhkBlhost } from '../../uhk-usb/src';
import * as isDev from 'electron-is-dev';
import { CommandLineInputs } from './models/command-line-inputs';
const optionDefinitions = [
{name: 'addons', type: Boolean, defaultOption: false}
{name: 'addons', type: Boolean},
{name: 'auto-write-config', type: Boolean}
];
const options: CommandLineArgs = commandLineArgs(optionDefinitions);
const options: CommandLineInputs = commandLineArgs(optionDefinitions);
// import './dev-extension';
// require('electron-debug')({ showDevTools: true, enabled: true });

View File

@@ -0,0 +1,4 @@
export interface CommandLineInputs {
addons?: boolean;
'auto-write-config'?: boolean;
}

View File

@@ -3,19 +3,21 @@ 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';
export class AppService extends MainServiceBase {
constructor(protected logService: LogService,
protected win: Electron.BrowserWindow,
private deviceService: DeviceService,
private options: CommandLineArgs,
private options: CommandLineInputs,
private uhkHidDeviceService: UhkHidDevice) {
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');
}
@@ -25,7 +27,10 @@ export class AppService extends MainServiceBase {
const packageJson = await this.getPackageJson();
const response: AppStartInfo = {
commandLineArgs: this.options,
commandLineArgs: {
addons: this.options.addons || false,
autoWriteConfig: this.options['auto-write-config'] || false
},
deviceConnected: this.deviceService.isConnected,
hasPermission: this.uhkHidDeviceService.hasPermission(),
agentVersionInfo: {
@@ -57,4 +62,9 @@ export class AppService extends MainServiceBase {
});
});
}
private exit() {
this.logService.info('[AppService] exit');
this.win.close();
}
}

View File

@@ -89,7 +89,6 @@ export class DeviceService {
success: true,
...result
};
event.sender.send(IpcEvents.device.loadConfigurationReply, JSON.stringify(response));
} catch (error) {
response = {
success: false,