我正在写一个Eletron节目.在程序中有一个索引窗口,由主进程(main.js)创建.在此窗口中有一个文件列表(图像).当我单击该列表中的一个文件时,我想启动第二个显示该文件的窗口.第二个窗口由索引窗口(index.js)的渲染器进程启动.如何在索引窗口的渲染器进程和第二个窗口的渲染器进程之间进行通信?
码:
从main.js中的主进程创建索引窗口:
let win;
function createWindow(){
// Create the browser window.
win = new BrowserWindow({width: 1024, height: 768, minWidth: 800, minHeight: 600, show: false, icon: 'files/images/icon.png'});
win.loadURL(`file://${__dirname}/files/html/index.html`);
win.once('ready-to-show', () => {
win.show()
})
// Emitted when the window is closed.
win.on('closed', () => {
win = null;
});
}
app.on('ready', createWindow);
Run Code Online (Sandbox Code Playgroud)
在index.html中,index.js(渲染器进程)启动:
<script src="../javascript/index.js"></script>
Run Code Online (Sandbox Code Playgroud)
在index.js function create_sprite_window()
中调用它来创建子窗口:
const fs = require('fs');
const path = require('path');
const {BrowserWindow} = require('electron').remote
let child_windows = [];
function create_child_window(URL, width, height){
let …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从主进程创建两个窗口。第二个窗口应始终显示在第一个窗口的顶部。在 Electron 网站上,我读到我必须创建一个父窗口和一个子窗口才能做到这一点。这是我的代码:
let win;
let child;
function createWindow(){
// Create the browser window.
win = new BrowserWindow({width: 1024, height: 768, show: false});
child = new BrowserWindow({parent: win});
child.show();
win.once('ready-to-show', () => {
win.show()
})
// and load the index.html of the app.
win.loadURL(`file://${__dirname}/index.html`);
// Emitted when the window is closed.
win.on('closed', () => {
win = null;
});
}
app.on('ready', createWindow);
Run Code Online (Sandbox Code Playgroud)
当我启动程序时,它会创建两个窗口,但子窗口并不总是在顶部。当我关闭父窗口 (win) 时,两个窗口都关闭了。如何使子窗口始终显示在顶部?我在 Gnome 上使用 Fedora 24。
我正在编写一个 Electron 程序,并希望在主进程中使用一些 javascript 类。我希望将这些类放在不同的文件中,并将它们包含在脚本中。
我通常通过在 html 文件中添加脚本和类来完成此操作,但由于它是主进程,因此没有 html 文件。
问题 是否可以在不同的 javascript 文件中包含外部 javascript 文件?
我正在尝试编写一个 Electron 程序,其中主进程创建一个不可见的窗口,向该窗口发送一个数字,该窗口计算阶乘,然后将其发送回来。
这是在主流程中:
function invisibleWindow() {
const invisPath = 'file://' + path.join(__dirname, 'files/html/inv.html')
let win = new BrowserWindow({ width: 400, height: 400, show: false })
win.loadURL(invisPath)
win.webContents.on('did-finish-load', function () {
const input = 100;
win.webContents.send('compute-factorial', input);
})
ipcMain.on('factorial-computed', function (event, input, output) {
const message = `The factorial of ${input} is ${output}`
console.log(message);
})
}
Run Code Online (Sandbox Code Playgroud)
该函数在主进程中通过以下方式调用:
app.on('ready', () => {
// creates different window here
invisibleWindow();
});
Run Code Online (Sandbox Code Playgroud)
这是 inv.html 文件:
<html>
<script type="text/javascript">
const ipc = require('electron').ipcRenderer
const BrowserWindow …
Run Code Online (Sandbox Code Playgroud)