feat: migrate from electron-webpack to electron-forge

Electron upgrade : 10.1.3 => 13.1.7
Angular upgrade : 10.1.3 => 12.1.2
This commit is contained in:
Amadou Ada DIENE
2021-07-19 12:34:50 +02:00
parent 433dfeb7f5
commit 4fa2999961
83 changed files with 73637 additions and 13521 deletions

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ElectronIpcService } from './electron-ipc.service';
describe('ElectronIpcService', () => {
let service: ElectronIpcService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ElectronIpcService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,44 @@
import { Injectable, NgZone } from '@angular/core';
import { WindowApi } from 'shared-lib';
@Injectable({
providedIn: 'root',
})
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;
}
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 {
if (this._api) {
this._api.receive(channel, (...data) => {
console.log(`Received from main process channel [${channel}]`, data);
// 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);
});
});
}
}
public send(channel: string, ...data: any): void {
if (this._api) {
console.log(`Sending to main process channel [${channel}]`, data);
this._api.send(channel, ...data);
}
}
}