dexie added
This commit is contained in:
parent
7207b4d32b
commit
71514e2268
|
@ -45,6 +45,7 @@
|
|||
"awesome-typescript-loader": "^5.2.0",
|
||||
"codelyzer": "~4.2.1",
|
||||
"core-js": "^2.5.4",
|
||||
"dexie": "^2.0.4",
|
||||
"devtron": "^1.4.0",
|
||||
"electron": "^2.0.7",
|
||||
"electron-builder": "^20.27.1",
|
||||
|
|
1
src/commons/model/index.ts
Normal file
1
src/commons/model/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './launch-state';
|
20
src/commons/model/launch-state.ts
Normal file
20
src/commons/model/launch-state.ts
Normal 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
|
||||
}
|
23
src/commons/service/database.service.ts
Normal file
23
src/commons/service/database.service.ts
Normal 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: '++',
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,48 @@
|
|||
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';
|
||||
|
||||
@Injectable()
|
||||
import { MenuEvent } from '../type';
|
||||
import { LaunchState } from '../model';
|
||||
import { LaunchService } from './launch.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ElectronProxyService {
|
||||
|
||||
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 {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import { DatabaseService } from './database.service';
|
||||
import { ElectronProxyService } from './electron-proxy.service';
|
||||
import { LaunchService } from './launch.service';
|
||||
|
||||
export const SERVICES = [
|
||||
DatabaseService,
|
||||
ElectronProxyService,
|
||||
LaunchService,
|
||||
];
|
||||
|
|
24
src/commons/service/launch.service.ts
Normal file
24
src/commons/service/launch.service.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,8 @@ import { registerWindowStateChangedEvents } from '@overflow/core/window-state';
|
|||
import { URLActionType } from '@overflow/core/parse-app-url';
|
||||
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;
|
||||
|
||||
|
@ -217,9 +218,9 @@ export class AppWindow {
|
|||
}
|
||||
|
||||
/** Send the app launch timing stats to the renderer. */
|
||||
// public sendLaunchTimingStats(stats: ILaunchStats) {
|
||||
// this.window.webContents.send('launch-timing-stats', { stats });
|
||||
// }
|
||||
public sendLaunchTimingStats(state: LaunchState) {
|
||||
this.window.webContents.send('launch-timing-stats', { state });
|
||||
}
|
||||
|
||||
/** Send the app menu to the renderer. */
|
||||
// public sendAppMenu() {
|
||||
|
|
|
@ -27,7 +27,7 @@ let readyTime: number | null = null;
|
|||
|
||||
type OnDidLoadFn = (window: AppWindow) => void;
|
||||
/** See the `onDidLoad` function. */
|
||||
const onDidLoadFns: Array<OnDidLoadFn> | null = [];
|
||||
let onDidLoadFns: Array<OnDidLoadFn> | null = [];
|
||||
|
||||
function handleUncaughtException(error: Error) {
|
||||
preventQuit = true;
|
||||
|
@ -428,17 +428,17 @@ function createWindow() {
|
|||
|
||||
window.onDidLoad((data: any) => {
|
||||
window.show();
|
||||
// window.sendLaunchTimingStats({
|
||||
// mainReadyTime: readyTime!,
|
||||
// loadTime: window.loadTime!,
|
||||
// rendererReadyTime: window.rendererReadyTime!,
|
||||
// });
|
||||
window.sendLaunchTimingStats({
|
||||
mainReadyTime: readyTime!,
|
||||
loadTime: window.loadTime!,
|
||||
rendererReadyTime: window.rendererReadyTime!,
|
||||
});
|
||||
|
||||
// const fns = onDidLoadFns!;
|
||||
// onDidLoadFns = null;
|
||||
// for (const fn of fns) {
|
||||
// fn(window);
|
||||
// }
|
||||
let fns = onDidLoadFns!;
|
||||
onDidLoadFns = null;
|
||||
for (const fn of fns) {
|
||||
fn(window);
|
||||
}
|
||||
});
|
||||
|
||||
window.load();
|
||||
|
|
|
@ -1969,6 +1969,10 @@ devtron@^1.4.0:
|
|||
highlight.js "^9.3.0"
|
||||
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:
|
||||
version "0.0.1"
|
||||
resolved "https://nexus.loafle.net/repository/npm-all/di/-/di-0.0.1.tgz#806649326ceaa7caa3306d75d985ea2748ba913c"
|
||||
|
|
Loading…
Reference in New Issue
Block a user