久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Electron:從 main 調用渲染器函數

Electron: Call renderer function from main(Electron:從 main 調用渲染器函數)
本文介紹了Electron:從 main 調用渲染器函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在本地存儲中有一些數據必須在 app.quit() 上刪除.但我認為從主要過程中無法做到這一點.

I have some data in the localstorage that has to be deleted on app.quit(). But I see no way to do so from the main process.

有沒有辦法從 main 調用 renderer 函數?

Is there a way to call a renderer function from main?

我知道 var remote = require('remote'); 但它似乎只走錯了方向.

I know about var remote = require('remote'); but it seems to go only in the wrong direction.

推薦答案

您可以通過 webContents.send 將消息從主進程發送到渲染器進程,如此處文檔中所述:https://github.com/atom/electron/blob/master/docs/api/web-contents.md#webcontentssendchannel-arg1-arg2-.

You can send messages from the main process to a renderer process via webContents.send as called out in the documentation here: https://github.com/atom/electron/blob/master/docs/api/web-contents.md#webcontentssendchannel-arg1-arg2-.

以下是您直接從文檔中執行此操作的方法:

Here is how you do it straight from the docs:

在主進程中:

// In the main process.
var window = null;
app.on('ready', function() {
  window = new BrowserWindow({width: 800, height: 600});
  window.loadURL('file://' + __dirname + '/index.html');
  window.webContents.on('did-finish-load', function() {
    window.webContents.send('ping', 'whoooooooh!');
  });
});

在 index.html 中:

In index.html:

<!-- index.html -->
<html>
<body>
  <script>
    require('electron').ipcRenderer.on('ping', function(event, message) {
      console.log(message);  // Prints "whoooooooh!"
    });
  </script>
</body>
</html>

注意它是異步的.我不確定這對您的特定解決方案有何影響,但這至少應該讓您與渲染器進程對話.

Note it is asynchronous. I am not sure how that affects things with your particular solution, but this should at least get you talking back to the renderer process.

這篇關于Electron:從 main 調用渲染器函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 久久精品一区二区三区四区 | 日韩欧美精品在线 | 一区二区免费 | 欧美成人久久 | av网站在线看| 中文字幕成人在线 | 国产精品久久久久久久久久免费 | 黄色操视频 | 日本综合在线观看 | 欧美高清免费 | 国产精品一区久久久 | 国产福利视频导航 | 亚洲欧美一区在线 | 亚洲激情一级片 | 国产精品日日做人人爱 | 天堂在线中文字幕 | 国产视频久久 | 四虎成人免费电影 | 精品国产欧美一区二区三区成人 | 久久久av | 亚洲欧美精品久久 | 美女久久久久久久久 | 超碰最新在线 | 欧美日韩中文字幕在线 | 69xxx免费| 午夜无码国产理论在线 | 九九99精品 | 在线观看国产网站 | 在线视频成人 | 亚洲精品久久久一区二区三区 | 国产精品一区二区免费 | 日韩图区| 欧美不卡一区 | 521av网站| av入口| 欧美xxxx做受欧美 | 亚洲午夜精品一区二区三区他趣 | 日日做夜夜爽毛片麻豆 | 欧美日韩综合视频 | 天堂一区二区三区 | 欧美一区成人 |