app/src/app/app.component.ts
crusader 3a0a72aca4 ing
2018-10-11 17:32:00 +09:00

101 lines
2.7 KiB
TypeScript

import { Component, OnInit, OnDestroy, ChangeDetectorRef, AfterContentInit, AfterViewInit } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { of, Subscription } from 'rxjs';
import { map, catchError, take } from 'rxjs/operators';
import { ElectronProxyService } from './service/electron-proxy.service';
import { MenuEvent } from '../commons/type';
import * as AppStore from './store/app';
import * as UserStore from './store/environment/user';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, AfterContentInit, AfterViewInit, OnDestroy {
title = 'scanner-app';
showTitleBar: boolean;
block: boolean;
menuSubscription: Subscription;
displayAbout: boolean;
displayExportJPEG: boolean;
displayExportPNG: boolean;
displayExportSVG: boolean;
displayPreferences: boolean;
displayPrint: boolean;
public constructor(
private changeDetector: ChangeDetectorRef,
private store: Store<any>,
private electronProxyService: ElectronProxyService,
) {
// this.showTitleBar = !__LINUX__;
this.showTitleBar = false;
this.block = false;
}
ngOnInit(): void {
this.store.dispatch(new AppStore.AppInit());
this.store.dispatch(new UserStore.SetMemberID({ memberID: 'scannerUser' }));
// this.probeService.connect();
this.electronProxyService.sendReady(performance.now());
this.menuSubscription = this.electronProxyService.menuObservable()
.pipe(
map((name: MenuEvent) => {
switch (name) {
case 'show-about':
this.displayAbout = true;
break;
case 'show-export-jpeg':
this.displayExportJPEG = true;
break;
case 'show-export-png':
this.displayExportPNG = true;
break;
case 'show-export-svg':
this.displayExportSVG = true;
break;
case 'show-preferences':
this.displayPreferences = true;
break;
case 'show-print':
this.displayPrint = true;
break;
default:
break;
}
this.changeDetector.detectChanges();
}),
catchError(error => {
return of();
}),
)
.subscribe();
}
ngAfterContentInit(): void {
this.store.dispatch(new AppStore.AppAfterContentInit());
}
ngAfterViewInit(): void {
this.store.dispatch(new AppStore.AppAfterViewInit());
}
ngOnDestroy(): void {
this.store.dispatch(new AppStore.AppDestroy());
this.menuSubscription.unsubscribe();
}
// onMenuClosed(event) {
// this.changeDetector.markForCheck();
// }
}