refactor(auto-update): Show notification messages with the angular-notifier (#334)
* refactor(log): Refactor logging service Removed the InjectionToken and changed LogService as default logger. Finally ElectronLogService implements LogService directly. * refactor: Optimize imports * fix(app-update): Add missing rxjs imports * style: Remove extra line * refactor(store): Move app.actions.ts to shared module * feat(notification): Add notification panel Add angular-notifier to the app and created the ShowNotificationAction to manage notifications * style(notification): Fix tslint suggestion * fix(notification): Add missing rxjs imports * refactor(app-update): Refactor app-update notification * fix(auto-update): Add missing rxjs imports
This commit is contained in:
committed by
László Monda
parent
c9a1e9853c
commit
f7212320e6
@@ -3,7 +3,7 @@ import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
|
||||
import { AppState, getShowAppUpdateAvailable } from '../store';
|
||||
import { DoNotUpdateAppAction, UpdateAppAction } from '../store/actions/app-update.action';
|
||||
import { DoNotUpdateAppAction, UpdateAppAction } from '../shared/store/actions/app-update.action';
|
||||
|
||||
@Component({
|
||||
selector: 'app',
|
||||
|
||||
@@ -121,8 +121,8 @@ autoUpdater.on('update-not-available', (ev: any, info: VersionInfo) => {
|
||||
sendIpcToWindow(IpcEvents.autoUpdater.updateNotAvailable, info);
|
||||
});
|
||||
|
||||
autoUpdater.on('error', (ev: any, err: Error) => {
|
||||
sendIpcToWindow(IpcEvents.autoUpdater.autoUpdateError, err);
|
||||
autoUpdater.on('error', (ev: any, err: string) => {
|
||||
sendIpcToWindow(IpcEvents.autoUpdater.autoUpdateError, err.substr(0, 100));
|
||||
});
|
||||
|
||||
autoUpdater.on('download-progress', (progressObj: ProgressInfo) => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ipcRenderer } from 'electron';
|
||||
|
||||
import { IpcEvents } from '../shared/util';
|
||||
import { AppState } from '../store';
|
||||
import { UpdateDownloadedAction } from '../store/actions/app-update.action';
|
||||
import { UpdateDownloadedAction, UpdateErrorAction } from '../shared/store/actions/app-update.action';
|
||||
import { CheckForUpdateFailedAction, CheckForUpdateSuccessAction } from '../shared/store/actions/auto-update-settings';
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ export class AppUpdateRendererService {
|
||||
|
||||
ipcRenderer.on(IpcEvents.autoUpdater.autoUpdateError, (event: string, arg: any) => {
|
||||
this.writeUpdateState(IpcEvents.autoUpdater.autoUpdateError, arg);
|
||||
this.dispachStoreAction(new CheckForUpdateFailedAction(arg));
|
||||
this.dispachStoreAction(new UpdateErrorAction(arg));
|
||||
});
|
||||
|
||||
ipcRenderer.on(IpcEvents.autoUpdater.autoUpdateDownloadProgress, (event: string, arg: any) => {
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
import { type } from '../../shared/util/';
|
||||
|
||||
const PREFIX = '[app-update] ';
|
||||
|
||||
// tslint:disable-next-line:variable-name
|
||||
export const ActionTypes = {
|
||||
UPDATE_AVAILABLE: type(PREFIX + 'update available'),
|
||||
UPDATE_APP: type(PREFIX + 'update app'),
|
||||
DO_NOT_UPDATE_APP: type(PREFIX + 'do not update app'),
|
||||
UPDATE_DOWNLOADED: type(PREFIX + 'update downloaded'),
|
||||
UPDATING: type(PREFIX + 'updating')
|
||||
};
|
||||
|
||||
export class UpdateAvailableAction implements Action {
|
||||
type = ActionTypes.UPDATE_AVAILABLE;
|
||||
}
|
||||
|
||||
export class UpdateAppAction implements Action {
|
||||
type = ActionTypes.UPDATE_APP;
|
||||
}
|
||||
|
||||
export class DoNotUpdateAppAction implements Action {
|
||||
type = ActionTypes.DO_NOT_UPDATE_APP;
|
||||
}
|
||||
|
||||
export class UpdateDownloadedAction implements Action {
|
||||
type = ActionTypes.UPDATE_DOWNLOADED;
|
||||
}
|
||||
|
||||
export class UpdatingAction implements Action {
|
||||
type = ActionTypes.UPDATING;
|
||||
}
|
||||
|
||||
export type Actions
|
||||
= UpdateAvailableAction
|
||||
| UpdateAppAction
|
||||
| DoNotUpdateAppAction
|
||||
| UpdateDownloadedAction
|
||||
| UpdatingAction;
|
||||
@@ -1,13 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Action } from '@ngrx/store';
|
||||
import { Actions, Effect } from '@ngrx/effects';
|
||||
import { Actions, Effect, toPayload } from '@ngrx/effects';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import 'rxjs/add/operator/do';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/first';
|
||||
|
||||
import { ActionTypes } from '../actions/app-update.action';
|
||||
import { ActionTypes } from '../../shared/store/actions/app-update.action';
|
||||
import { ActionTypes as AutoUpdateActionTypes } from '../../shared/store/actions/auto-update-settings';
|
||||
import { AppUpdateRendererService } from '../../services/app-update-renderer.service';
|
||||
import { NotificationType } from '../../shared/models/notification';
|
||||
import { ShowNotificationAction } from '../../shared/store/actions/app.action';
|
||||
|
||||
@Injectable()
|
||||
export class AppUpdateEffect {
|
||||
@@ -25,6 +29,16 @@ export class AppUpdateEffect {
|
||||
this.appUpdateRendererService.checkForUpdate();
|
||||
});
|
||||
|
||||
@Effect() handleError$: Observable<Action> = this.actions$
|
||||
.ofType(ActionTypes.UPDATE_ERROR)
|
||||
.map(toPayload)
|
||||
.map((message: string) => {
|
||||
return new ShowNotificationAction({
|
||||
type: NotificationType.Error,
|
||||
message
|
||||
});
|
||||
});
|
||||
|
||||
constructor(private actions$: Actions,
|
||||
private appUpdateRendererService: AppUpdateRendererService) {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Actions, ActionTypes } from '../actions/app-update.action';
|
||||
import { Actions, ActionTypes } from '../../shared/store/actions/app-update.action';
|
||||
|
||||
export interface State {
|
||||
updateAvailable: boolean;
|
||||
@@ -19,11 +19,13 @@ export function reducer(state = initialState, action: Actions) {
|
||||
newState.updateAvailable = true;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case ActionTypes.UPDATE_DOWNLOADED: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.updateDownloaded = true;
|
||||
return newState;
|
||||
}
|
||||
|
||||
case ActionTypes.DO_NOT_UPDATE_APP: {
|
||||
const newState = Object.assign({}, state);
|
||||
newState.doNotUpdateApp = true;
|
||||
|
||||
Reference in New Issue
Block a user