electron

electron――ipcMain模块、ipcRenderer模块

匿名 (未验证) 提交于 2019-12-02 21:53:52
ipcMain 从 主进程 到 渲染进程 的异步通信。 ipcMain模块是EventEmitter类的一个实例。 当在主进程中使用时,它处理从渲染器进程(网页)发送出来的异步和同步信息。 从渲染器进程发送的消息将被发送到该模块。 // 在主进程中. const { ipcMain } = require('electron') // 监听asynchronous-message,接收渲染进程发送的消息 ipcMain.on('asynchronous-message', (event, arg) => { console.log(arg) // prints "ping" // 回复消息 event.reply('asynchronous-reply', 'pong') }) // 监听synchronous-message,接收渲染进程发送的消息 ipcMain.on('synchronous-message', (event, arg) => { console.log(arg) // prints "ping" // 返回的值 event.returnValue = 'pong' }) //在渲染器进程 (网页) 中。 const { ipcRenderer } = require('electron') // 向主进程synchronous-message发送消息

关于electron中入口文件main.js一些重要参数(持续更新maybe)

匿名 (未验证) 提交于 2019-12-02 21:53:52
const {app, BrowserWindow} = require('electron') const path = require('path') let mainWindow function createWindow () { console.log(123) mainWindow = new BrowserWindow({ width: 900, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration:true//设置此项以使用nodejs }, frame:true }) mainWindow.loadFile('main.html') mainWindow.on('closed', function () { mainWindow = null }) } app.on('ready', createWindow) app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit() }) app.on('activate', function () { if (mainWindow === null) createWindow() }

connecting to TFS using windows auth in electron app

北战南征 提交于 2019-12-02 21:17:41
问题 i'm building an electron app that connect to a TFS server and retrieve some data from it. They use Windows credential to access TFS , how can i connect to TFS using Windows credential through chrome or node.js ? i tried this code but give me 401 : unauthorized $.ajax({ url: 'https://tfs.myserver.com:8090/tfs/IKM.TPC.Projects/MR/_workitems', type: 'GET', dataType: 'json', xhrFields: { withCredentials: true } }) .done(function (data) { $('#result').text(data); }) .fail(function (jqXHR,

How to call local .dll files in Electron App

女生的网名这么多〃 提交于 2019-12-02 20:53:44
i have an issue how to call sample .dll files into my Electron App. I have sample .dll files in my folder, the thing is how to access my sample.dll file and how to call my sample.dll function and gets results. Any tutorials or steps to follow please sample code to start Calling into a .dll in Electron is no different to calling into one in plain NodeJS, which means you have two options, node-ffi or a native Node addon that links with your .dll and exposes a JavaScript API. If you decide to create a native Node addon you will need to build it to target Electron . Here are some links that cover

How connect to proxy in electron webview?

一个人想着一个人 提交于 2019-12-02 19:47:05
as I can connect through a to a free proxy server (or pay), currently in use as electron JS solution as desktop application example proxy list servers http://proxylist.hidemyass.com/ You can use .setProxy() method of session object. You're able to specify proxy directly like in example below: // in main.js var electron = require('electron'); var BrowserWindow = electron.BrowserWindow; mainWindow = new BrowserWindow({ "width": 970, "height": 500, "center": true, 'title': 'Main window', }); mainWindow.webContents.session.setProxy({proxyRules:"socks5://114.215.193.156:1080"}, function () {

Electron 截图踩坑和优化集合

痞子三分冷 提交于 2019-12-02 19:27:28
本文转载于: 猿2048 网站➸ https://www.mk2048.com/blog/blog.php?id=c1ch0cb0j 上一篇文章《 从零开始用 electron 手撸一个截屏工具 》发布之后发现阅读的朋友还不少,不过工具真正使用的时候就发现了问题,所以为了让我们的截图工具更好用,就又做了很多优化,当然了也遇到了很多坑。 截屏效果图: 项目修改后的完整代码依然是之前的地址: https://github.com/chrisbing/electorn-capture-screen 欢迎大家关注 接下来就列举一下解决的问题和具体做法 1. 截图一瞬间卡顿问题 先放上一版截图代码 console.time('capture') desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: width * scaleFactor, height: height * scaleFactor, } }, (error, sources) => { console.timeEnd('capture') let imgSrc = sources[0].thumbnail.toDataURL() let capture = new CaptureRenderer($canvas, $bg, imgSrc,

Print from an Electron application

坚强是说给别人听的谎言 提交于 2019-12-02 19:20:34
I'm trying to use node printer from an Electron application, but as soon I add the lines to use the printer, the app crashes. The console outputs this: [1] 9860 segmentation fault (core dumped) node_modules/electron-prebuilt/dist/electron. This is the app I'm running: var app = require('app'); var BrowserWindow = require('browser-window'); var printer = require('printer'); require('crash-reporter').start(); app.on('ready', function() { var mainWindow = new BrowserWindow({width: 800, height: 600}); mainWindow.loadUrl('file://' + __dirname + '/app/index.html'); mainWindow.openDevTools(); printer

How to access BrowserWindow Javascript global from main process in electron?

a 夏天 提交于 2019-12-02 19:06:26
I want a menu, defined in the main process to call JS code inside the current browser window in an atom/electron application. Getting main process globals form the browser window is const remote = require('remote') const foo = remote.getGlobal('foo') What is the equivalent for the main process (aka get current window globals). This is what I want to do in pseudo-code // JS inside main process const BrowserWindow = require('browser-window') //... // Inside the menu callback let window = BrowserWindow.getFocusedWindow() let commander = window.global('commander') /// <---- PSEUDO-CODE !!!

How to reduce Electron package size that exceeds more than 600 mb

会有一股神秘感。 提交于 2019-12-02 18:50:12
问题 I see this is because of node-modules and application is packaged with some unwanted stuffs for running. Current file size is 600 mb but I want it to be less than 200 mb. I suspect --no-prune populates all the node-modules in package that is built, but I need only specifies node-modules in the package that is built I tried removing unwanted packages in package.json, it doesn't help me either after refactoring "bundledDependencies": [ "fs", "os", "path", "regedit", "request", "start", "xml2js"

How to port an existing angular app to electron?

孤人 提交于 2019-12-02 18:37:25
I am a beginner to angular and a complete noob to electron. I was wondering if it would be possible to port an existing angular app to electron by using most of the existing codebase of the webapp? I found a couple of links on this but not much on Google. Most results talk about starting with angular and electron to create a desktop app - which is my intention but I would like to use most of my existing code base and ideally just add webpack and electron related config to compile the electon app from existing codebase as I don't want to maintain two version of the same codebase. I could use