- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
构建我的第一个 Electron 应用程序,我希望工作流程如下:
主窗口打开 -> 用户单击“打开”按钮 -> 第二个窗口打开 -> 用户输入/点击提交 -> 主窗口打开并显示用户输入
下面是我的 main.js
中的 app.on('ready'
)。应用程序启动 (win.loadURL
) 工作正常,open-new-window
事件也是如此。奇怪之处在于输入广播。
当用户在第二个窗口中输入内容时,主窗口将重新打开。但是,input-broadcast
中的 console.log
中的文本不会出现,并且 input-received
永远不会在主窗口中触发渲染器。
不确定我做错了什么,但是我也可能使用了错误的设计模式。任何帮助将不胜感激!
main.js
const {app, BrowserWindow, ipcMain, remote} = require('electron');
const url = require('url');
const path = require('path');
const countdown = require('./countdown');
let win;
const windows = [];
app.on('ready', () =>{
console.log('app ready');
ipcMain.on('open-new-window', () =>{
console.log('trying to open window');
win.loadURL(url.format({
pathname: path.join(__dirname, 'enterValue.html'),
protocol: 'file:',
slashes: true
}));
});
ipcMain.on('input-broadcast', (evt, data) =>{
console.log('input-broadcast happened in main');
win.webContents.send('input-received', data);
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
});
win = new BrowserWindow({width: 800, height: 600});
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
win.on('closed', () =>{
console.log('closed');
win = null;
});
})
renderer.js(与index.html关联)
console.log('from renderer1');
const {ipcRenderer} = require('electron');
document.getElementById('start').addEventListener('click', ()=>{
ipcRenderer.send('open-new-window');
console.log('window button clicked');
});
ipcRenderer.on('open-new-window', (evt, count) =>{
document.getElementById('userInput').innerHTML(count);
});
ipcRenderer.on('input-received', (evt, data) =>{
console.log('input received');
console.log(evt);
console.log(data);
});
renderer2.js(与用户enterValue.html关联)
console.log('from renderer2');
const {ipcRenderer} = require('electron');
document.getElementById('submitButton').addEventListener('click', (evt, input)=>{
var input = document.getElementById('randomInput').value;
ipcRenderer.send('input-broadcast', input);
});
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<p>Your input was <span id="userInput"></span><p>
<button id="start">Open</button>
<script>require('./renderer')</script>
</html>
enterValue.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Enter a name</p>
<input type="text" id="randomInput" placeholder="enter a value"/>
<button id="submitButton">Submit</button>
<script>require('./renderer2.js')</script>
</body>
</html>
最佳答案
将输入发送回 renderer.js
时,您的调用顺序不正确。你打电话
win.webContents.send('input-received', data)
当 index.html
尚未重新加载到 win
中时!
要解决此问题,您应该交换调用并确保发送 ipc 消息时内容已准备好
ipcMain.on('input-broadcast', (evt, data) => {
console.log('input-broadcast happened in main')
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
win.webContents.once('dom-ready', () => {
win.webContents.send('input-received', data)
})
})
关于javascript - 尝试通过 ipc 将数据从一个 Electron 窗口发送到另一个 Electron 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45259372/
我的主要流程(重要代码): let introWindow let win = null function createWindow() { // Create the browser win
信号量是一种 IPC 机制吗? 最佳答案 是的,在许多平台下,信号量可以跨进程同步。您将为此使用“命名”信号量——多个进程通过名称访问对象,类似于文件系统对象。 在 POSIX 中,您可以通过 sem
我一直在关注 Thrift 对 Windows 和 VS 开发的支持,感谢许多贡献者,它已经取得了长足的进步。有针对编译器和 C++ 库的 VS 2010 项目,我已经确认它们在 0.8 中运行良好。
或者它们是同义词吗? 最佳答案 维基百科通常非常适合这些目的。 RPC: Remote procedure call (RPC) is an Inter-process communication t
是否有标准库的一部分? 我一直在四处挖掘,但我看不到任何明显的实现它的东西,或者在 Process 上的任何东西可以让你这样做? 我错过了吗?还是我必须为此功能做一些 C 包装器工作? (如果是这样,
我计划在同一主机上运行的两个进程之间为我的 IPC(进程间通信)使用 unix 域套接字。但在选择 unix 套接字之前,我还必须研究数据安全性。 我只是想知道如果我使用 unix 套接字而不加密我在
System V IPC 和 POSIX IPC 之间有什么区别? 为什么我们有两个标准? 如何决定使用哪些 IPC 函数? 最佳答案 两者都有相同的基本工具——信号量、共享内存和消息队列。它们提供的
在我的menu.js中的“label:'Database'”下,单击事件返回错误:ipc未定义。我想,如果这是 main.js 文件的一部分,并且如果我已经在全局范围内声明了一个 const 为 ip
我正在设置两个 docker 容器 - 一个作为服务器在内存中保存数据,另一个作为客户端访问该数据。为此,我相信我需要使用 --ipc在容器之间共享内存的标志。 Docker documentatio
我正在尝试使用来自 HDFS 的文件运行 flink 作业。我创建了一个数据集如下 - DataSource> visits = env.readHadoopFile(new TextInputFor
我在 NetBeans IDE 8.0.2 中使用 hadoop 2.7.0 和 java oracle jdk1.7.0_79。当我尝试使用 Java 文件与 Hadoop 通信时,出现以下错误。是
我一直在使用 Electrons 同步和异步 RPC 通信机制,并且可以很好地在进程之间传递我的数据。但是,我现在需要不断地向渲染器进程发送事件数据(有点像聊天应用程序)并更新一些文本。 这在 Ele
我正在用 Go 编写一个负载平衡的服务器系统。 负载平衡服务器将与多个应用服务器通信并处理请求。这些服务器既可以在同一台机器上运行,也可以在网络上运行。 我已经弄清楚了网络,但现在我需要为负载均衡器找
我有一个关于操作系统中进程间通信的问题。 两个进程是否可以通过打开同一个文件(据说是在两个进程之前创建的,所以两个进程都有文件处理程序)然后通过写入该文件进行通信来相互通信? 如果是,这个方法属于什么
Closed. This question is opinion-based。它当前不接受答案。 想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。 6年前关闭。
我有一个使用 System V 共享内存段的应用程序。通常它在内部管理这些,没有人需要接触它们。但对于紧急情况,我们有一个实用程序可以手动清除共享内存段。 问题是,为了做到这一点,它运行ipcs,并使
当使用node-ipc通过IPC在NodeJS进程之间进行通信时,启动服务器并监听连接,或者创建客户端并连接到服务器似乎非常简单。 但是有些事情看起来并不那么简单: How can the serve
我正在寻找有关我可以在我自制的 AVR32 板操作系统中实现的可能 IPC 机制的建议。 我目前的选择是实现 Tanenbaum 所写书籍中描述的按摩传递机制。 这是一个不错的选择吗?有没有更简单的方
我去面试了。面试官问我: If two nodes are sending two messages of the same identifier (0x100) with different dat
我正在寻找一种进程间通信工具,可以在相同或不同系统上运行的语言和/或环境之间使用。例如,它应该允许在 Java、C# 和/或 C++ 组件之间发送信号,并且还应该支持某种排队机制。唯一明显与环境和语言
我是一名优秀的程序员,十分优秀!