dexie added

This commit is contained in:
crusader 2018-08-17 12:09:37 +09:00
parent 7207b4d32b
commit 71514e2268
13 changed files with 131 additions and 18 deletions

View File

@ -45,6 +45,7 @@
"awesome-typescript-loader": "^5.2.0", "awesome-typescript-loader": "^5.2.0",
"codelyzer": "~4.2.1", "codelyzer": "~4.2.1",
"core-js": "^2.5.4", "core-js": "^2.5.4",
"dexie": "^2.0.4",
"devtron": "^1.4.0", "devtron": "^1.4.0",
"electron": "^2.0.7", "electron": "^2.0.7",
"electron-builder": "^20.27.1", "electron-builder": "^20.27.1",

View File

@ -0,0 +1 @@
export * from './launch-state';

View File

@ -0,0 +1,20 @@
/** The timing stats for app launch. */
export interface LaunchState {
/**
* The time (in milliseconds) it takes from when our main process code is
* first loaded until the app `ready` event is emitted.
*/
readonly mainReadyTime: number
/**
* The time (in milliseconds) it takes from when loading begins to loading
* end.
*/
readonly loadTime: number
/**
* The time (in milliseconds) it takes from when our renderer process code is
* first loaded until the renderer `ready` event is emitted.
*/
readonly rendererReadyTime: number
}

View File

@ -0,0 +1,23 @@
import { Injectable } from '@angular/core';
import Dexie from 'dexie';
import { LaunchState } from '../model';
const DatabaseVersion = 1;
@Injectable({
providedIn: 'root'
})
export class DatabaseService extends Dexie {
public launches!: Dexie.Table<LaunchState, number>
public constructor() {
super('overflow-scanner');
this.version(1).stores({
launches: '++',
});
}
}

View File

@ -1,13 +1,48 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable, of } from 'rxjs';
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
@Injectable() import { MenuEvent } from '../type';
import { LaunchState } from '../model';
import { LaunchService } from './launch.service';
@Injectable({
providedIn: 'root'
})
export class ElectronProxyService { export class ElectronProxyService {
public constructor( public constructor(
private store: Store<any>,
private launchService: LaunchService,
) { ) {
this.bindIPCRenderer();
}
private bindIPCRenderer(): void {
ipcRenderer.on('menu-event',
(event: Electron.IpcMessageEvent, { name }: { name: MenuEvent }) => {
}
);
ipcRenderer.on('launch-timing-stats',
(event: Electron.IpcMessageEvent, { state }: { state: LaunchState }) => {
console.info(`App ready time: ${state.mainReadyTime}ms`)
console.info(`Load time: ${state.loadTime}ms`)
console.info(`Renderer ready time: ${state.rendererReadyTime}ms`)
this.launchService.save(state).pipe(
map((id: number) => {
}),
catchError(error => {
return of();
}),
take(1),
).subscribe();
}
)
} }
public sendReady(time: number): void { public sendReady(time: number): void {

View File

@ -1,5 +1,9 @@
import { DatabaseService } from './database.service';
import { ElectronProxyService } from './electron-proxy.service'; import { ElectronProxyService } from './electron-proxy.service';
import { LaunchService } from './launch.service';
export const SERVICES = [ export const SERVICES = [
DatabaseService,
ElectronProxyService, ElectronProxyService,
LaunchService,
]; ];

View File

@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';
import { Observable, defer } from 'rxjs';
import { DatabaseService } from './database.service';
import { LaunchState } from '../model';
@Injectable({
providedIn: 'root'
})
export class LaunchService {
public constructor(
private readonly databaseService: DatabaseService,
) {
}
public save(launchState: LaunchState): Observable<number> {
return defer(async () => {
return await this.databaseService.launches.add(launchState);
});
}
}

View File

@ -11,7 +11,8 @@ import { registerWindowStateChangedEvents } from '@overflow/core/window-state';
import { URLActionType } from '@overflow/core/parse-app-url'; import { URLActionType } from '@overflow/core/parse-app-url';
import { now } from '@overflow/core/now'; import { now } from '@overflow/core/now';
import { MenuEvent } from './menu'; import { MenuEvent } from '../commons/type';
import { LaunchState } from '../commons/model';
let windowStateKeeper: any | null = null; let windowStateKeeper: any | null = null;
@ -217,9 +218,9 @@ export class AppWindow {
} }
/** Send the app launch timing stats to the renderer. */ /** Send the app launch timing stats to the renderer. */
// public sendLaunchTimingStats(stats: ILaunchStats) { public sendLaunchTimingStats(state: LaunchState) {
// this.window.webContents.send('launch-timing-stats', { stats }); this.window.webContents.send('launch-timing-stats', { state });
// } }
/** Send the app menu to the renderer. */ /** Send the app menu to the renderer. */
// public sendAppMenu() { // public sendAppMenu() {

View File

@ -27,7 +27,7 @@ let readyTime: number | null = null;
type OnDidLoadFn = (window: AppWindow) => void; type OnDidLoadFn = (window: AppWindow) => void;
/** See the `onDidLoad` function. */ /** See the `onDidLoad` function. */
const onDidLoadFns: Array<OnDidLoadFn> | null = []; let onDidLoadFns: Array<OnDidLoadFn> | null = [];
function handleUncaughtException(error: Error) { function handleUncaughtException(error: Error) {
preventQuit = true; preventQuit = true;
@ -428,17 +428,17 @@ function createWindow() {
window.onDidLoad((data: any) => { window.onDidLoad((data: any) => {
window.show(); window.show();
// window.sendLaunchTimingStats({ window.sendLaunchTimingStats({
// mainReadyTime: readyTime!, mainReadyTime: readyTime!,
// loadTime: window.loadTime!, loadTime: window.loadTime!,
// rendererReadyTime: window.rendererReadyTime!, rendererReadyTime: window.rendererReadyTime!,
// }); });
// const fns = onDidLoadFns!; let fns = onDidLoadFns!;
// onDidLoadFns = null; onDidLoadFns = null;
// for (const fn of fns) { for (const fn of fns) {
// fn(window); fn(window);
// } }
}); });
window.load(); window.load();

View File

@ -1969,6 +1969,10 @@ devtron@^1.4.0:
highlight.js "^9.3.0" highlight.js "^9.3.0"
humanize-plus "^1.8.1" humanize-plus "^1.8.1"
dexie@^2.0.4:
version "2.0.4"
resolved "https://nexus.loafle.net/repository/npm-all/dexie/-/dexie-2.0.4.tgz#6027a5e05879424e8f9979d8c14e7420f27e3a11"
di@^0.0.1: di@^0.0.1:
version "0.0.1" version "0.0.1"
resolved "https://nexus.loafle.net/repository/npm-all/di/-/di-0.0.1.tgz#806649326ceaa7caa3306d75d985ea2748ba913c" resolved "https://nexus.loafle.net/repository/npm-all/di/-/di-0.0.1.tgz#806649326ceaa7caa3306d75d985ea2748ba913c"