In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "electron how to make QQ Music client main process and rendering process communication", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to make QQ Music client main process and rendering process communication" this article.
The Electron main process manages all web pages and their corresponding rendering processes, while the rendering process can only manage the corresponding web pages, and the collapse of one rendering process will not affect other rendering processes, so how to communicate between the two processes?
There are two processes in Electron: the main process and the rendering process.
Main process
1. The main process creates a web page by creating an instance of BrowserWindow. Each BrowserWindow instance runs a web page during its rendering process, and when a BrowserWindow instance is destroyed, the corresponding rendering process is terminated.
two。 The main process manages all web pages and their corresponding rendering processes.
Rendering proc
1. The rendering process can only manage the corresponding web pages, and the collapse of one rendering process will not affect other rendering processes.
two。 The rendering process communicates with the main process through IPC to perform GUI operations on the page. For security and possible resource leaks, calling the local GUI-related API directly from the renderer process is limited.
Communication between processes can be done through the Inter-Process Communication (IPC) module: ipcMain and ipcRenderer
To create a window, call the BrowserWindow class, but use it only in the main process (main.js):
Const {BrowserWindow} = require ('electron') const win = new BrowserWindow ()
To call the main process from the rendering process, use the IPC module: for example, custom close window function in clean window mode
1. First, the main process sends a message to the rendering process, telling it the id of the window (multiple rendering processes are started)
Win.once ('ready-to-show', () = > {win.webContents.send (' init_win_id', win.id); win.show ()})
two。 The winid is received by the rendering process and sent to the main process when the window is closed
/ / the rendering process listens for init_win_id events (custom) and assigns winid to the global variable winid let winid =''; require ('electron'). IpcRenderer.on (' init_win_id', (event, message) = > {winid = message }) / / close form function closex () {/ / send window id to the main process const {ipcRenderer} = require ('electron') ipcRenderer.send (' close_window', winid) in the rendering process;}
3. Receive the rendering process that needs to be shut down in the main process
/ / the main process acquires the winid closing form ipcMain.on ('close_window', (event, arg) = > {/ / app.quit ()) A single window can directly app.quit () / / win.close (); / / 1. Receive the window sent by the rendering process id let winid = arg; console.log (winid) / / 2. Find the corresponding BrowserWindow object (win, win22) through id, and call the close () of this object to close the corresponding window BrowserWindow.fromId (winid). Close ();}) these are all the contents of the article "how to make the communication between the main process of the QQ Music client and the rendering process". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.