Electron:如何在Electron加载的页面中提取变量以更新徽章值。

Electron:如何在Electron加载的页面中提取变量以更新徽章值。,electron,electron-builder,Electron,Electron Builder,我正在寻找一种方法,根据electron加载的页面中提供的信息更新MAC应用程序的徽章值 我在启动时使用main.js文件中的以下代码加载页面 function createWindow () { // Create the browser window. mainWindow = new BrowserWindow({width: 1280, height: 800, show:false}) // and load the index.html of the app. mainWindow.

我正在寻找一种方法,根据electron加载的页面中提供的信息更新MAC应用程序的徽章值

我在启动时使用
main.js
文件中的以下代码加载页面

function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1280, height: 800, show:false})
// and load the index.html of the app.
mainWindow.loadURL('https://myapp/Home.html');
加载的页“”有一个隐藏的输入变量,该变量包含需要在Electron标记上更新的通知数

如何从main.js文件调用变量并使用更新标记

app.on('ready', app.setBadgeCount(Html_Hidden_Variable))
请让我也知道,这是正确的方式继续知道,我想避免必须创建和额外调用应用程序的数据库


提前谢谢你的帮助

您必须使用IPC并将通知号传递给main.js,然后将其保存在变量中并在代码中使用

您必须使用IPC并将通知号传递给main.js,然后将其保存在变量中并在代码中使用

以下是我如何做到的

获取带有通知数的变量,并将其发送到electron应用程序

Home.html

<script>
//setup the electron object to be able to send variable to it 
const ipcRenderer = require('electron').ipcRenderer;

//send the value Html_Hidden_Variable to electron variable CountNotifElectron 
ipcRenderer.send('CountNotifElectron', Html_Hidden_Variable);
</script>

下面是我如何做到这一点的

获取带有通知数的变量,并将其发送到electron应用程序

Home.html

<script>
//setup the electron object to be able to send variable to it 
const ipcRenderer = require('electron').ipcRenderer;

//send the value Html_Hidden_Variable to electron variable CountNotifElectron 
ipcRenderer.send('CountNotifElectron', Html_Hidden_Variable);
</script>