auto write userconfig
This commit is contained in:
@@ -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 });
|
||||
|
||||
4
packages/uhk-agent/src/models/command-line-inputs.ts
Normal file
4
packages/uhk-agent/src/models/command-line-inputs.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface CommandLineInputs {
|
||||
addons?: boolean;
|
||||
'auto-write-config'?: boolean;
|
||||
}
|
||||
@@ -6,12 +6,13 @@ import { join } from 'path';
|
||||
import { AppStartInfo, CommandLineArgs, 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);
|
||||
|
||||
@@ -25,7 +26,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: {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export interface CommandLineArgs {
|
||||
addons: boolean;
|
||||
autoWriteConfig: boolean;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { AppStartInfo, HardwareConfiguration, Notification, type, VersionInformation } from 'uhk-common';
|
||||
import { AppStartInfo, CommandLineArgs, HardwareConfiguration, Notification, type, VersionInformation } from 'uhk-common';
|
||||
import { ElectronLogEntry } from '../../models/xterm-log';
|
||||
|
||||
const PREFIX = '[app] ';
|
||||
@@ -10,7 +10,7 @@ export const ActionTypes = {
|
||||
APP_BOOTSRAPPED: type(PREFIX + 'bootstrapped'),
|
||||
APP_STARTED: type(PREFIX + 'started'),
|
||||
APP_SHOW_NOTIFICATION: type(PREFIX + 'show notification'),
|
||||
APP_TOGGLE_ADDON_MENU: type(PREFIX + 'toggle add-on menu'),
|
||||
APPLY_COMMAND_LINE_ARGS: type(PREFIX + 'apply command line args'),
|
||||
APP_PROCESS_START_INFO: type(PREFIX + 'process start info'),
|
||||
UNDO_LAST: type(PREFIX + 'undo last action'),
|
||||
UNDO_LAST_SUCCESS: type(PREFIX + 'undo last action success'),
|
||||
@@ -34,10 +34,10 @@ export class ShowNotificationAction implements Action {
|
||||
constructor(public payload: Notification) { }
|
||||
}
|
||||
|
||||
export class ToggleAddonMenuAction implements Action {
|
||||
type = ActionTypes.APP_TOGGLE_ADDON_MENU;
|
||||
export class ApplyCommandLineArgsAction implements Action {
|
||||
type = ActionTypes.APPLY_COMMAND_LINE_ARGS;
|
||||
|
||||
constructor(public payload: boolean) { }
|
||||
constructor(public payload: CommandLineArgs) { }
|
||||
}
|
||||
|
||||
export class ProcessAppStartInfoAction implements Action {
|
||||
@@ -82,7 +82,7 @@ export type Actions
|
||||
= AppStartedAction
|
||||
| AppBootsrappedAction
|
||||
| ShowNotificationAction
|
||||
| ToggleAddonMenuAction
|
||||
| ApplyCommandLineArgsAction
|
||||
| ProcessAppStartInfoAction
|
||||
| UndoLastAction
|
||||
| UndoLastSuccessAction
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
DismissUndoNotificationAction,
|
||||
ProcessAppStartInfoAction,
|
||||
ShowNotificationAction,
|
||||
ToggleAddonMenuAction,
|
||||
ApplyCommandLineArgsAction,
|
||||
UndoLastAction, UpdateAgentVersionInformationAction
|
||||
} from '../actions/app';
|
||||
import { AppRendererService } from '../../services/app-renderer.service';
|
||||
@@ -56,7 +56,7 @@ export class ApplicationEffects {
|
||||
.mergeMap((appInfo: AppStartInfo) => {
|
||||
this.logService.debug('[AppEffect][processStartInfo] payload:', appInfo);
|
||||
return [
|
||||
new ToggleAddonMenuAction(appInfo.commandLineArgs.addons),
|
||||
new ApplyCommandLineArgsAction(appInfo.commandLineArgs),
|
||||
new ConnectionStateChangedAction(appInfo.deviceConnected),
|
||||
new PermissionStateChangedAction(appInfo.hasPermission),
|
||||
new UpdateAgentVersionInformationAction(appInfo.agentVersionInfo)
|
||||
|
||||
@@ -12,35 +12,27 @@ import 'rxjs/add/operator/startWith';
|
||||
import 'rxjs/add/operator/withLatestFrom';
|
||||
import 'rxjs/add/operator/mergeMap';
|
||||
import 'rxjs/add/observable/of';
|
||||
import 'rxjs/add/observable/empty';
|
||||
|
||||
import {
|
||||
ConfigurationReply,
|
||||
HardwareConfiguration,
|
||||
LogService,
|
||||
NotificationType,
|
||||
UhkBuffer,
|
||||
ConfigurationReply, HardwareConfiguration, LogService, NotificationType, UhkBuffer,
|
||||
UserConfiguration
|
||||
} from 'uhk-common';
|
||||
|
||||
import {
|
||||
ActionTypes,
|
||||
LoadConfigFromDeviceReplyAction,
|
||||
LoadUserConfigSuccessAction,
|
||||
RenameUserConfigurationAction,
|
||||
ActionTypes, LoadConfigFromDeviceReplyAction, LoadUserConfigSuccessAction, RenameUserConfigurationAction,
|
||||
SaveUserConfigSuccessAction
|
||||
} from '../actions/user-config';
|
||||
|
||||
import { DataStorageRepositoryService } from '../../services/datastorage-repository.service';
|
||||
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
|
||||
import { AppState, getPrevUserConfiguration, getUserConfiguration } from '../index';
|
||||
import { AppState, autoWriteUserConfiguration, getPrevUserConfiguration, getUserConfiguration } from '../index';
|
||||
import { KeymapAction, KeymapActions, MacroAction, MacroActions } from '../actions';
|
||||
import {
|
||||
DismissUndoNotificationAction,
|
||||
LoadHardwareConfigurationSuccessAction,
|
||||
ShowNotificationAction,
|
||||
DismissUndoNotificationAction, LoadHardwareConfigurationSuccessAction, ShowNotificationAction,
|
||||
UndoLastAction
|
||||
} from '../actions/app';
|
||||
import { ShowSaveToKeyboardButtonAction } from '../actions/device';
|
||||
import { SaveConfigurationAction, ShowSaveToKeyboardButtonAction } from '../actions/device';
|
||||
import { DeviceRendererService } from '../../services/device-renderer.service';
|
||||
import { UndoUserConfigData } from '../../models/undo-user-config-data';
|
||||
|
||||
@@ -193,6 +185,18 @@ export class UserConfigEffects {
|
||||
saveAs(blob, 'UserConfiguration.bin');
|
||||
});
|
||||
|
||||
@Effect() loadUserConfigurationSuccess$ = this.actions$
|
||||
.ofType(ActionTypes.SAVE_USER_CONFIG_SUCCESS)
|
||||
.withLatestFrom(this.store.select(autoWriteUserConfiguration))
|
||||
.switchMap(([action, autoWriteUserConfig]) => {
|
||||
if (autoWriteUserConfig) {
|
||||
return Observable.of(new SaveConfigurationAction());
|
||||
}
|
||||
else {
|
||||
return Observable.empty();
|
||||
}
|
||||
});
|
||||
|
||||
constructor(private actions$: Actions,
|
||||
private dataStorageRepository: DataStorageRepositoryService,
|
||||
private store: Store<AppState>,
|
||||
|
||||
@@ -43,6 +43,7 @@ export const getDeviceName = (state: AppState) => state.userConfiguration.device
|
||||
|
||||
export const appState = (state: AppState) => state.app;
|
||||
export const showAddonMenu = createSelector(appState, fromApp.showAddonMenu);
|
||||
export const autoWriteUserConfiguration = createSelector(appState, fromApp.autoWriteUserConfiguration);
|
||||
export const getUndoableNotification = createSelector(appState, fromApp.getUndoableNotification);
|
||||
export const getPrevUserConfiguration = createSelector(appState, fromApp.getPrevUserConfiguration);
|
||||
export const runningInElectron = createSelector(appState, fromApp.runningInElectron);
|
||||
|
||||
@@ -11,6 +11,7 @@ import { KeyboardLayout } from '../../keyboard/keyboard-layout.enum';
|
||||
export interface State {
|
||||
started: boolean;
|
||||
showAddonMenu: boolean;
|
||||
autoWriteUserConfiguration: boolean;
|
||||
undoableNotification?: Notification;
|
||||
navigationCountAfterNotification: number;
|
||||
prevUserConfig?: UserConfiguration;
|
||||
@@ -23,6 +24,7 @@ export interface State {
|
||||
export const initialState: State = {
|
||||
started: false,
|
||||
showAddonMenu: false,
|
||||
autoWriteUserConfiguration: false,
|
||||
navigationCountAfterNotification: 0,
|
||||
runningInElectron: runInElectron(),
|
||||
configLoading: true
|
||||
@@ -37,10 +39,11 @@ export function reducer(state = initialState, action: Action & { payload: any })
|
||||
};
|
||||
}
|
||||
|
||||
case ActionTypes.APP_TOGGLE_ADDON_MENU: {
|
||||
case ActionTypes.APPLY_COMMAND_LINE_ARGS: {
|
||||
return {
|
||||
...state,
|
||||
showAddonMenu: action.payload
|
||||
showAddonMenu: action.payload.addons,
|
||||
autoWriteUserConfiguration: action.payload.autoWriteConfig
|
||||
};
|
||||
}
|
||||
|
||||
@@ -124,6 +127,7 @@ export function reducer(state = initialState, action: Action & { payload: any })
|
||||
}
|
||||
|
||||
export const showAddonMenu = (state: State) => state.showAddonMenu;
|
||||
export const autoWriteUserConfiguration = (state: State) => state.autoWriteUserConfiguration;
|
||||
export const getUndoableNotification = (state: State) => state.undoableNotification;
|
||||
export const getPrevUserConfiguration = (state: State) => state.prevUserConfig;
|
||||
export const runningInElectron = (state: State) => state.runningInElectron;
|
||||
|
||||
Reference in New Issue
Block a user