问题标签 [ipcrenderer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
57 浏览

electron - 使用 arg 超出 ipcRenderer 电子?

所以我有这段代码,并且 arg 是从 Main 发送的。

我希望能够在 ipcRenderer 函数之外使用 arg,但我无法将其取出。这甚至可能吗?如果可以,那怎么办?提前致谢。

0 投票
3 回答
11319 浏览

javascript - 无法在 IPCRenderer 中传递对象/数组,无法克隆对象 EventEmitter.i.send.i.send

我无法将任何对象或数组传递给 IPCRenderer。

通过 ipcs 传递对象或数组时出现错误,我什至尝试通过使用 JSON.stringify 转换为字符串来发送,但它会将其转换为空对象字符串。

我试过传递一个文件列表,一个对象数组,甚至一个对象都没有传递。只有字符串或手写对象有效。

我读过它使用结构化克隆算法,并且该算法允许使用 fileList & Array

错误:

ElectronJS ipcRenderer 错误无法克隆对象。

我尝试了许多可能的解决方案,但没有任何效果

代码:

现在我尝试将文件发送为JSON.stringify,我尝试将其作为对象发送,但除非我手动编写虚拟对象或字符串,否则没有任何效果。

这是这个项目的我的Github 存储库

有错误J 的文件:-

图像处理.js

更新:-

我替换了这个:

进入这个: -

现在我在这里通过forEach一个一个地发送文件,实际上它发送字符串“文件路径”所以它是如何工作的我仍然很困惑为什么我必须这样做?为什么我不能发送整个文件列表我认为这种循环方法是一种不好的做法,因为它会在一个额外的循环中消耗更多的 CPU,但是如果我能够发送整个数组就没有必要了。

0 投票
0 回答
529 浏览

vue.js - __dirname 未定义:ipcRenderer.on('settings', () => {

我首先使用 @vue/cli 创建了一个全新的 vue.js 项目:

vue 创建新项目

在创建过程中,我选择了 typecipt 选项。

然后,我安装了 electron-builder 插件:

vue 添加电子生成器

执行纱线电子:服务全新的应用程序似乎工作:

在此处输入图像描述

但是当我添加这两行时:

ipcRenderer.on('设置', () => { }

在 Ipc.vue 中:

我收到错误消息: 在此处输入图像描述

babel.config.js :

tsconfig.json :

环境信息:

如何解决问题?期待您的帮助。马可

更新 1)

将 nodeIntegration: true 放在 createWindow() 函数中,我收到了这个新的错误消息:

在此处输入图像描述

顺便说一句,出于安全原因,我更喜欢保留 nodeIntegration: false 我尝试使用此处建议的预加载文件:Electron require() is not defined 但具有:

我收到此错误消息:

在此处输入图像描述

更新 2)

这是 preload.js :

在 background.js 我放:

我收到此错误:

在此处输入图像描述

更新 3)

只有 nodeIntegration: true,没有预加载:

我收到此错误:

在此处输入图像描述

还预加载:

我收到另一个错误:

在此处输入图像描述

更新 4) preload.js 和 background.js 在同一个文件夹中:src

我收到此错误:

在此处输入图像描述

这是 webpack.config.js :

webpack.config.js 是正确的还是我应该在这里修改一些东西?

0 投票
2 回答
1006 浏览

vue.js - import { ipcRenderer } from 'electron' 产生此错误:__dirname is not defined

有了这个简单的 Vue 页面:

import { ipcRenderer } from 'electron' 的唯一存在会产生错误 __dirname is not defined :

在此处输入图像描述

这个问题是与 webpack 配置有关还是由于其他原因?

这是我的 webpack.config.js :

这是 vue.config.js :

  • 电子:版本​​ 9.0.0
  • webpack:版本 4.44.1
  • 系统:操作系统:Linux 5.4 Ubuntu 18.04.4 LTS(仿生海狸) CPU:(8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  • 二进制文件:节点:14.5.0 - ~/.nvm/versions/node/v14.5.0/bin/node 纱线:1.22.4 - /usr/bin/yarn npm:6.14.5 - ~/.nvm/versions/node /v14.5.0/bin/npm
  • 浏览器:Chrome:84.0.4147.105 Firefox:79.0

期待您的帮助。马可

0 投票
3 回答
6272 浏览

javascript - 如何在 vue.js 中导入 ipcRenderer?__dirname 未定义

我很难理解如何在 .vue 文件中正确导入 ipcRenderer。

我放入 /src/background.js 文件:

而且,基于https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration我把 preload.js :

webpack.config.js :

为了方便调试,我创建了一个github repo。你可以从这里 git 克隆 repo:https ://github.com/raphael10-collab/ElectronVueTypeScriptScaffolding.git

执行 yarn -> yarn electron:serve 后你会得到正确的页面。

但是在 /src/views/Home.vue 中激活此行时:

//从“电子”导入 { ipcRenderer }

你会得到这个错误:

__dirname 未定义

更新 1)

我尝试将 webPreferences 设置如下(使用 nodeIntegration:true):

并得到这个错误:

fs.existsSync 不是函数

搜索有关此类问题的信息,我发现了这篇文章: 如何解决 fs.existsSync 不是一个函数 通过此链接:https ://webpack.js.org/concepts/targets/

但我已经在 webpack.config.js 中指定了目标“节点”:

在 webpack.config.js 中:

那么......如何解决这个新问题?

顺便说一句,我为什么要放

如果出于安全原因,更安全的是:

dist_electron/preload.js :

https://www.electronjs.org/docs/tutorial/security#electron-security-warnings

更新 2)

在 vue.config.js 我放了:

但是当我这样做时我得到了同样的错误

UncaughtReferenceError: __dirname 未定义

设置 nodeIntegration: true 时(但我更愿意将其设置为 false,并使用 preload.js 文件),我得到另一个错误(如上):

未捕获的类型错误:fs.existsSync 不是函数

如何解决问题?期待您的热心帮助

0 投票
0 回答
70 浏览

javascript - Electron 在浏览器窗口中使用 ipcRenderer 获取对象选定对象的类名

我有一个浏览器窗口对象,用于'NodeIntegration=true'使用 ipcRendere 在渲染器和主程序之间进行交互,它适用于 github.com 等页面。不幸的是,对于 StackOverflow,它不会加载外部 javascript 文件。当我关闭 NodeIntegration 时,它工作正常。

下面是我的代码

使用上下文菜单右键单击所选对象 o 识别类并作为同步消息传递

}

页面完成加载时加载Dom 检查器和 Jquery

输出

在此处输入图像描述

当我关闭节点集成时,它可以工作,但我不确定如何注入 dom-inspector js。我应该尝试使用<webview>并预加载脚本,有什么想法吗?

0 投票
3 回答
1244 浏览

vue.js - Electron JS事件多次触发

在 electronJS 中,我创建了一个自定义应用程序菜单,在其中我将事件从主进程发送到渲染器进程,但现在发生的事情是我正在监听该事件多次运行的地方。因此,如果有人可以帮助我找到并解决错误。谢谢。这是我的代码:

现在这个 console.log 被打印了多次。

原始代码:

},

0 投票
1 回答
138 浏览

javascript - Windows.alert() 防止访问/数据进入电子反应应用程序中的文本输入字段。处理 windows.alert 的最佳方法是什么?

我在电子反应应用程序中有一个文本输入字段。windows.alert() 被用于通过在给定条件下更改状态的警报。但是在发出警报后,一个完全独立的表单中的输入文本字段将不允许用户在不点击应用程序然后再返回的情况下输入数据。

我目前确实有一个解决方法,即使用电子的 ipcRenderer 和 ipcMain 发出警报,但样式与应用程序的其余部分不匹配。有没有办法处理不会阻止数据输入到文本输入字段的 windows.alert()?是什么导致 windows.alert() 阻止将数据输入到文本输入中?

之前的代码示例:

使用 preload.js 和 ipcMain 中的 ipcRenderer 解决代码:

0 投票
1 回答
1800 浏览

electron - 如何使用 preload.js 将 ipcRenderer.invoke 处理程序答案传递给电子渲染器进程

我正在编写一个 CRA + Electron 应用程序,我需要使用 ipcRenderer.invoke 进行进程间通信。我能够使 ipcRenderer.send 和 ipcRender.on 在 contextIsolation 模式下工作,但 ipcRender.invoke 没有运气。由于某种我不明白的原因,我无法以任何形式(承诺或价值)将处理程序响应返回给渲染器,我得到的只是“未定义”值。

preload.js

main.js

Main.js 输出

渲染器.js

Renderer.js 输出

谁能指出我做错了什么?提前致谢

0 投票
1 回答
154 浏览

angular - Electron-Angular open client-side dialog on ipc event

I have a back-end notification that pops up a client-side angular-material dialog component. Sometimes, but not always, the dialog does not completely instantiate. The constructor of the component is invoked, but nothing else in the lifecycle is called until the dialog closes. Sometimes it works just fine and ngOnInit is invoked, too.

The component that has the ipc subscription looks like this (I have also tried setTimeout and using Observable, neither with much success):

The hotkey implementation calls the same method as a button which does the this.dialog.open(...) business.

The api is implemented via a contextBridge in preload.js as follows:

I assume the problem is some missing context that angular isn't getting from the ipcRenderer code path; do you know what I am missing?