UNPKG

3.67 kBMarkdownView Raw
1# ngx-electron
2
3[![Build Status](https://travis-ci.org/ThorstenHans/ngx-electron.svg?branch=master)](https://travis-ci.org/ThorstenHans/ngx-electron)
4[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
5
6`ngx-electron` is a small Module for [Angular](http://angular.io) which makes calling [Electron]() APIs from the [Renderer Process]() easier. By adding it to your Angular projet, you'll get intelli sense and a simple Angular service which acts as facade for Electron API's.
7
8`ngx-electron` is licensed under [MIT](https://opensource.org/licenses/MIT).
9
10## Introduction
11
12Checkout the introduction post on my [blog](https://medium.com/@ThorstenHans/integrating-angular-and-electron-using-ngx-electron-9c36affca25e#.4scol1nli) for more details.
13
14## Support me
15
16[![Become a Patron!](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/bePatron?u=16380186)
17
18## Installation
19
20`ngx-electron` can be installed easily using either `yarn` or `npm` commands in the scope of an angular project.
21
22```bash
23yarn add ngx-electron --save
24# or
25npm install ngx-electron --save
26```
27
28The `NgxElectronModule` needs to be import in your `root` Angular module (eg `AppModule`).
29
30``` typescript
31import { NgModule } from '@angular/core';
32import { BrowserModule } from '@angular/platform-browser';
33import { AppComponent } from './app.component';
34
35import { NgxElectronModule } from 'ngx-electron';
36
37
38@NgModule({
39 declarations: [],
40 imports: [
41 BrowserModule,
42 NgxElectronModule
43 ],
44 bootstrap: [AppComponent]
45})
46export class AppModule {
47
48}
49```
50
51Once the module has been imported, you can easily use dependency injection to get an instance of `ElectronService`.
52
53``` typescript
54import { Component } from '@angular/core';
55import { ElectronService } from 'ngx-electron';
56
57@Component({
58 selector: 'my-app',
59 templateUrl: 'app.html'
60})
61export class AppComponent {
62
63 constructor(private _electronService: ElectronService) { }
64
65 public playPingPong() {
66 if(this._electronService.isElectronApp) {
67 let pong: string = this._electronService.ipcRenderer.sendSync('ping');
68 console.log(pong);
69 }
70 }
71}
72```
73
74## ElectronService
75
76The `ElectronService` is exposing all API's accessible from within Electron's renderer process. **If your app is not running inside electron, all getters will return NULL instead**.
77
78### Properties
79
80 * `desktopCapturer: Electron.DesktopCapturer` - Electron's desktop capturing API
81 * `ipcRenderer: Electron.IpcRenderer` - Electron IpcRenderer
82 * `remote: Electron.Remote` - Electron Remote capabilities
83 * `webFrame: Electron.WebFrame` - Electron WebFrame
84 * `clipboard: Electron.Clipboard` - Clipboard API
85 * `crashReporter: Electron.CrashReporter` - Electron's CrashReporter
86 * `process: NodeJS.Process` - Electron's Process Object
87 * `screen: Electron.Screen` - Electron's Screen API
88 * `shell: Electron.Shell` - Electron's Shell API
89 * `nativeImage: Electron.NativeImage` - Electron's NativeImage API
90 * `isElectronApp: boolean` - Indicates if app is being executed inside of electron or not
91 * `isMacOS: boolean` - Indicates if app is running in electron and on `macOS`
92 * `isWindows: boolean` - Indicates if app is running in electron and on `Windows`
93 * `isLinux: boolean` - Indicates if app is running in electron and on `Linux`
94 * `isX86: boolean` - Indicates if app is running in electron and on a `x86` architecture
95 * `isX64: boolean` - Indicates if app is running in electron and on a `x64` architecture