Conditional import of Electron/NodeJS libs - The app can be launch in browser mode
This commit is contained in:
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