ing
This commit is contained in:
parent
2ff4e28720
commit
94f6acabc7
53
@overflow/core/emitter.ts
Normal file
53
@overflow/core/emitter.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { Subject, PartialObserver } from 'rxjs';
|
||||
|
||||
export class Emitter {
|
||||
private subjects: Map<string, Subject<any>>;
|
||||
|
||||
public constructor() {
|
||||
this.subjects = new Map();
|
||||
}
|
||||
|
||||
private static createName(name: string): string {
|
||||
return '$' + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* emit
|
||||
*/
|
||||
public emit(name: string, data?: any) {
|
||||
const fnName = Emitter.createName(name);
|
||||
|
||||
if (!this.subjects.has(fnName)) {
|
||||
this.subjects.set(fnName, new Subject());
|
||||
}
|
||||
|
||||
this.subjects.get(fnName).next(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* listen
|
||||
*/
|
||||
public listen(name: string, handler: (data?: any) => void) {
|
||||
const fnName = Emitter.createName(name);
|
||||
|
||||
if (!this.subjects.has(fnName)) {
|
||||
this.subjects.set(fnName, new Subject());
|
||||
}
|
||||
|
||||
return this.subjects.get(fnName).subscribe(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* dispose
|
||||
*/
|
||||
public dispose() {
|
||||
const _subjects = this.subjects;
|
||||
_subjects.forEach((value: Subject<any>, key: string) => {
|
||||
if (_subjects.has(key)) {
|
||||
_subjects.get(key).unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
this.subjects = new Map();
|
||||
}
|
||||
}
|
|
@ -1,10 +1,21 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ElectronProxyService } from '../commons/service/electron-proxy.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.scss']
|
||||
})
|
||||
export class AppComponent {
|
||||
export class AppComponent implements OnInit {
|
||||
title = 'scanner-app';
|
||||
|
||||
public constructor(
|
||||
private electronProxyService: ElectronProxyService,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.electronProxyService.sendReady(performance.now());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import { CommonsUIModule } from '@overflow/commons/ui/commons-ui.module';
|
|||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
import { CommonsModule } from '../commons/commons.module';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent
|
||||
|
@ -17,6 +19,7 @@ import { AppComponent } from './app.component';
|
|||
BrowserAnimationsModule,
|
||||
|
||||
CommonsUIModule,
|
||||
CommonsModule,
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent]
|
||||
|
|
17
src/commons/commons.module.ts
Normal file
17
src/commons/commons.module.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { NgModule, APP_INITIALIZER } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
|
||||
import { SERVICES } from './service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
],
|
||||
declarations: [
|
||||
],
|
||||
providers: [
|
||||
...SERVICES,
|
||||
]
|
||||
})
|
||||
export class CommonsModule { }
|
17
src/commons/service/electron-proxy.service.ts
Normal file
17
src/commons/service/electron-proxy.service.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
@Injectable()
|
||||
export class ElectronProxyService {
|
||||
|
||||
public constructor(
|
||||
) {
|
||||
}
|
||||
|
||||
public sendReady(time: number): void {
|
||||
ipcRenderer.send('renderer-ready', time);
|
||||
}
|
||||
|
||||
}
|
5
src/commons/service/index.ts
Normal file
5
src/commons/service/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { ElectronProxyService } from './electron-proxy.service';
|
||||
|
||||
export const SERVICES = [
|
||||
ElectronProxyService,
|
||||
];
|
|
@ -1,7 +1,10 @@
|
|||
import { BrowserWindow, ipcMain, Menu, app, dialog } from 'electron';
|
||||
import * as path from 'path';
|
||||
import * as URL from 'url';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import { Subscription, PartialObserver } from 'rxjs';
|
||||
|
||||
import { Emitter } from '@overflow/core/emitter';
|
||||
|
||||
import { encodePathAsUrl } from '@overflow/core/path';
|
||||
import { registerWindowStateChangedEvents } from '@overflow/core/window-state';
|
||||
|
@ -14,7 +17,7 @@ let windowStateKeeper: any | null = null;
|
|||
|
||||
export class AppWindow {
|
||||
private window: Electron.BrowserWindow;
|
||||
private emitter = new EventEmitter();
|
||||
private emitter = new Emitter();
|
||||
|
||||
private _loadTime: number | null = null;
|
||||
private _rendererReadyTime: number | null = null;
|
||||
|
@ -42,7 +45,7 @@ export class AppWindow {
|
|||
height: savedWindowState.height,
|
||||
minWidth: this.minWidth,
|
||||
minHeight: this.minHeight,
|
||||
show: true,
|
||||
show: false,
|
||||
// This fixes subpixel aliasing on Windows
|
||||
// See https://github.com/atom/atom/commit/683bef5b9d133cb194b476938c77cc07fd05b972
|
||||
backgroundColor: '#fff',
|
||||
|
@ -61,11 +64,9 @@ export class AppWindow {
|
|||
} else if (__WIN32__) {
|
||||
windowOptions.frame = false;
|
||||
} else if (__LINUX__) {
|
||||
// windowOptions.icon = path.join(__dirname, 'static', 'icon-logo.png');
|
||||
windowOptions.icon = path.join(__dirname, 'static', 'icon-logo.png');
|
||||
}
|
||||
|
||||
console.log(windowOptions);
|
||||
|
||||
this.window = new BrowserWindow(windowOptions);
|
||||
savedWindowState.manage(this.window);
|
||||
|
||||
|
@ -159,7 +160,7 @@ export class AppWindow {
|
|||
return;
|
||||
}
|
||||
|
||||
this.emitter.emit('did-load', null);
|
||||
this.emitter.emit('did-load');
|
||||
}
|
||||
|
||||
/** Is the page loaded and has the renderer signalled it's ready? */
|
||||
|
@ -175,8 +176,8 @@ export class AppWindow {
|
|||
* Register a function to call when the window is done loading. At that point
|
||||
* the page has loaded and the renderer has signalled that it is ready.
|
||||
*/
|
||||
public onDidLoad(fn: () => void): EventEmitter {
|
||||
return this.emitter.on('did-load', fn);
|
||||
public onDidLoad(fn: (data?: any) => void): Subscription {
|
||||
return this.emitter.listen('did-load', fn);
|
||||
}
|
||||
|
||||
public isMinimized() {
|
||||
|
|
|
@ -48,7 +48,7 @@ process.on('uncaughtException', (error: Error) => {
|
|||
handleUncaughtException(error);
|
||||
});
|
||||
|
||||
let handlingSquirrelEvent = false;
|
||||
const handlingSquirrelEvent = false;
|
||||
// if (__WIN32__ && process.argv.length > 1) {
|
||||
// const arg = process.argv[1];
|
||||
|
||||
|
@ -78,7 +78,7 @@ let handlingSquirrelEvent = false;
|
|||
// });
|
||||
// }
|
||||
|
||||
let isDuplicateInstance = false;
|
||||
const isDuplicateInstance = false;
|
||||
// If we're handling a Squirrel event we don't want to enforce single instance.
|
||||
// We want to let the updated instance launch and do its work. It will then quit
|
||||
// once it's done.
|
||||
|
@ -426,7 +426,7 @@ function createWindow() {
|
|||
}
|
||||
});
|
||||
|
||||
window.onDidLoad(() => {
|
||||
window.onDidLoad((data: any) => {
|
||||
window.show();
|
||||
// window.sendLaunchTimingStats({
|
||||
// mainReadyTime: readyTime!,
|
||||
|
|
Loading…
Reference in New Issue
Block a user