Skip to content

Commit a4d41f3

Browse files
ert78gbmondalaci
authored andcommitted
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
1 parent 2525713 commit a4d41f3

File tree

18 files changed

+649
-3536
lines changed

18 files changed

+649
-3536
lines changed

electron/src/app.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import { reducer } from './store';
107107
import { AutoUpdateSettings } from './shared/components/auto-update-settings/auto-update-settings';
108108
import { angularNotifierConfig } from './shared/models/angular-notifier-config';
109109
import { UhkHeader } from './shared/components/uhk-header/uhk-header';
110+
import { AppRendererService } from './services/app-renderer.service';
110111

111112
@NgModule({
112113
declarations: [
@@ -210,8 +211,8 @@ import { UhkHeader } from './shared/components/uhk-header/uhk-header';
210211
AppUpdateRendererService,
211212
UhkHidApiService,
212213
UhkLibUsbApiService,
213-
uhkDeviceProvider()
214-
214+
uhkDeviceProvider(),
215+
AppRendererService
215216
],
216217
bootstrap: [AppComponent]
217218
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'command-line-args';

electron/src/electron-main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference path="./custom_types/electron-is-dev.d.ts"/>
2+
/// <reference path="./custom_types/command-line-args.d.ts"/>
23

34
import { app, BrowserWindow, ipcMain } from 'electron';
45
import { autoUpdater } from 'electron-updater';
@@ -8,9 +9,17 @@ import { ProgressInfo } from 'electron-builder-http/out/ProgressCallbackTransfor
89
import { VersionInfo } from 'electron-builder-http/out/publishOptions';
910
import * as settings from 'electron-settings';
1011
import * as isDev from 'electron-is-dev';
12+
import * as commandLineArgs from 'command-line-args';
1113

1214
import { IpcEvents } from './shared/util';
1315
import { ElectronDataStorageRepositoryService } from './services/electron-datastorage-repository.service';
16+
import { CommandLineArgs } from './shared/models/command-line-args';
17+
18+
const optionDefinitions = [
19+
{ name: 'addons', type: Boolean, defaultOption: false }
20+
];
21+
22+
const options: CommandLineArgs = commandLineArgs(optionDefinitions);
1423

1524
// import './dev-extension';
1625
require('electron-debug')({ showDevTools: false, enabled: true });
@@ -143,6 +152,8 @@ ipcMain.on(IpcEvents.app.appStarted, () => {
143152

144153
ipcMain.on(IpcEvents.autoUpdater.checkForUpdate, () => checkForUpdate());
145154

155+
ipcMain.on(IpcEvents.app.getCommandLineArgs, (event: any) => event.sender.send(IpcEvents.app.getCommandLineArgsReply, options));
156+
146157
function isFirstRun() {
147158
if (!settings.has('firstRunVersion')) {
148159
return true;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Injectable, NgZone } from '@angular/core';
2+
import { Action, Store } from '@ngrx/store';
3+
import { ipcRenderer } from 'electron';
4+
5+
import { IpcEvents } from '../shared/util';
6+
import { AppState } from '../store';
7+
import { CommandLineArgs } from '../shared/models/command-line-args';
8+
import { ProcessCommandLineArgsAction } from '../../../shared/src/store/actions/app.action';
9+
10+
@Injectable()
11+
export class AppRendererService {
12+
constructor(private store: Store<AppState>,
13+
private zone: NgZone) {
14+
this.registerEvents();
15+
}
16+
17+
getCommandLineArgs() {
18+
ipcRenderer.send(IpcEvents.app.getCommandLineArgs);
19+
}
20+
21+
private registerEvents() {
22+
ipcRenderer.on(IpcEvents.app.getCommandLineArgsReply, (event: string, arg: CommandLineArgs) => {
23+
this.dispachStoreAction(new ProcessCommandLineArgsAction(arg));
24+
});
25+
}
26+
27+
private dispachStoreAction(action: Action) {
28+
this.zone.run(() => this.store.dispatch(action));
29+
}
30+
}

electron/src/store/effects/app.effect.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ import 'rxjs/add/operator/do';
66

77
import * as app from '../../shared/store/actions/app.action';
88
import { AppUpdateRendererService } from '../../services/app-update-renderer.service';
9+
import { AppRendererService } from '../../services/app-renderer.service';
910

1011
@Injectable()
1112
export class ApplicationEffect {
1213
@Effect()
1314
appStart$: Observable<Action> = this.actions$
1415
.ofType(app.ActionTypes.APP_BOOTSRAPPED)
1516
.startWith(new app.AppStartedAction())
16-
.delay(3000) // wait 3 sec to mainRenderer subscribe all events
1717
.do(() => {
1818
this.appUpdateRendererService.sendAppStarted();
19+
this.appRendererService.getCommandLineArgs();
1920
});
2021

2122
constructor(
2223
private actions$: Actions,
23-
private appUpdateRendererService: AppUpdateRendererService) { }
24+
private appUpdateRendererService: AppUpdateRendererService,
25+
private appRendererService: AppRendererService) { }
2426
}

electron/src/store/index.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,19 @@ import { createSelector } from 'reselect';
33
import { compose } from '@ngrx/core/compose';
44
import { storeFreeze } from 'ngrx-store-freeze';
55
import { ActionReducer, combineReducers } from '@ngrx/store';
6-
import { routerReducer } from '@ngrx/router-store';
76
import * as isDev from 'electron-is-dev';
87

98
import { AppState as CommonState } from '../shared/store';
10-
import * as fromApp from './reducers/app.reducer';
119
import * as fromAppUpdate from './reducers/app-update.reducer';
12-
import { autoUpdateReducer, presetReducer, userConfigurationReducer } from '../shared/store/reducers';
10+
import { reducer as CommonReducer } from '../shared/store/reducers';
1311

1412
export interface AppState extends CommonState {
15-
app: fromApp.State;
1613
appUpdate: fromAppUpdate.State;
1714
}
1815

1916
const reducers = {
20-
userConfiguration: userConfigurationReducer,
21-
presetKeymaps: presetReducer,
22-
router: routerReducer,
23-
app: fromApp.reducer,
24-
appUpdate: fromAppUpdate.reducer,
25-
autoUpdateSettings: autoUpdateReducer
17+
...CommonReducer,
18+
appUpdate: fromAppUpdate.reducer
2619
};
2720

2821
const developmentReducer: ActionReducer<AppState> = compose(storeFreeze, combineReducers)(reducers);

electron/src/store/reducers/app.reducer.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)