-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditional import of Electron/NodeJS libs - The app can be launch in…
… browser mode
- Loading branch information
1 parent
9d43304
commit c434f8a
Showing
9 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import { Component } from '@angular/core'; | ||
import { ipcRenderer } from 'electron'; | ||
import * as childProcess from 'child_process'; | ||
import { ElectronService } from './providers/electron.service'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'] | ||
}) | ||
export class AppComponent { | ||
constructor() { | ||
// Check if electron is correctly injected (see externals in webpack.config.js) | ||
console.log('c', ipcRenderer); | ||
// Check if nodeJs childProcess is correctly injected (see externals in webpack.config.js) | ||
console.log('c', childProcess); | ||
constructor(public electronService: ElectronService) { | ||
|
||
if(electronService.isElectron()) { | ||
console.log('Mode electron'); | ||
// Check if electron is correctly injected (see externals in webpack.config.js) | ||
console.log('c', electronService.ipcRenderer); | ||
// Check if nodeJs childProcess is correctly injected (see externals in webpack.config.js) | ||
console.log('c', electronService.childProcess); | ||
} else { | ||
console.log('Mode web'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |