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

@@ -32,7 +32,7 @@
</li>
</ul>
</li>
<li class="sidebar__level-1--item">
<li class="sidebar__level-1--item" *ngIf="showAddonMenu$ | async">
<div class="sidebar__level-1">
<i class="fa fa-puzzle-piece"></i> Add-on modules
<i class="fa fa-chevron-up pull-right" (click)="toggleHide($event, 'addon')"></i>

View File

@@ -12,7 +12,7 @@ import { runInElectron } from '../../util/index';
import { Keymap } from '../../config-serializer/config-items/keymap';
import { Macro } from '../../config-serializer/config-items/macro';
import { AppState } from '../../store';
import { AppState, showAddonMenu } from '../../store';
import { MacroActions } from '../../store/actions';
import { getKeymaps, getMacros } from '../../store/reducers/user-configuration';
@@ -33,6 +33,7 @@ import { getKeymaps, getMacros } from '../../store/reducers/user-configuration';
styleUrls: ['./side-menu.component.scss']
})
export class SideMenuComponent {
showAddonMenu$: Observable<boolean>;
runInElectron = runInElectron();
private keymaps$: Observable<Keymap[]>;
@@ -57,6 +58,8 @@ export class SideMenuComponent {
.do((macros: Macro[]) => {
macros.sort((first: Macro, second: Macro) => first.name.localeCompare(second.name));
});
this.showAddonMenu$ = this.store.select(showAddonMenu);
}
toggleHide(event: Event, type: string) {

View File

@@ -0,0 +1,3 @@
export interface CommandLineArgs {
addons: boolean;
}

View File

@@ -2,6 +2,7 @@ import { Action } from '@ngrx/store';
import { type } from '../../util';
import { Notification } from '../../models/notification';
import { CommandLineArgs } from '../../models/command-line-args';
const PREFIX = '[app] ';
@@ -9,7 +10,9 @@ const PREFIX = '[app] ';
export const ActionTypes = {
APP_BOOTSRAPPED: type(PREFIX + 'bootstrapped'),
APP_STARTED: type(PREFIX + 'started'),
APP_SHOW_NOTIFICATION: type(PREFIX + 'show notification')
APP_SHOW_NOTIFICATION: type(PREFIX + 'show notification'),
APP_TOGGLE_ADDON_MENU: type(PREFIX + 'toggle add-on menu'),
APP_PROCESS_COMMAND_LINE_ARGS: type(PREFIX + 'process command line args')
};
export class AppBootsrappedAction implements Action {
@@ -26,7 +29,21 @@ export class ShowNotificationAction implements Action {
constructor(public payload: Notification) { }
}
export class ToggleAddonMenuAction implements Action {
type = ActionTypes.APP_TOGGLE_ADDON_MENU;
constructor(public payload: boolean) { }
}
export class ProcessCommandLineArgsAction implements Action {
type = ActionTypes.APP_PROCESS_COMMAND_LINE_ARGS;
constructor(public payload: CommandLineArgs) { }
}
export type Actions
= AppStartedAction
| AppBootsrappedAction
| ShowNotificationAction;
| ShowNotificationAction
| ToggleAddonMenuAction
| ProcessCommandLineArgsAction;

View File

@@ -7,8 +7,9 @@ import { NotifierService } from 'angular-notifier';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import { ActionTypes } from '../actions/app.action';
import { ActionTypes, ToggleAddonMenuAction } from '../actions/app.action';
import { Notification, NotificationType } from '../../models/notification';
import { CommandLineArgs } from '../../models/command-line-args';
@Injectable()
export class ApplicationEffects {
@@ -22,6 +23,12 @@ export class ApplicationEffects {
this.notifierService.notify(type, notification.message);
});
@Effect()
processCommandLineArgs: Observable<Action> = this.actions$
.ofType(ActionTypes.APP_PROCESS_COMMAND_LINE_ARGS)
.map(toPayload)
.map((args: CommandLineArgs) => new ToggleAddonMenuAction(args.addons || false));
// TODO: Change typescript -> 2.4 and use string enum.
// Corrently ngrx store is not compatible witn typescript 2.4
private static mapNotificationType(type: NotificationType): string {

View File

@@ -1,18 +1,25 @@
import { createSelector } from 'reselect';
import { RouterState } from '@ngrx/router-store';
import { Keymap } from '../config-serializer/config-items/keymap';
import { UserConfiguration } from '../config-serializer/config-items/user-configuration';
import * as autoUpdate from './reducers/auto-update-settings';
import * as fromApp from './reducers/app.reducer';
// State interface for the application
export interface AppState {
userConfiguration: UserConfiguration;
presetKeymaps: Keymap[];
autoUpdateSettings: autoUpdate.State;
app: fromApp.State;
router: RouterState;
}
export const getUserConfiguration = (state: AppState) => state.userConfiguration;
export const appState = (state: AppState) => state.app;
export const showAddonMenu = createSelector(appState, fromApp.showAddonMenu);
export const appUpdateState = (state: AppState) => state.autoUpdateSettings;
export const getAutoUpdateSettings = createSelector(appUpdateState, autoUpdate.getUpdateSettings);

View File

@@ -0,0 +1,30 @@
import { Action } from '@ngrx/store';
import { ActionTypes } from '../actions/app.action';
export interface State {
started: boolean;
showAddonMenu: boolean;
}
const initialState: State = {
started: false,
showAddonMenu: false
};
export function reducer(state = initialState, action: Action) {
switch (action.type) {
case ActionTypes.APP_STARTED: {
return Object.assign({ ...state }, { started: true });
}
case ActionTypes.APP_TOGGLE_ADDON_MENU: {
return Object.assign({ ...state }, { showAddonMenu: action.payload });
}
default:
return state;
}
}
export const showAddonMenu = (state: State) => state.showAddonMenu;

View File

@@ -3,13 +3,15 @@ import { routerReducer } from '@ngrx/router-store';
import userConfigurationReducer from './user-configuration';
import presetReducer from './preset';
import { reducer as autoUpdateReducer } from './auto-update-settings';
import { reducer as appReducer } from './app.reducer';
export { userConfigurationReducer, presetReducer, autoUpdateReducer };
export { userConfigurationReducer, presetReducer, autoUpdateReducer, appReducer };
// All reducers that are used in application
export const reducer = {
userConfiguration: userConfigurationReducer,
presetKeymaps: presetReducer,
router: routerReducer,
autoUpdateSettings: autoUpdateReducer
autoUpdateSettings: autoUpdateReducer,
app: appReducer
};

View File

@@ -1,5 +1,7 @@
class App {
public static readonly appStarted = 'app-started';
public static readonly getCommandLineArgs = 'app-get-command-line-args';
public static readonly getCommandLineArgsReply = 'app-get-command-line-args-reply';
}
class AutoUpdate {