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

如何從電子的主進程訪問 BrowserWindow Javascript 全局

How to access BrowserWindow Javascript global from main process in electron?(如何從電子的主進程訪問 BrowserWindow Javascript 全局?)
本文介紹了如何從電子的主進程訪問 BrowserWindow Javascript 全局?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想要一個在主進程中定義的菜單,用于在原子/電子應用程序的當前瀏覽器窗口中調用 JS 代碼.

I want a menu, defined in the main process to call JS code inside the current browser window in an atom/electron application.

從瀏覽器窗口獲取主進程全局變量

Getting main process globals form the browser window is

const remote = require('remote')
const foo    = remote.getGlobal('foo')

主進程的等價物是什么(又名獲取當前窗口全局變量).這就是我想用偽代碼做的事情

What is the equivalent for the main process (aka get current window globals). This is what I want to do in pseudo-code

// JS inside main process
const BrowserWindow = require('browser-window')
//...
// Inside the menu callback
let window    = BrowserWindow.getFocusedWindow()
let commander = window.global('commander') /// <---- PSEUDO-CODE !!!
commander.handleCommand('File.Save')

推薦答案

這里 是對您對 api 中 webContents 進程的評論的引用,位于遙控器下的注意:"中.

Here is a reference to your comment about the webContents process in the api, in the "Note:" under remotes.

但是,如果你只是想觸發(fā)一個函數,你也可以使用 webContents.send() 和 ipc(main process) 進程觸發(fā)相應的代碼運行.像這樣的...

However, if you just want to trigger a function, you could also use the webContents.send() and ipc(main process) processes to trigger the appropriate code to run. Something like this...

// JS inside main process
const window = require('electron').BrowserWindow;

ipc.on('menuItem-selected', function(){
    let focusedWindow    = window.getFocusedWindow();
    focusedWindow.webContents.send('file-save');
});

// Inside the menu callback
require('ipc').on('file-save', function() {
  // File save function call here
});

更新:

對于 Electron 0.35.0 及以上版本,ipc api 更改為:

Update:

For Electron version 0.35.0 and above, the ipc api changed to the following:

// In main process.
const ipcMain = require('electron').ipcMain;

// In renderer process (web page).
const ipcRenderer = require('electron').ipcRenderer;

這篇關于如何從電子的主進程訪問 BrowserWindow Javascript 全局?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創(chuàng)建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發(fā)技術
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 上執(zhí)行腳本)
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?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 香蕉视频色版 | 国产又粗又猛视频免费 | 天天操狠狠操 | 毛片网站大全 | 黄色大片免费在线观看 | 国产乱码精品一区二区三 | 91精品免费视频 | 天天爽夜夜爽夜夜爽精品视频 | 日韩av免费看 | 久久精品视频一区二区 | 中文字幕精品在线观看 | 美日韩在线视频 | 日本不卡视频在线观看 | 日韩一区三区 | 午夜影院免费 | 色综合天天综合网国产成人网 | 美女综合网| 欧美精品第一页 | 国产精品久久久一区二区三区 | 国产日韩欧美日韩大片 | 欧美成人精品一区二区三区 | 97视频在线免费观看 | 97视频免费在线观看 | 成人一区二区三区 | 国产无遮挡又黄又爽免费网站 | 成人欧美激情 | 伊人9999| 日本www视频 | 成人午夜免费视频 | 成人在线国产 | 亚洲超碰在线 | 色播亚洲 | 黄色毛毛片 | 欧美激情国产精品 | 日本福利视频 | 五月婷婷激情 | 久久精品播放 | 久久久影院| 日本久久精品视频 | 特级淫片裸体免费看 | 欧美一级淫片 |