fix: fixing eslint problems
This commit is contained in:
@@ -24,5 +24,14 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"ignorePatterns": ["**/dist/**/*","**/.dist/**/*"],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-unused-vars": ["error", {
|
||||
"argsIgnorePattern": "^_"
|
||||
}],
|
||||
"@typescript-eslint/no-explicit-any": ["error", {
|
||||
"ignoreRestArgs": true
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
7
package-lock.json
generated
7
package-lock.json
generated
@@ -5,7 +5,6 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "electron-angular-quick-start",
|
||||
"version": "2.0.0",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
@@ -54,7 +53,7 @@
|
||||
"style-loader": "^2.0.0",
|
||||
"ts-loader": "^9.2.2",
|
||||
"ts-node": "^10.1.0",
|
||||
"typescript": "^4.0.2",
|
||||
"typescript": "^4.3.5",
|
||||
"wait-on": "^6.0.0"
|
||||
}
|
||||
},
|
||||
@@ -28703,7 +28702,7 @@
|
||||
"karma-coverage": "~2.0.3",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
"karma-jasmine-html-reporter": "~1.7.0",
|
||||
"typescript": "~4.3.2"
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
},
|
||||
"workspaces/angular-app/node_modules/@types/node": {
|
||||
@@ -33131,7 +33130,7 @@
|
||||
"karma-jasmine-html-reporter": "~1.7.0",
|
||||
"rxjs": "~6.6.0",
|
||||
"tslib": "^2.2.0",
|
||||
"typescript": "~4.3.2",
|
||||
"typescript": "^4.3.5",
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
"publish": "electron-forge publish",
|
||||
"lint": "eslint --ext .ts .",
|
||||
"test:electron-e2e": "npm run package && cross-env X_NODE_ENV=e2e-test node workspaces/electron-e2e/jasmine.js",
|
||||
"clean": "del -f .webpack out node_modules workspaces/shared-lib/dist workspaces/angular-app/node_modules workspaces/angular-app/dist",
|
||||
"clean": "del -f .webpack out node_modules workspaces/shared-lib/.dist workspaces/angular-app/node_modules workspaces/angular-app/.dist",
|
||||
"version": "npx conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
|
||||
},
|
||||
"config": {
|
||||
@@ -137,7 +137,7 @@
|
||||
"style-loader": "^2.0.0",
|
||||
"ts-loader": "^9.2.2",
|
||||
"ts-node": "^10.1.0",
|
||||
"typescript": "^4.0.2",
|
||||
"typescript": "^4.3.5",
|
||||
"wait-on": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"noImplicitReturns": true,
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"outDir": "dist",
|
||||
"outDir": ".dist",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"paths": {
|
||||
|
||||
@@ -20,7 +20,7 @@ module.exports = {
|
||||
patterns: [
|
||||
{ from: "workspaces/electron-app/main/assets" },
|
||||
{
|
||||
from: "workspaces/angular-app/dist",
|
||||
from: "workspaces/angular-app/.dist/angular-app",
|
||||
to: "../renderer/angular_window",
|
||||
noErrorOnMissing: true
|
||||
}
|
||||
|
||||
2
workspaces/angular-app/.gitignore
vendored
2
workspaces/angular-app/.gitignore
vendored
@@ -1,7 +1,7 @@
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# compiled output
|
||||
/dist
|
||||
/.dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
# Only exists if Bazel was run
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:browser",
|
||||
"options": {
|
||||
"outputPath": "./dist",
|
||||
"outputPath": "./.dist/angular-app",
|
||||
"index": "src/index.html",
|
||||
"main": "src/main.ts",
|
||||
"polyfills": "src/polyfills.ts",
|
||||
|
||||
@@ -32,6 +32,6 @@
|
||||
"karma-coverage": "~2.0.3",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
"karma-jasmine-html-reporter": "~1.7.0",
|
||||
"typescript": "~4.3.2"
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { AppComponent } from './app.component';
|
||||
import { MutiplesComponent } from './components/mutiples/mutiples.component';
|
||||
|
||||
// AoT requires an exported function for factories
|
||||
export function HttpLoaderFactory(http: HttpClient) {
|
||||
export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
|
||||
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export class MutiplesComponent implements OnInit {
|
||||
input: new FormControl(Math.round(Math.random() * 100) % 10),
|
||||
});
|
||||
|
||||
multiples = [];
|
||||
multiples: number[] = [];
|
||||
|
||||
constructor(
|
||||
private electronIpc: ElectronIpcService,
|
||||
@@ -23,13 +23,16 @@ export class MutiplesComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
// Specifying what to do with received data from main process
|
||||
this.electronIpc.receive(WindowApiConst.MULTIPLES_OUTPUT, (...data: []) => {
|
||||
// Update current data
|
||||
this.multiples = data;
|
||||
});
|
||||
this.electronIpc.receive<number[]>(
|
||||
WindowApiConst.MULTIPLES_OUTPUT,
|
||||
(output: number[]) => {
|
||||
// Update current data
|
||||
this.multiples = output;
|
||||
}
|
||||
);
|
||||
|
||||
// Reset multiples on form changes
|
||||
this.timesTableForm.valueChanges.subscribe((value) => {
|
||||
this.timesTableForm.valueChanges.subscribe(() => {
|
||||
this.multiples = [];
|
||||
});
|
||||
|
||||
@@ -37,12 +40,12 @@ export class MutiplesComponent implements OnInit {
|
||||
this.onSubmit();
|
||||
}
|
||||
|
||||
translateIn(lang: string) {
|
||||
translateIn(lang: string): void {
|
||||
this.translate.use(lang);
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
const intput = this.timesTableForm.value.input;
|
||||
this.electronIpc.send(WindowApiConst.MULTIPLES_INPUT, intput);
|
||||
onSubmit(): void {
|
||||
const input = this.timesTableForm.value.input;
|
||||
this.electronIpc.send(WindowApiConst.MULTIPLES_INPUT, input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,37 +8,33 @@ export class ElectronIpcService {
|
||||
private _api!: WindowApi;
|
||||
|
||||
constructor(private zone: NgZone) {
|
||||
if (window && (window as any).api) {
|
||||
try {
|
||||
this._api = (window as any).api;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
if (window && (window as Window).api) {
|
||||
this._api = (window as Window).api;
|
||||
console.log('Preloader API has been loaded successfully');
|
||||
} else {
|
||||
console.warn('Preloader API is not loaded');
|
||||
}
|
||||
}
|
||||
|
||||
public receive(channel: string, func: (...data: any) => void): void {
|
||||
public receive<Out>(channel: string, func: (output: Out) => void): void {
|
||||
if (this._api) {
|
||||
this._api.receive(channel, (...data) => {
|
||||
console.log(`Received from main process channel [${channel}]`, data);
|
||||
this._api.receive<Out>(channel, (output) => {
|
||||
console.log(`Received from main process channel [${channel}]`, output);
|
||||
|
||||
// Next code might run outside of Angular zone and therefore Angular
|
||||
// doesn't recognize it needs to run change detection
|
||||
// Further details on SO : https://stackoverflow.com/a/49136353/11480016
|
||||
this.zone.run(() => {
|
||||
func(...data);
|
||||
func(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public send(channel: string, ...data: any): void {
|
||||
public send<In>(channel: string, input: In): void {
|
||||
if (this._api) {
|
||||
console.log(`Sending to main process channel [${channel}]`, data);
|
||||
this._api.send(channel, ...data);
|
||||
console.log(`Sending to main process channel [${channel}]`, input);
|
||||
this._api.send<In>(channel, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"outDir": "./dist/out-tsc",
|
||||
"outDir": "./.dist/out-tsc",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"development": {
|
||||
"config_id": "development",
|
||||
"configId": "development",
|
||||
"mainLogFile": "dist/dev-main.log",
|
||||
"mainLogLevel": "debug",
|
||||
"isIconAvailable": true,
|
||||
@@ -10,7 +10,7 @@
|
||||
"isOpenDevTools": true
|
||||
},
|
||||
"e2e-test": {
|
||||
"config_id": "e2e-test",
|
||||
"configId": "e2e-test",
|
||||
"mainLogFile": "dist/e2e-main.log",
|
||||
"mainLogLevel": "error",
|
||||
"isIconAvailable": true,
|
||||
@@ -20,7 +20,7 @@
|
||||
"isOpenDevTools": false
|
||||
},
|
||||
"production": {
|
||||
"config_id": "production",
|
||||
"configId": "production",
|
||||
"mainLogFile": "main.log",
|
||||
"mainLogLevel": "error",
|
||||
"isIconAvailable": false,
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import { app, BrowserWindow, shell } from 'electron';
|
||||
import { Window } from './window';
|
||||
import { app, BrowserWindow, shell } from "electron";
|
||||
import { Window } from "./window";
|
||||
|
||||
export class App {
|
||||
private static _wrapper: Window;
|
||||
|
||||
public static launch() {
|
||||
app.on('window-all-closed', App.quit);
|
||||
app.on('activate', App.start);
|
||||
app.on('ready', App.start);
|
||||
public static launch(): void {
|
||||
app.on("window-all-closed", App.quit);
|
||||
app.on("activate", App.start);
|
||||
app.on("ready", App.start);
|
||||
|
||||
// Fix warning by applying electron new default value for this property
|
||||
// Further details : https://github.com/electron/electron/issues/18397
|
||||
app.allowRendererProcessReuse = true;
|
||||
|
||||
// Limit navigation and open external links in default browser
|
||||
app.on('web-contents-created', App.openExternalLinksInDefaultBrowser);
|
||||
app.on("web-contents-created", App.openExternalLinksInDefaultBrowser);
|
||||
}
|
||||
|
||||
public static get window(): BrowserWindow | any {
|
||||
return this._wrapper ? this._wrapper.window : null;
|
||||
public static get electronWindow(): BrowserWindow | undefined {
|
||||
return this._wrapper ? this._wrapper.electronWindow : undefined;
|
||||
}
|
||||
|
||||
private static start() {
|
||||
// On MacOS it is common to re-create a window from app even after all windows have been closed
|
||||
if (!App.window) {
|
||||
if (!App.electronWindow) {
|
||||
App._wrapper = new Window();
|
||||
}
|
||||
}
|
||||
|
||||
private static quit() {
|
||||
// On MacOS it is common for applications to stay open until the user explicitly quits
|
||||
if (process.platform !== 'darwin') {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
@@ -40,23 +40,21 @@ export class App {
|
||||
contents: Electron.WebContents
|
||||
) => {
|
||||
// Disabling creation of new windows
|
||||
contents.on(
|
||||
'new-window',
|
||||
(event: Electron.Event, navigationUrl: string) => {
|
||||
// Blocking this event from loading in current app
|
||||
event.preventDefault();
|
||||
// Telling the user platform to open this event's url in the default browser
|
||||
shell.openExternal(navigationUrl);
|
||||
}
|
||||
);
|
||||
contents.setWindowOpenHandler((handler: Electron.HandlerDetails) => {
|
||||
// Telling the user platform to open this event's url in the default browser
|
||||
shell.openExternal(handler.url);
|
||||
|
||||
// Blocking this event from loading in current app
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
// Limiting navigation
|
||||
contents.on(
|
||||
'will-navigate',
|
||||
"will-navigate",
|
||||
(event: Electron.Event, navigationUrl: string) => {
|
||||
const parsedUrl = new URL(navigationUrl);
|
||||
// Allowing local navigation only
|
||||
if (parsedUrl.origin !== 'http://localhost:4200') {
|
||||
if (parsedUrl.origin !== "http://localhost:4200") {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
import { app, BrowserWindow, ipcMain, nativeImage } from "electron";
|
||||
import * as path from "path";
|
||||
import * as url from "url";
|
||||
import { AbstractService } from "../services/abstract-service";
|
||||
import { MultiplesService } from "../services/multiples-service";
|
||||
import { Logger } from "../utils/logger";
|
||||
|
||||
declare const global: any;
|
||||
declare const global: Global;
|
||||
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
|
||||
|
||||
export class Window {
|
||||
private _window: BrowserWindow | any;
|
||||
private _electronWindow: BrowserWindow | undefined;
|
||||
|
||||
constructor() {
|
||||
this.createWindow();
|
||||
this.loadRenderer();
|
||||
this.registerService(MultiplesService);
|
||||
this.registerService<number, number[]>(new MultiplesService());
|
||||
}
|
||||
|
||||
private createWindow(): void {
|
||||
this._window = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
this._electronWindow = new BrowserWindow({
|
||||
width: 1280,
|
||||
height: 720,
|
||||
backgroundColor: "#FFFFFF",
|
||||
// FIXME
|
||||
// icon: this.loadIcon(),
|
||||
@@ -28,25 +27,25 @@ export class Window {
|
||||
// Default behavior in Electron since 5, that
|
||||
// limits the powers granted to remote content
|
||||
// except in e2e test when those powers are required by Spectron
|
||||
nodeIntegration: global.gConfig.isNodeIntegration,
|
||||
nodeIntegration: global.appConfig.isNodeIntegration,
|
||||
// Isolate window context to protect against prototype pollution
|
||||
// except in e2e test when that access is required by Spectron
|
||||
contextIsolation: global.gConfig.isContextIsolation,
|
||||
contextIsolation: global.appConfig.isContextIsolation,
|
||||
// Ensure that JS values can't unsafely cross between worlds
|
||||
// when using contextIsolation
|
||||
worldSafeExecuteJavaScript: global.gConfig.isContextIsolation,
|
||||
worldSafeExecuteJavaScript: global.appConfig.isContextIsolation,
|
||||
// Disable the remote module to enhance security
|
||||
// except in e2e test when that access is required by Spectron
|
||||
enableRemoteModule: global.gConfig.isEnableRemoteModule,
|
||||
enableRemoteModule: global.appConfig.isEnableRemoteModule,
|
||||
// Use a preload script to enhance security
|
||||
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private loadIcon(): Electron.NativeImage {
|
||||
let iconObj = null;
|
||||
if (global.gConfig.isIconAvailable) {
|
||||
private loadIcon(): Electron.NativeImage | undefined {
|
||||
let iconObj = undefined;
|
||||
if (global.appConfig.isIconAvailable) {
|
||||
const iconPath = path.join(__dirname, "icons/icon.png");
|
||||
Logger.debug("Icon Path", iconPath);
|
||||
iconObj = nativeImage.createFromPath(iconPath);
|
||||
@@ -59,58 +58,63 @@ export class Window {
|
||||
}
|
||||
|
||||
private loadRenderer(): void {
|
||||
if (global.gConfig.config_id === "development") {
|
||||
if (global.appConfig.configId === "development") {
|
||||
// Dev mode, take advantage of the live reload by loading local URL
|
||||
this.window.loadURL(`http://localhost:4200`);
|
||||
this.electronWindow.loadURL(`http://localhost:4200`);
|
||||
} else {
|
||||
// Else mode, we simply load angular bundle
|
||||
const indexPath = url.format({
|
||||
pathname: path.join(__dirname, `../renderer/angular_window/index.html`),
|
||||
protocol: "file:",
|
||||
slashes: true,
|
||||
});
|
||||
this.window.loadURL(indexPath);
|
||||
const indexPath = path.join(
|
||||
__dirname,
|
||||
"../renderer/angular_window/index.html"
|
||||
);
|
||||
this.electronWindow.loadURL(`file://${indexPath}`);
|
||||
}
|
||||
|
||||
if (global.gConfig.isOpenDevTools) {
|
||||
if (global.appConfig.isOpenDevTools) {
|
||||
this.openDevTools();
|
||||
}
|
||||
|
||||
// When the window is closed`
|
||||
this._window.on("closed", () => {
|
||||
this._electronWindow.on("closed", () => {
|
||||
// Remove IPC Main listeners
|
||||
ipcMain.removeAllListeners();
|
||||
// Delete current reference
|
||||
delete this._window;
|
||||
delete this._electronWindow;
|
||||
});
|
||||
}
|
||||
|
||||
private openDevTools(): void {
|
||||
this._window.webContents.openDevTools();
|
||||
this._window.webContents.on("devtools-opened", () => {
|
||||
this._window.focus();
|
||||
this._electronWindow.webContents.openDevTools();
|
||||
this._electronWindow.webContents.on("devtools-opened", () => {
|
||||
this._electronWindow.focus();
|
||||
setImmediate(() => {
|
||||
this._window.focus();
|
||||
this._electronWindow.focus();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private registerService(AnyService: typeof AbstractService) {
|
||||
const service = new AnyService();
|
||||
ipcMain.on(service.receptionChannel(), async (event, ...args) => {
|
||||
// Handling input
|
||||
Logger.debug(`Received [${service.receptionChannel()}]`, args);
|
||||
const data = await service.process(...args);
|
||||
private registerService<In, Out>(service: AbstractService<In, Out>) {
|
||||
ipcMain.on(
|
||||
service.receptionChannel(),
|
||||
async (event: Electron.IpcMainEvent, ...args: any[]) => {
|
||||
// Handling input
|
||||
const input = args[0];
|
||||
Logger.debug(`[${service.receptionChannel()}] =====> `, input);
|
||||
const output: Out = await service.process(input);
|
||||
|
||||
// Handling output
|
||||
if (service.sendingChannel()) {
|
||||
Logger.debug(`Sent [${service.sendingChannel()}]`, data);
|
||||
this._window.webContents.send(service.sendingChannel(), ...data);
|
||||
// Handling output
|
||||
if (service.sendingChannel()) {
|
||||
Logger.debug(`[${service.sendingChannel()}] =====> `, output);
|
||||
this._electronWindow.webContents.send(
|
||||
service.sendingChannel(),
|
||||
output
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
public get window(): BrowserWindow | any {
|
||||
return this._window;
|
||||
public get electronWindow(): BrowserWindow | undefined {
|
||||
return this._electronWindow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import * as fs from "fs-extra";
|
||||
import * as _ from "lodash";
|
||||
import * as path from "path";
|
||||
import { AppConfig } from "shared-lib";
|
||||
import { App } from "./components/app";
|
||||
|
||||
declare const global: any;
|
||||
declare const global: Global;
|
||||
|
||||
declare global {
|
||||
// Global augmentation of the `Global` interface
|
||||
interface Global {
|
||||
appConfig: AppConfig;
|
||||
}
|
||||
}
|
||||
|
||||
// Load config
|
||||
const currentEnv = process.env.X_NODE_ENV || process.env.NODE_ENV;
|
||||
const appConfig =
|
||||
const appConfigs = fs.readJsonSync(path.join(__dirname, "config.json"));
|
||||
const defaultConf = appConfigs.development;
|
||||
const currentConf = appConfigs[currentEnv];
|
||||
global.appConfig =
|
||||
currentEnv === "development"
|
||||
? fs.readJsonSync(path.join(__dirname, "config.json"))
|
||||
: fs.readJsonSync(path.join(__dirname, "config.json"));
|
||||
const defaultConf = appConfig.development;
|
||||
const currentConf = appConfig[currentEnv];
|
||||
global.gConfig = _.merge(defaultConf, currentConf);
|
||||
? defaultConf
|
||||
: _.merge(defaultConf, currentConf);
|
||||
|
||||
// Launch app
|
||||
App.launch();
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
export class AbstractService {
|
||||
export class AbstractService<In, Out> {
|
||||
receptionChannel(): string {
|
||||
throw new Error('Method not implemented.');
|
||||
throw new Error("Method not implemented yet.");
|
||||
}
|
||||
|
||||
sendingChannel(): string {
|
||||
throw new Error('Method not implemented.');
|
||||
throw new Error("Method not implemented yet.");
|
||||
}
|
||||
|
||||
process(...args: any): any {
|
||||
throw new Error('Method not implemented.');
|
||||
process(_input: In): Out {
|
||||
throw new Error("Method not implemented yet.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { WindowApiConst } from "shared-lib";
|
||||
import { AbstractService } from "./abstract-service";
|
||||
|
||||
export class MultiplesService extends AbstractService {
|
||||
export class MultiplesService extends AbstractService<number, number[]> {
|
||||
receptionChannel(): string {
|
||||
return WindowApiConst.MULTIPLES_INPUT;
|
||||
}
|
||||
@@ -10,11 +10,11 @@ export class MultiplesService extends AbstractService {
|
||||
return WindowApiConst.MULTIPLES_OUTPUT;
|
||||
}
|
||||
|
||||
process(...args: any): any {
|
||||
process(input: number): number[] {
|
||||
// From 1 to 10, return input multiples
|
||||
const multiples = [];
|
||||
for (let n = 1; n <= 10; n++) {
|
||||
multiples.push(n * args[0]);
|
||||
multiples.push(n * input);
|
||||
}
|
||||
return multiples;
|
||||
}
|
||||
|
||||
@@ -3,48 +3,48 @@ import * as os from "os";
|
||||
import * as path from "path";
|
||||
import * as winston from "winston";
|
||||
|
||||
declare const global: any;
|
||||
declare const global: Global;
|
||||
|
||||
export class Logger {
|
||||
private static singleton: Logger;
|
||||
private _logger: winston.Logger;
|
||||
|
||||
public static error(message: string, ...meta: any[]) {
|
||||
public static error(message: string, ...meta: any[]): void {
|
||||
Logger.initSingleton();
|
||||
Logger.singleton._logger.error(message, ...meta);
|
||||
Logger.singleton._logger.error(message, meta);
|
||||
}
|
||||
|
||||
public static warn(message: string, ...meta: any[]) {
|
||||
public static warn(message: string, ...meta: any[]): void {
|
||||
Logger.initSingleton();
|
||||
Logger.singleton._logger.warn(message, ...meta);
|
||||
Logger.singleton._logger.warn(message, meta);
|
||||
}
|
||||
|
||||
public static info(message: string, ...meta: any[]) {
|
||||
public static info(message: string, ...meta: any[]): void {
|
||||
Logger.initSingleton();
|
||||
Logger.singleton._logger.info(message, ...meta);
|
||||
Logger.singleton._logger.info(message, meta);
|
||||
}
|
||||
|
||||
public static http(message: string, ...meta: any[]) {
|
||||
public static http(message: string, ...meta: any[]): void {
|
||||
Logger.initSingleton();
|
||||
Logger.singleton._logger.http(message, ...meta);
|
||||
Logger.singleton._logger.http(message, meta);
|
||||
}
|
||||
|
||||
public static verbose(message: string, ...meta: any[]) {
|
||||
public static verbose(message: string, ...meta: any[]): void {
|
||||
Logger.initSingleton();
|
||||
Logger.singleton._logger.verbose(message, ...meta);
|
||||
Logger.singleton._logger.verbose(message, meta);
|
||||
}
|
||||
|
||||
public static debug(message: string, ...meta: any[]) {
|
||||
public static debug(message: string, ...meta: any[]): void {
|
||||
Logger.initSingleton();
|
||||
Logger.singleton._logger.debug(message, ...meta);
|
||||
Logger.singleton._logger.debug(message, meta);
|
||||
}
|
||||
|
||||
public static silly(message: string, ...meta: any[]) {
|
||||
public static silly(message: string, ...meta: any[]): void {
|
||||
Logger.initSingleton();
|
||||
Logger.singleton._logger.silly(message, ...meta);
|
||||
Logger.singleton._logger.silly(message, meta);
|
||||
}
|
||||
|
||||
private static initSingleton() {
|
||||
private static initSingleton(): void {
|
||||
if (!Logger.singleton) {
|
||||
Logger.singleton = new Logger();
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export class Logger {
|
||||
transports: [
|
||||
new winston.transports.File({
|
||||
filename: this.getLogFilename(),
|
||||
level: global.gConfig.mainLogLevel,
|
||||
level: global.appConfig.mainLogLevel,
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
this.fileFormat
|
||||
@@ -69,7 +69,7 @@ export class Logger {
|
||||
|
||||
// If we're not in production then log also to the `console` with the format:
|
||||
// `${info.timestamp} ${info.level}: ${info.message} JSON.stringify({ ...rest }) `
|
||||
if (global.gConfig.config_id === "development") {
|
||||
if (global.appConfig.configId === "development") {
|
||||
this._logger.add(
|
||||
new winston.transports.Console({
|
||||
stderrLevels: ["error", "warn"],
|
||||
@@ -87,8 +87,8 @@ export class Logger {
|
||||
* In production, returns absolute standard path depending on platform
|
||||
*/
|
||||
private getLogFilename() {
|
||||
let filename = global.gConfig.mainLogFile;
|
||||
if (global.gConfig.config_id === "production") {
|
||||
let filename = global.appConfig.mainLogFile;
|
||||
if (global.appConfig.configId === "production") {
|
||||
const appName = app.getName();
|
||||
if (process.platform == "linux") {
|
||||
filename = `.config/${appName}/${filename}`;
|
||||
@@ -106,24 +106,28 @@ export class Logger {
|
||||
* Write JSON logs with given format :
|
||||
* `${timestamp} ${level} : ${info.message} : ${meta})`
|
||||
*/
|
||||
private fileFormat = winston.format.printf((data: any) => {
|
||||
return JSON.stringify(this.prepareLogData(data));
|
||||
});
|
||||
private fileFormat = winston.format.printf(
|
||||
(data: winston.Logform.TransformableInfo) => {
|
||||
return JSON.stringify(this.prepareLogData(data));
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Custom winston console format
|
||||
* Write logs with given format :
|
||||
* `${timestamp} ${level} : ${info.message} : JSON.stringify({ ...meta }) `
|
||||
*/
|
||||
private consoleFormat = winston.format.printf((data: any) => {
|
||||
const preparedData = this.prepareLogData(data);
|
||||
return (
|
||||
`${preparedData.timestamp} ${preparedData.level} : ` +
|
||||
`${preparedData.message} : ${JSON.stringify(preparedData.meta)}`
|
||||
);
|
||||
});
|
||||
private consoleFormat = winston.format.printf(
|
||||
(data: winston.Logform.TransformableInfo) => {
|
||||
const preparedData = this.prepareLogData(data);
|
||||
return (
|
||||
`${preparedData.timestamp} ${preparedData.level} : ` +
|
||||
`${preparedData.message} : ${JSON.stringify(preparedData.meta)}`
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
private prepareLogData = (data: any) => {
|
||||
private prepareLogData = (data: winston.Logform.TransformableInfo) => {
|
||||
const additionalData = { ...data };
|
||||
delete additionalData.timestamp;
|
||||
delete additionalData.level;
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
// To secure user platform when running renderer process stuff,
|
||||
// Node.JS and Electron APIs are only available in this script
|
||||
import { contextBridge, ipcRenderer } from "electron";
|
||||
import { contextBridge, ipcRenderer, IpcRendererEvent } from "electron";
|
||||
import { WindowApi, WindowApiConst } from "shared-lib";
|
||||
|
||||
// So we expose protected methods that allow the renderer process
|
||||
// to use the ipcRenderer without exposing the entire object
|
||||
const windowApi: WindowApi = {
|
||||
send: (channel: any, ...data: any) => {
|
||||
send: <In>(channel: string, input: In) => {
|
||||
if (WindowApiConst.SENDING_SAFE_CHANNELS.includes(channel)) {
|
||||
ipcRenderer.send(channel, ...data);
|
||||
ipcRenderer.send(channel, input);
|
||||
}
|
||||
},
|
||||
receive: (channel: string, func: (...data: any) => void) => {
|
||||
receive: <Out>(channel: string, func: (output: Out) => void) => {
|
||||
if (WindowApiConst.RECEIVING_SAFE_CHANNELS.includes(channel)) {
|
||||
// Deliberately strip event as it includes `sender`
|
||||
ipcRenderer.on(channel, (event, ...args) => func(...args));
|
||||
ipcRenderer.on(channel, (event: IpcRendererEvent, ...args: any[]) =>
|
||||
func(args[0])
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
declare const window: any;
|
||||
declare const window: Window;
|
||||
if (process.env.X_NODE_ENV === "e2e-test") {
|
||||
// Injecting windowApi directly
|
||||
window.api = windowApi;
|
||||
@@ -29,4 +31,5 @@ if (process.env.X_NODE_ENV === "e2e-test") {
|
||||
contextBridge.exposeInMainWorld("api", windowApi);
|
||||
}
|
||||
|
||||
console.log(typeof window);
|
||||
console.log("The preload script has been injected successfully.");
|
||||
|
||||
@@ -9,7 +9,7 @@ jasmine.loadConfig({
|
||||
spec_files: ["./**/*-spec.ts"],
|
||||
helpers: ["./**/*-helper.ts"],
|
||||
random: false,
|
||||
seed: null,
|
||||
seed: undefined,
|
||||
stopSpecOnExpectationFailure: false,
|
||||
});
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Application } from "spectron";
|
||||
|
||||
describe("A simple test to verify a visible window is opened with a title", () => {
|
||||
// Init local app
|
||||
let app = new Application({
|
||||
const app = new Application({
|
||||
path: path.join(__dirname, "../../../node_modules/.bin/electron"),
|
||||
args: [path.join(__dirname, "../../../.webpack/main/index.js")],
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../out-tsc/e2e",
|
||||
"outDir": "./.dist",
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"noEmit": true,
|
||||
|
||||
2
workspaces/shared-lib/.gitignore
vendored
2
workspaces/shared-lib/.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
# Generated JS files
|
||||
dist
|
||||
/.dist
|
||||
@@ -4,12 +4,12 @@ export interface WindowApi {
|
||||
* @param channel used by the renderer to receive data and by the main to send them
|
||||
* @param func the callback function to execute when data are available
|
||||
*/
|
||||
receive(channel: any, func: (...data: any) => void): void;
|
||||
receive<Out>(channel: string, func: (output: Out) => void): void;
|
||||
|
||||
/**
|
||||
* This method is used by the renderer process to send data to the main process
|
||||
* @param channel used by the renderer to send data and by the main to receive them
|
||||
* @param data the data sent by the renderer process to the main process
|
||||
*/
|
||||
send(channel: string, ...data: any): void;
|
||||
send<In>(channel: string, input: In): void;
|
||||
}
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
export * from './apis/window-api';
|
||||
export * from './apis/window-api-consts';
|
||||
import { WindowApi } from "./apis/window-api";
|
||||
export * from "./apis/window-api";
|
||||
export * from "./apis/window-api-consts";
|
||||
export * from "./models/config/app-config";
|
||||
|
||||
declare global {
|
||||
// Global augmentation of the `Window` interface
|
||||
interface Window {
|
||||
api: WindowApi;
|
||||
}
|
||||
}
|
||||
|
||||
25
workspaces/shared-lib/models/config/app-config.ts
Normal file
25
workspaces/shared-lib/models/config/app-config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export interface AppConfig {
|
||||
/** The configuration identifier */
|
||||
configId: string;
|
||||
|
||||
/** The main logger output file path */
|
||||
mainLogFile: string;
|
||||
|
||||
/** The main logger output level */
|
||||
mainLogLevel: string;
|
||||
|
||||
/** Tells if we should try to load app icon */
|
||||
isIconAvailable: boolean;
|
||||
|
||||
/** Tells if `nodeIntegration` webPreference is enabled */
|
||||
isNodeIntegration: boolean;
|
||||
|
||||
/** Tells if `contextIsolation` and `worldSafeExecuteJavaScript` webPreferences are enabled */
|
||||
isContextIsolation: boolean;
|
||||
|
||||
/** Tells if `isEnableRemoteModule` webPreference is enabled */
|
||||
isEnableRemoteModule: boolean;
|
||||
|
||||
/** Tells if we should open dev tools */
|
||||
isOpenDevTools: boolean;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "shared-lib",
|
||||
"version": "2.0.0",
|
||||
"main": "dist/index.js",
|
||||
"main": ".dist/index.js",
|
||||
"scripts": {
|
||||
},
|
||||
"author": "Sourcygen",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"sourceMap": true,
|
||||
"composite": true,
|
||||
"declaration": true,
|
||||
"outDir": "./dist"
|
||||
"outDir": "./.dist"
|
||||
},
|
||||
"include": ["./**/*.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user