how to use electron browser window inside components in angular-cli?

雨燕双飞 提交于 2019-12-04 18:09:53

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <script src="http://code.jquery.com/jquery-2.1.1.js"></script>
  <title>Workdesk 2.0</title>
  <!--<base href="./">-->
  <base href="./">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="styles.css">
  <script src="assets/jquery.js"></script>
</head>
<body style="margin: 0px;">
  <app-root>  </app-root>
  <script>
    var electron = require('electron');
    var BrowserWindow = require('electron').remote.BrowserWindow;
    var ipcMain = require('electron').remote.ipcMain;
    var shell = require('electron').shell;
    var Positioner = require('electron-positioner');
    var path = require('path');
    var gkm = require('gkm');
    var fs = require('fs');
    var os = require('os');
    var path = require('path');
    var base64Img = require('base64-img');
    var ip = require('ip');
  </script>
</body>
</html>

This will help you to communicate with electron in any of the script languages like angular2,react js, node js etc.,

Once you install ngx-electron via npm, you can create browserwindows inside of an angular component like this: (Working as of Angular 7)

import { ElectronService } from 'ngx-electron';
constructor(
private _electronService: ElectronService){}
var BrowserWindow = this._electronService.remote.BrowserWindow
var win = new BrowserWindow({
  width: 600,
height: 840,
})
win.webContents.openDevTools()

You can only do this by initialize electron variables inside index.html and you can communicate wherever you want inside typescript. Use electron variables inside TS.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!