Skip to content

Commit c9a1e98

Browse files
ert78gbmondalaci
authored andcommitted
feat(notification): display app errors, close #319 (#333)
* 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
1 parent 6bc2bc8 commit c9a1e98

21 files changed

+181
-41
lines changed

electron/src/app.module.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ErrorHandler, NgModule } from '@angular/core';
22
import { FormsModule } from '@angular/forms';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5+
import { NotifierModule } from 'angular-notifier';
56

67
import { EffectsModule } from '@ngrx/effects';
78
import { StoreModule } from '@ngrx/store';
@@ -79,7 +80,13 @@ import { UhkLibUsbApiService } from './services/uhk-lib-usb-api.service';
7980
import { UhkHidApiService } from './services/uhk-hid-api.service';
8081
import { uhkDeviceProvider } from './services/uhk-device-provider';
8182

82-
import { AutoUpdateSettingsEffects, KeymapEffects, MacroEffects, UserConfigEffects } from './shared/store/effects';
83+
import {
84+
ApplicationEffects,
85+
AutoUpdateSettingsEffects,
86+
KeymapEffects,
87+
MacroEffects,
88+
UserConfigEffects
89+
} from './shared/store/effects';
8390
import { ApplicationEffect, AppUpdateEffect } from './store/effects';
8491

8592
import { KeymapEditGuard } from './shared/components/keymap/edit';
@@ -93,11 +100,12 @@ import { DATA_STORAGE_REPOSITORY } from './shared/services/datastorage-repositor
93100
import { ElectronDataStorageRepositoryService } from './services/electron-datastorage-repository.service';
94101
import { DefaultUserConfigurationService } from './shared/services/default-user-configuration.service';
95102
import { ElectronLogService } from './services/electron-log.service';
96-
import { LOG_SERVICE } from '../../shared/src/services/logger.service';
103+
import { LogService } from './shared/services/logger.service';
97104
import { ElectronErrorHandlerService } from './services/electron-error-handler.service';
98105
import { AppUpdateRendererService } from './services/app-update-renderer.service';
99106
import { reducer } from './store';
100107
import { AutoUpdateSettings } from './shared/components/auto-update-settings/auto-update-settings';
108+
import { angularNotifierConfig } from '../../shared/src/models/angular-notifier-config';
101109

102110
@NgModule({
103111
declarations: [
@@ -172,12 +180,14 @@ import { AutoUpdateSettings } from './shared/components/auto-update-settings/aut
172180
}),
173181
StoreLogMonitorModule,
174182
Select2Module,
183+
NotifierModule.withConfig(angularNotifierConfig),
175184
EffectsModule.runAfterBootstrap(KeymapEffects),
176185
EffectsModule.runAfterBootstrap(MacroEffects),
177186
EffectsModule.runAfterBootstrap(UserConfigEffects),
178187
EffectsModule.runAfterBootstrap(AutoUpdateSettingsEffects),
179188
EffectsModule.run(ApplicationEffect),
180-
EffectsModule.run(AppUpdateEffect)
189+
EffectsModule.run(AppUpdateEffect),
190+
EffectsModule.run(ApplicationEffects)
181191
],
182192
providers: [
183193
UhkDeviceConnectedGuard,
@@ -192,7 +202,7 @@ import { AutoUpdateSettings } from './shared/components/auto-update-settings/aut
192202
CaptureService,
193203
{ provide: DATA_STORAGE_REPOSITORY, useClass: ElectronDataStorageRepositoryService },
194204
DefaultUserConfigurationService,
195-
{ provide: LOG_SERVICE, useClass: ElectronLogService },
205+
{ provide: LogService, useClass: ElectronLogService },
196206
{ provide: ErrorHandler, useClass: ElectronErrorHandlerService },
197207
AppUpdateRendererService,
198208
UhkHidApiService,

electron/src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
</app-update-available>
66

77
<router-outlet></router-outlet>
8+
<notifier-container></notifier-container>

electron/src/components/privilege-checker/privilege-checker.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as path from 'path';
1515
import * as sudo from 'sudo-prompt';
1616

1717
import { UhkDeviceService } from '../../services/uhk-device.service';
18-
import { ILogService, LOG_SERVICE } from '../../../../shared/src/services/logger.service';
18+
import { LogService } from '../../shared/services/logger.service';
1919

2020
@Component({
2121
selector: 'privilege-checker',
@@ -28,7 +28,7 @@ export class PrivilegeCheckerComponent {
2828

2929
constructor(private router: Router,
3030
private uhkDevice: UhkDeviceService,
31-
@Inject(LOG_SERVICE) private logService: ILogService) {
31+
private logService: LogService) {
3232
if (isDev) {
3333
this.rootDir = path.resolve(path.join(remote.process.cwd(), remote.process.argv[1]), '..');
3434
} else {

electron/src/services/electron-error-handler.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { ErrorHandler, Inject } from '@angular/core';
2-
import { ILogService, LOG_SERVICE } from '../../../shared/src/services/logger.service';
1+
import { ErrorHandler, Injectable } from '@angular/core';
2+
import { LogService} from '../shared/services/logger.service';
33

4+
@Injectable()
45
export class ElectronErrorHandlerService implements ErrorHandler {
5-
constructor(@Inject(LOG_SERVICE)private logService: ILogService) {}
6+
constructor(private logService: LogService) {}
67

78
handleError(error: any) {
89
this.logService.error(error);

electron/src/services/electron-log.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
22
import * as log from 'electron-log';
33
import * as util from 'util';
44

5-
import { ILogService } from '../../../shared/src/services/logger.service';
5+
import { LogService } from '../shared/services/logger.service';
66

77
/**
88
* This service use the electron-log package to write log in file.
@@ -14,7 +14,7 @@ import { ILogService } from '../../../shared/src/services/logger.service';
1414
* The app name: UHK Agent. The up to date value in the scripts/release.js file.
1515
*/
1616
@Injectable()
17-
export class ElectronLogService implements ILogService {
17+
export class ElectronLogService implements LogService {
1818
private static getErrorText(args: any) {
1919
return util.inspect(args);
2020
}

electron/src/services/uhk-device.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Subscriber } from 'rxjs/Subscriber';
66
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
77
import { Subscription } from 'rxjs/Subscription';
88

9-
import { ILogService, LOG_SERVICE } from '../shared/services/logger.service';
9+
import { LogService } from '../shared/services/logger.service';
1010
import { SenderMessage } from '../models/sender-message';
1111
import { Constants } from '../shared/util/constants';
1212

@@ -24,7 +24,7 @@ export abstract class UhkDeviceService {
2424
protected messageIn$: Observable<Buffer>;
2525
protected messageOut$: Subject<SenderMessage>;
2626

27-
constructor(@Inject(LOG_SERVICE) protected logService: ILogService) {
27+
constructor(protected logService: LogService) {
2828
this.messageOut$ = new Subject<SenderMessage>();
2929
this.initialized$ = new BehaviorSubject(false);
3030
this.connected$ = new BehaviorSubject(false);

electron/src/services/uhk-hid-api.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'rxjs/add/operator/concatMap';
1414
import 'rxjs/add/operator/publish';
1515
import 'rxjs/add/operator/do';
1616

17-
import { ILogService, LOG_SERVICE } from '../shared/services/logger.service';
17+
import { LogService } from '../shared/services/logger.service';
1818
import { Constants } from '../shared/util';
1919
import { UhkDeviceService } from './uhk-device.service';
2020

@@ -24,7 +24,7 @@ export class UhkHidApiService extends UhkDeviceService implements OnDestroy {
2424

2525
private pollTimer$: Subscription;
2626

27-
constructor(@Inject(LOG_SERVICE) protected logService: ILogService) {
27+
constructor(protected logService: LogService) {
2828
super(logService);
2929

3030
this.pollUhkDevice();

electron/src/services/uhk-lib-usb-api.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'rxjs/add/operator/do';
1414

1515
import { Device, findByIds, InEndpoint, Interface, on, OutEndpoint } from 'usb';
1616

17-
import { ILogService, LOG_SERVICE } from '../shared/services/logger.service';
17+
import { LogService} from '../shared/services/logger.service';
1818
import { Constants } from '../shared/util';
1919
import { UhkDeviceService } from './uhk-device.service';
2020

@@ -28,7 +28,7 @@ export class UhkLibUsbApiService extends UhkDeviceService implements OnDestroy {
2828
}
2929

3030
constructor(zone: NgZone,
31-
@Inject(LOG_SERVICE) protected logService: ILogService) {
31+
protected logService: LogService) {
3232
super(logService);
3333

3434
this.initialize();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Effect, Actions } from '@ngrx/effects';
44
import { Observable } from 'rxjs/Observable';
55
import 'rxjs/add/operator/do';
66

7-
import * as app from '../actions/app.action';
7+
import * as app from '../../shared/store/actions/app.action';
88
import { AppUpdateRendererService } from '../../services/app-update-renderer.service';
99

1010
@Injectable()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Actions, ActionTypes } from '../actions/app.action';
1+
import { Actions, ActionTypes } from '../../shared/store/actions/app.action';
22

33
export interface State {
44
started: boolean;

0 commit comments

Comments
 (0)