feat(app): Show add-on menu if start app with --addons arg (#359)

* refactor(store): Move app reducer from electron to shared module

* feat(app): Show add-on menu if start app with --addons arg

close: #351
This commit is contained in:
Róbert Kiss
2017-07-18 09:46:55 +02:00
committed by László Monda
parent 25257132a6
commit a4d41f36d5
18 changed files with 649 additions and 3536 deletions

View File

@@ -107,6 +107,7 @@ import { reducer } from './store';
import { AutoUpdateSettings } from './shared/components/auto-update-settings/auto-update-settings';
import { angularNotifierConfig } from './shared/models/angular-notifier-config';
import { UhkHeader } from './shared/components/uhk-header/uhk-header';
import { AppRendererService } from './services/app-renderer.service';
@NgModule({
declarations: [
@@ -210,8 +211,8 @@ import { UhkHeader } from './shared/components/uhk-header/uhk-header';
AppUpdateRendererService,
UhkHidApiService,
UhkLibUsbApiService,
uhkDeviceProvider()
uhkDeviceProvider(),
AppRendererService
],
bootstrap: [AppComponent]
})

View File

@@ -0,0 +1 @@
declare module 'command-line-args';

View File

@@ -1,4 +1,5 @@
/// <reference path="./custom_types/electron-is-dev.d.ts"/>
/// <reference path="./custom_types/command-line-args.d.ts"/>
import { app, BrowserWindow, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
@@ -8,9 +9,17 @@ import { ProgressInfo } from 'electron-builder-http/out/ProgressCallbackTransfor
import { VersionInfo } from 'electron-builder-http/out/publishOptions';
import * as settings from 'electron-settings';
import * as isDev from 'electron-is-dev';
import * as commandLineArgs from 'command-line-args';
import { IpcEvents } from './shared/util';
import { ElectronDataStorageRepositoryService } from './services/electron-datastorage-repository.service';
import { CommandLineArgs } from './shared/models/command-line-args';
const optionDefinitions = [
{ name: 'addons', type: Boolean, defaultOption: false }
];
const options: CommandLineArgs = commandLineArgs(optionDefinitions);
// import './dev-extension';
require('electron-debug')({ showDevTools: false, enabled: true });
@@ -143,6 +152,8 @@ ipcMain.on(IpcEvents.app.appStarted, () => {
ipcMain.on(IpcEvents.autoUpdater.checkForUpdate, () => checkForUpdate());
ipcMain.on(IpcEvents.app.getCommandLineArgs, (event: any) => event.sender.send(IpcEvents.app.getCommandLineArgsReply, options));
function isFirstRun() {
if (!settings.has('firstRunVersion')) {
return true;

View File

@@ -0,0 +1,30 @@
import { Injectable, NgZone } from '@angular/core';
import { Action, Store } from '@ngrx/store';
import { ipcRenderer } from 'electron';
import { IpcEvents } from '../shared/util';
import { AppState } from '../store';
import { CommandLineArgs } from '../shared/models/command-line-args';
import { ProcessCommandLineArgsAction } from '../../../shared/src/store/actions/app.action';
@Injectable()
export class AppRendererService {
constructor(private store: Store<AppState>,
private zone: NgZone) {
this.registerEvents();
}
getCommandLineArgs() {
ipcRenderer.send(IpcEvents.app.getCommandLineArgs);
}
private registerEvents() {
ipcRenderer.on(IpcEvents.app.getCommandLineArgsReply, (event: string, arg: CommandLineArgs) => {
this.dispachStoreAction(new ProcessCommandLineArgsAction(arg));
});
}
private dispachStoreAction(action: Action) {
this.zone.run(() => this.store.dispatch(action));
}
}

View File

@@ -6,6 +6,7 @@ import 'rxjs/add/operator/do';
import * as app from '../../shared/store/actions/app.action';
import { AppUpdateRendererService } from '../../services/app-update-renderer.service';
import { AppRendererService } from '../../services/app-renderer.service';
@Injectable()
export class ApplicationEffect {
@@ -13,12 +14,13 @@ export class ApplicationEffect {
appStart$: Observable<Action> = this.actions$
.ofType(app.ActionTypes.APP_BOOTSRAPPED)
.startWith(new app.AppStartedAction())
.delay(3000) // wait 3 sec to mainRenderer subscribe all events
.do(() => {
this.appUpdateRendererService.sendAppStarted();
this.appRendererService.getCommandLineArgs();
});
constructor(
private actions$: Actions,
private appUpdateRendererService: AppUpdateRendererService) { }
private appUpdateRendererService: AppUpdateRendererService,
private appRendererService: AppRendererService) { }
}

View File

@@ -3,26 +3,19 @@ import { createSelector } from 'reselect';
import { compose } from '@ngrx/core/compose';
import { storeFreeze } from 'ngrx-store-freeze';
import { ActionReducer, combineReducers } from '@ngrx/store';
import { routerReducer } from '@ngrx/router-store';
import * as isDev from 'electron-is-dev';
import { AppState as CommonState } from '../shared/store';
import * as fromApp from './reducers/app.reducer';
import * as fromAppUpdate from './reducers/app-update.reducer';
import { autoUpdateReducer, presetReducer, userConfigurationReducer } from '../shared/store/reducers';
import { reducer as CommonReducer } from '../shared/store/reducers';
export interface AppState extends CommonState {
app: fromApp.State;
appUpdate: fromAppUpdate.State;
}
const reducers = {
userConfiguration: userConfigurationReducer,
presetKeymaps: presetReducer,
router: routerReducer,
app: fromApp.reducer,
appUpdate: fromAppUpdate.reducer,
autoUpdateSettings: autoUpdateReducer
...CommonReducer,
appUpdate: fromAppUpdate.reducer
};
const developmentReducer: ActionReducer<AppState> = compose(storeFreeze, combineReducers)(reducers);

View File

@@ -1,21 +0,0 @@
import { Actions, ActionTypes } from '../../shared/store/actions/app.action';
export interface State {
started: boolean;
}
const initialState: State = {
started: false
};
export function reducer(state = initialState, action: Actions) {
switch (action.type) {
case ActionTypes.APP_STARTED: {
const newState = Object.assign({}, state);
newState.started = true;
return newState;
}
default:
return state;
}
}