Conditional import of Electron/NodeJS libs - The app can be launch in browser mode
This commit is contained in:
15
src/app/providers/electron.service.spec.ts
Normal file
15
src/app/providers/electron.service.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { ElectronService } from './electron.service';
|
||||
|
||||
describe('ElectronService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ElectronService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should ...', inject([ElectronService], (service: ElectronService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
23
src/app/providers/electron.service.ts
Normal file
23
src/app/providers/electron.service.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { ipcRenderer } from 'electron';
|
||||
import * as childProcess from 'child_process';
|
||||
|
||||
@Injectable()
|
||||
export class ElectronService {
|
||||
|
||||
ipcRenderer: typeof ipcRenderer;
|
||||
childProcess: typeof childProcess;
|
||||
|
||||
constructor() {
|
||||
if (this.isElectron()) {
|
||||
this.ipcRenderer = window.require('electron').ipcRenderer;
|
||||
this.childProcess = window.require('child_process');
|
||||
}
|
||||
}
|
||||
|
||||
isElectron = () => {
|
||||
return window && window.process && window.process.type;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user