Inter-process communication method and device based on Electron framework, equipment and medium

By introducing a shared channel mechanism in the Electron framework, the problem of low efficiency and high coupling of the main process in the traditional inter-process communication method is solved, and more efficient and independent inter-process communication is achieved.

CN118939441APending Publication Date: 2024-11-12RICHFIT INFORMATION TECH +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310520736.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-09
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

In the multi-process model of the Electron framework, the traditional inter-process communication method causes the main process to frequently set and manage message channels between multiple rendering processes, resulting in low work efficiency, high coupling, and increased communication tasks between rendering processes tedious task recognition and processing is required.

Method used

Using the shared channel mechanism, create a shared channel in the main process, and receive and forward the extended message body between rendering processes through the shared channel, avoiding the declaration of a specific message channel in the main process every time, and directly listening and parsing messages in the rendering process. body.

Benefits of technology

It reduces the workload of the main process, improves the work efficiency of the main process, reduces the coupling between processes, improves the independence and efficiency of the rendering process, and simplifies the communication process between processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939441A_ABST
    Figure CN118939441A_ABST
Patent Text Reader

Abstract

The invention discloses an inter-process communication method and device based on an Electron framework, equipment and a medium. The method comprises the following steps: monitoring an established sharing channel in a host process according to a sharing identifier; receiving a first extended message body sent by the first rendering process through the shared channel; the first extended message body comprises a second rendering process identifier, a plurality of service messages and task identifiers thereof; and according to the second rendering process identifier, sending the first extension message body of the shared channel to a second rendering process for monitoring the shared channel, so that the second rendering process analyzes the first extension message body to obtain a plurality of service messages. According to the method provided by the invention, tedious task identification during interaction between the processes is avoided, the workload of the host process is reduced, the performance improvement of the host process is facilitated, the memory space occupation amount is reduced, the working efficiency of the host process and the rendering process is improved, the coupling degree between the processes is reduced, and high-cohesion and low-coupling module independence is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to an inter-process communication method, device, equipment and medium based on the Electron framework. Background Art

[0002] In the multi-process model of the Electron framework, the main process and the rendering process have different responsibilities. Inter-Process Communication (IPC) is the only way to perform many common tasks. It is the only way for the main process to communicate with the rendering process, and between rendering processes. The traditional method of building IPC is:

[0003] 1. Use the main process as a message proxy between rendering processes, and set up a specific message channel in the main process to listen to the task instructions of the two rendering processes;

[0004] 2. Send a message as a task instruction from a rendering process A to a specific message channel set in the main process, and then the main process forwards the message to another rendering process B that listens to the specific message channel;

[0005] 3. Rendering process B executes related tasks or methods based on the message. Summary of the invention

[0006] In order to provide a new inter-process communication method, an embodiment of the present invention provides an inter-process communication method, apparatus, device and medium based on the Electron framework.

[0007] In a first aspect, an embodiment of the present invention provides an inter-process communication method based on the Electron framework, which is applied to a main process. The method includes:

[0008] The shared channel created by monitoring according to the shared identifier; the shared channel is provided with the shared identifier;

[0009] receiving, through the shared channel, a first extended message body sent by the first rendering process; the first extended message body including a second rendering process identifier, a plurality of service messages and task identifiers thereof;

[0010] According to the second rendering process identifier, the first extended message body of the shared channel is sent to the second rendering process monitoring the shared channel, so that the second rendering process parses the first extended message body to obtain the multiple service messages.

[0011] Based on the foregoing implementation, in an optional implementation of the embodiment of the present application, the monitoring of the created shared channel includes:

[0012] During the life cycle of the application, according to the sharing identifier, the sharing channel is monitored to see whether a first rendering process initiates a connection request thereto, and a notification instruction is sent to the first rendering process and the second rendering process.

[0013] Based on the foregoing implementation, in an optional implementation of the embodiment of the present application, the number of the second rendering processes is at least two;

[0014] The step of sending the first extended message body of the shared channel to the second rendering process monitoring the shared channel according to the second rendering process identifier, so that the second rendering process parses the first extended message body to obtain the multiple service messages, includes:

[0015] The second rendering process sent by the target is determined according to the second rendering process identifier in the first extended message body, and the first extended message body is sent to the second rendering process sent by the target that monitors the shared channel, so that the second rendering process sent by the target parses the first extended message body to obtain the multiple service messages.

[0016] Based on the foregoing implementation, in an optional implementation of the embodiment of the present application, according to the listening event of the second rendering process sent by the target, a notification instruction is sent to the second rendering process sent by the target, so that the second rendering process parses the first extended message body according to the parsing instruction.

[0017] In a second aspect, an embodiment of the present invention provides an inter-process communication method based on the Electron framework, which is applied to a first rendering process, and the method includes:

[0018] If multiple service messages and their task identifiers are received, the multiple service messages, the multiple task identifiers and the second rendering process identifier are encapsulated to obtain a first extended message body;

[0019] The first extended message body is sent to the shared channel of the main process according to the shared identifier of the shared channel.

[0020] Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the shared channel is monitored according to the shared identifier;

[0021] receiving a second extended message body sent by the shared channel; the second extended message body includes the first rendering process identifier, the multiple service messages and their task identifiers;

[0022] The second extended message body is parsed to obtain multiple service messages, so as to execute corresponding tasks according to the multiple service messages.

[0023] In a third aspect, an embodiment of the present invention provides an inter-process communication method based on the Electron framework, which is applied to a second rendering process, and the method includes:

[0024] Monitoring the shared channel according to the shared identifier of the shared channel;

[0025] receiving a first extended message body sent by the shared channel; the first extended message body includes a second rendering process identifier, the multiple service messages and their task identifiers;

[0026] The first extended message body is parsed to obtain multiple service messages, so as to execute corresponding tasks according to the multiple service messages.

[0027] In a fourth aspect, an embodiment of the present invention provides an inter-process communication device based on the Electron framework, which is applied to a main process, and the device includes:

[0028] A first monitoring module, configured to monitor a created shared channel according to a shared identifier; the shared channel is provided with a shared identifier;

[0029] A first receiving module, configured to receive a first extended message body sent by a first rendering process through the shared channel; the first extended message body includes a second rendering process identifier, a plurality of service messages and task identifiers thereof;

[0030] The first sending module is used to send the first extended message body of the shared channel to the second rendering process monitoring the shared channel according to the second rendering process identifier, so that the second rendering process parses the first extended message body to obtain the multiple service messages.

[0031] In a fifth aspect, an embodiment of the present invention provides an inter-process communication device based on the Electron framework, which is applied to a first rendering process, and the device includes:

[0032] A message encapsulation module, configured to encapsulate the multiple business messages, the task identifiers and the second rendering process identifier to obtain a first extended message body if multiple business messages and their task identifiers are received;

[0033] The second sending module is used to send the first extended message body to the shared channel of the main process.

[0034] In a sixth aspect, an embodiment of the present invention provides an inter-process communication device based on the Electron framework, which is applied to a second rendering process, and the device includes:

[0035] A second monitoring module, configured to monitor the shared channel according to the shared identifier of the shared channel;

[0036] A second receiving module is configured to receive a first extended message body sent by the shared channel; the first extended message body includes a second rendering process identifier, the multiple service messages and their task identifiers;

[0037] The message parsing module is used to parse the first extended message body to obtain multiple business messages so as to execute corresponding tasks according to the multiple business messages.

[0038] In a seventh aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the inter-process communication method based on the Electron framework as described above.

[0039] In an eighth aspect, an embodiment of the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the inter-process communication method based on the Electron framework as described above is implemented.

[0040] In a ninth aspect, an embodiment of the present invention provides a computer program product comprising instructions, which, when the computer program product is run on a computer device, enables the computer device to execute the inter-process communication method based on the Electron framework as described above.

[0041] In the tenth aspect, an embodiment of the present invention provides a chip, the chip includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement the inter-process communication method based on the Electron framework as described above.

[0042] The beneficial effects of the above technical solution provided by the embodiment of the present invention include at least:

[0043] The inter-process communication method based on the Electron framework provided in the embodiment of the present invention monitors the created shared channel in the main process according to the shared identifier, receives the first extended message body sent by the first rendering process through the shared channel, and sends the first extended message body of the shared channel to the second rendering process that monitors the shared channel according to the second rendering process identifier, so that the second rendering process parses the first extended message body to obtain multiple business messages. By registering a shared channel in the main process, inter-process communication is realized, and tedious task identification is avoided during the interaction between processes, which reduces the workload of the main process, improves the work efficiency of the main process, and is conducive to the performance improvement of the main process; at the same time, the workload in the rendering process is reduced, the memory space occupied is reduced, the work efficiency is improved, the coupling between processes is reduced, and the module independence with high cohesion and low coupling is realized.

[0044] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.

[0045] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0047] Figure 1 A schematic diagram of a traditional IPC construction method provided by an embodiment of the present invention;

[0048] Figure 2 A schematic diagram of a process flow of an inter-process communication method based on the Electron framework provided in an embodiment of the present invention;

[0049] Figure 3 A schematic diagram of an inter-process communication method provided by an embodiment of the present invention;

[0050] Figure 4 A schematic diagram of the process flow of message transmission during inter-process communication provided by an embodiment of the present invention;

[0051] Figure 5 A schematic diagram of execution steps in a main process provided by an embodiment of the present invention;

[0052] Figure 6 A pseudo code comparison diagram of the embodiment of the present invention and the traditional IPC in the main process provided by the embodiment of the present invention;

[0053] Figure 7 A schematic diagram of the workflow in the main process provided by an embodiment of the present invention;

[0054] Figure 8 A schematic diagram of the steps executed in the first rendering process provided by an embodiment of the present invention;

[0055] Fig. 9 A pseudo code comparison diagram of the embodiment of the present invention and the traditional IPC in the first rendering process provided by the embodiment of the present invention;

[0056] Fig.10 A schematic diagram of a workflow in a first rendering process provided by an embodiment of the present invention;

[0057] Fig.11 A schematic diagram of the steps executed in the second rendering process provided by an embodiment of the present invention;

[0058] Fig.12 A pseudo code comparison diagram of the embodiment of the present invention and the traditional IPC in the second rendering process provided by the embodiment of the present invention;

[0059] Fig.13 A schematic diagram of a workflow in a second rendering process provided by an embodiment of the present invention;

[0060] Fig.14 A schematic diagram of the structure of an inter-process communication device based on the Electron framework applied to a main process provided by an embodiment of the present invention;

[0061] Fig.15 A schematic structural diagram of an inter-process communication device based on the Electron framework provided by an embodiment of the present invention and applied to a first rendering process;

[0062] Fig.16 A schematic structural diagram of an inter-process communication device based on the Electron framework provided in an embodiment of the present invention and applied to a second rendering process. DETAILED DESCRIPTION

[0063] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0064] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0065] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0066] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0067] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0068] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0069] It should be understood that the size of the serial numbers of the steps in the following embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0070] In order to illustrate the technical solution of the present application, a specific embodiment is provided below for illustration.

[0071] The inventor found that in the prior art, referring to Figure 1 As shown, in the traditional IPC construction method, for each new inter-process communication task, it is necessary to set a specific message channel (channel 1, channel 2, channel 3 ...) for monitoring the two rendering processes in the main process. When there are too many task instructions that need to be communicated between the two rendering processes, it is necessary to register multiple message channels in the main process, which makes the work efficiency low during the implementation process, and easily causes redundant workload, and the coupling between the main process and the rendering process is too high. Based on this, the inventor has made the present invention after further research and development, and provides an inter-process communication method, device, equipment and medium based on the Electron framework.

[0072] Embodiment 1

[0073] The embodiment of the present invention provides an inter-process communication method based on the Electron framework, which is implemented by creating a shared channel in the main process. Figure 2 As shown, when the communication task instructions between rendering processes increase, there is no need to declare the corresponding specific message channel in the main process every time. It is only necessary to listen to the shared channel in the rendering process that receives the task instructions to receive the encapsulated extended message body with the task identifier and the rendering process identifier passed by the main process, and execute the corresponding tasks and methods by parsing the extended message body. Figure 2 A flow chart of an inter-process communication method based on the Electron framework provided in the first embodiment of the present invention is shown. For the sake of convenience, the communication between the main process, the first rendering process, and the second rendering process is taken as an example, and only the parts related to this embodiment are shown.

[0074] To facilitate understanding of the inter-process communication method based on the Electron framework proposed in the embodiment of the present application, the Electron framework is first introduced below:

[0075] Electron is a framework for building desktop applications using JavaScript, HTML, and CSS. By embedding Chromium and Node.js into its binary, Electron allows developers to maintain a single JavaScript codebase and create cross-platform applications that can run on Windows, macOS, and Linux.

[0076] Electron provides a rich operating system application programming interface (Application Programming Interface, API), enabling developers to create desktop applications purely using JavaScript. Unlike other Node.js runtimes, Electron focuses on desktop applications rather than web servers.

[0077] Electron inherits its multi-process architecture from Chromium, which makes the framework very similar to modern web browsers in architecture, and web browsers are very complex applications. In addition to the main function of displaying web content, they have many secondary responsibilities, such as managing multiple windows or tabs, and loading third-party extensions. Therefore, the multi-process module is one of the important functional feature modules of Electron.

[0078] Electron's multi-process module is mainly divided into the main process (Main Process), the renderer process (RendererProcess) and IPC. The renderer process can also be called the rendering process.

[0079] Each Electron application has a single main process, which is the entry point of the application. The main process runs in the Node.js environment, which means it has the ability to request modules and use all Node.js APIs. The main process consists of the following parts:

[0080] 1. Window Management

[0081] The main purpose of the main process is to create and manage application windows using the BrowserWindow module. Each instance of the BrowserWindow class creates an application window and loads a web page in a separate renderer process. You can interact with the web content from the main process using the webContent object of the window class. Responsible for rendering and controlling the web page, which is also a property of the objects in the BrowserWindow class.

[0082] 2. Application Lifecycle

[0083] The main process can also control the life cycle of the application through Electron's Application (App) module. This module provides a full set of events and methods that allow developers to add custom application behaviors, such as programmatically exiting the application, modifying the dock, or showing the about panel.

[0084] 3. Native API

[0085] In order to make Electron's functions more than just encapsulating web content, the main process also adds a custom API to interact with the user's operating system. Electron has a variety of modules that control native desktop functions, such as menus, dialog boxes, and tray icons.

[0086] Among them, each Electron application will generate a separate rendering process for each open BrowserWindow, or generate a separate rendering process for each BrowserWindow embedded with each web page, which is responsible for rendering the web page content.

[0087] Among them, IPC is a key part of building feature-rich desktop applications in Electron. Because the main process and renderer process have different responsibilities in Electron's multi-process module, such as Figure 3 As shown, IPC is the only way to perform many common tasks and the only way for the main process to communicate with the rendering process, and between rendering processes.

[0088] Take the more complex communication between two rendering processes, the first rendering process and the second rendering process as an example. Figure 3 As shown, the traditional method of IPC construction is:

[0089] 1. Use the main process as a message agent between rendering processes, and set up a message channel (Channel) in the main process to listen to the task instructions of the two rendering processes;

[0090] 2. Send the message as the task instruction from the first rendering process to the message channel, and then the main process forwards the message to another second rendering process that monitors the message channel;

[0091] 3. The second rendering process executes related tasks or methods according to the message.

[0092] Since this method has low working efficiency, when the communication task instructions between rendering processes increase, a specific message channel needs to be declared in the main process each time. The inventor proposes to create a shared channel in the main process, and use the shared channel as a transit station to receive and forward messages to achieve communication between rendering processes.

[0093] In this embodiment, taking the communication between the main process, the first rendering process, and the second rendering process as an example, the process of the first rendering process communicating with the second rendering process is as follows: Figure 4 As shown, during the user's use, when the first rendering process receives a user operation instruction and requires the second rendering process to complete a task, the first rendering process will first call the message encapsulation module to encapsulate business data and task instructions and other data into a first extended message body; then, the first rendering process calls the sending method of the ipcRenderer module to send the first extended message body to the shared channel of the main process; after the main process monitors the first extended message body of the first rendering process, it forwards the first extended message body to the second rendering process; at the same time, after the second rendering process monitoring the shared channel receives the first extended message body, it calls the message parsing module to parse the first extended message body into task instructions, business messages, etc., and then schedules the task through the task instructions and business data to complete the task.

[0094] The following takes the communication between the main process, the first rendering process (named renderer_a in the following pseudo code), and the second rendering process (named renderer_b in the following pseudo code) as an example to specifically introduce the inter-process communication method based on the Electron framework:

[0095] In this embodiment, refer to Figure 5 As shown, the main process will perform the following steps:

[0096] S101, monitoring a created shared channel according to a shared identifier; the shared channel is provided with a shared identifier;

[0097] The monitoring of the created shared channel described in step S101 above specifically includes:

[0098] During the life cycle of the application, according to the sharing identifier, the sharing channel is monitored to see whether a first rendering process initiates a connection request thereto, and a notification instruction is sent to the first rendering process and the second rendering process.

[0099] In step S101, it is necessary to first confirm the shared identifier of the shared channel. The shared identifier is a unique identifier sent and monitored by the rendering process. For example, the shared identifier can be marked as 'CommonChannel'. After confirming the shared identifier, a shared channel with the shared identifier is created in the main process. The main process continuously monitors the shared channel throughout the life cycle of the application through the ipcMain module of the Electron API to monitor whether there is a rendering process that issues a connection request to the shared channel. Among them, the ipcMain module of the Electron API is an instance of the EventEmitter class. When used in the main process, it controls the asynchronous or synchronous messages sent by the rendering process, and the messages sent from the rendering process will trigger events.

[0100] S102: receiving a first extended message body sent by a first rendering process through the shared channel; the first extended message body includes a second rendering process identifier, a plurality of service messages and task identifiers thereof;

[0101] In step S102, the main process monitors the shared channel (CommonChannel) through the Electron API, registers the shared channel in the rendering process, and sends a notification instruction to the rendering process. All rendering processes also monitor the shared channel throughout the application life cycle. During the monitoring process, the main process receives the first extended message body (which can be named specialMsg) sent by the first rendering process. The first extended message body contains the identifier of the target rendering process (i.e., the second rendering process identifier), multiple business messages and their task identifiers. The task identifier is an identifier determined according to the task instruction, which is determined at the beginning of the entire application life cycle.

[0102] S103: Send the first extended message body of the shared channel to a second rendering process that monitors the shared channel according to the second rendering process identifier, so that the second rendering process parses the first extended message body to obtain the multiple service messages.

[0103] The specific implementation process of the above step S103 may include:

[0104] According to the second rendering process identifier in the first extended message body, the second rendering process sent by the target is determined, and the first extended message body is sent to the second rendering process sent by the target that monitors the shared channel, so that the second rendering process sent by the target parses the first extended message body to obtain the multiple business messages. The second rendering process identifier can be obtained by the main process, and the main process will confirm the target rendering process to which the first extended message body is forwarded according to the second rendering process identifier.

[0105] In step S103, after receiving the first extended message body sent by the first rendering process to the shared channel, the main process sends an instruction to the target rendering process (i.e., the second rendering process) according to the rendering process identifier of the first extended message body, to the listening event of the second rendering process, and then forwards the message to the second rendering process. After receiving the instruction and the first extended message body, the listening event of the second rendering process parses the first extended message body.

[0106] In the embodiment of the present invention, the pseudo code for implementing the specific execution process of the above steps S101 to S103 is as follows:

[0107] ipcMain.on('CommonChannel',(specialMsg,event){

[0108] renderer_b.webContents.send('CommonChannel',specialMsg);

[0109] });

[0110] In the embodiment of the present invention, by designing a shared channel, when the number of communication task instructions between rendering processes increases, there is no need to declare a specific message channel in the main process each time. It is only necessary to monitor the shared message channel in the rendering process that receives the task notification, so as to pass a special message body to identify the task and method, and execute the corresponding task and method by parsing the special message body. Assuming that there are 4 business messages between the first rendering process and the second rendering process that need to be transmitted by the main process, the traditional IPC method needs to register 4 specific message channels in the main process, and each task instruction corresponds to a specific message channel; and the inter-process communication method based on the Electron framework provided in the embodiment of the present invention only needs to set up 1 shared channel, and the main process does not need to care about the task association between the rendering processes, and only needs to provide a shared channel for the transmission of the extended message body. Reference Figure 6As shown, by comparing the pseudo code of the traditional IPC with the pseudo code of the main process in the inter-process communication method based on the Electron framework provided by an embodiment of the present invention, it can be found that the workload of the main process is greatly reduced, and the development efficiency can be improved, the coupling between the main process and the rendering process can be reduced, the heavy development workload in the main process can be avoided, and code redundancy can be reduced.

[0111] It should be noted that renderer_b is used as the sending object in the above pseudo code because this embodiment takes the communication between the main process, the first rendering process, and the second rendering process as an example, and the main process reads the rendering process identifier from the first extended message body as the identifier corresponding to the second rendering process. In actual applications, the shared channel receives multiple extended message bodies at the same time, containing multiple rendering process identifiers, and the part of searching for the rendering process sent by the target can be added before sending the instruction.

[0112] The specific process executed in the main process is as follows Figure 7 As shown, the main process creates and monitors the shared channel module, receives the first extended message body from the first rendering process, and forwards the first extended message body to the corresponding second rendering process according to the rendering process identifier included in the first extended message body.

[0113] In this embodiment, refer to Figure 8 As shown, the first rendering process will perform the following steps:

[0114] S201, receiving multiple business messages and their task identifiers, encapsulating the multiple business messages, multiple task identifiers and the second rendering process identifier to obtain a first extended message body;

[0115] In step S201, after receiving the service message, the first rendering process needs to send the message to the shared channel in the main process, and then the shared channel forwards the message to the second rendering process to complete the entire inter-process communication process. In this process, after the first rendering process receives multiple service messages and their task identifiers, it needs to encapsulate the service messages in sequence. The specific steps of encapsulation are as follows:

[0116] 1. In the first rendering process, a message encapsulation module is called to receive task instructions and business data contained in a regular business message as parameters and encapsulate the message;

[0117] 2. Encapsulate the received regular business message into a first extended message body having business information, task identifier, rendering process identifier, etc. The task identifier is an identifier corresponding to the task instruction contained in the business message; the rendering process identifier is an identifier corresponding to the rendering process that needs to receive the business message, for example, the identifier corresponding to the second rendering process is the second rendering process identifier.

[0118] S202: Send the first extended message body to the shared channel of the main process.

[0119] In step S202, after encapsulating multiple business messages, the first rendering process needs to pass them to the corresponding second rendering process to perform the task. Here, the first extended message body is transmitted through the ipcRenderer module of the Electron API to send the first extended message body to the shared channel in the main process, and then the shared channel forwards it according to steps S102 and S103. Among them, the ipcRenderer module of the Electron API is an instance of the EventEmitter class. It provides limited methods to send synchronous or asynchronous messages from the rendering process to the main process, and also to receive responses from the main process.

[0120] In the embodiment of the present invention, the pseudo code for implementing the specific execution process of the above steps S201 to S202 is as follows:

[0121] var specialMsg=package(msg);

[0122] renderer_a.ipcRenderer.send('CommonChannel',specialMsg);

[0123] In the embodiment of the present invention, the first rendering process encapsulates the conventional business message into a first extended message body having business information, task identifier, rendering process identifier, etc., and sends the first extended message body to the shared channel of the main process. When the communication task instructions between rendering processes increase, the first rendering process does not need to send business messages through a specific message channel every time. Fig. 9 As shown, by comparing the pseudo code of the traditional IPC with the pseudo code of the first rendering process in the inter-process communication method based on the Electron framework provided by an embodiment of the present invention, it can be found that the workload of the first rendering process is greatly reduced, the code is neater and lighter, and there is no one-to-one strong coupling between the first rendering process and the main process, achieving module independence with high cohesion and low coupling.

[0124] The specific process performed in the first rendering process is as follows Fig.10 As shown, the first rendering process calls the message encapsulation module to encapsulate the conventional business message into a first extended message body with business information, task identifier, and rendering process identifier, and sends it to the shared channel in the main process, which is then forwarded to the second rendering process corresponding to the rendering process identifier by the shared channel.

[0125] In this embodiment, refer to Fig.11 As shown, the second rendering process will perform the following steps:

[0126] S301, monitoring the shared channel according to the shared identifier of the shared channel;

[0127] In step S301, the second rendering process monitors the shared channel in the main process through the Electron API throughout the application life cycle. When the second rendering process is created, a monitoring event is registered and initialized, and the monitoring event is used to monitor the notification instruction sent by the main process to the second rendering process.

[0128] S302, receiving a first extended message body sent by the shared channel; the first extended message body includes a second rendering process identifier, the multiple business messages and their task identifiers;

[0129] In step S302, when the first extended message body needs to be sent to the second rendering process, the main process will send a notification instruction to the monitoring event of the second rendering process after confirming the second rendering process identifier in the first extended message body. After receiving the notification instruction, the second rendering process responds, receives the first extended message body and parses it.

[0130] S303: Parse the first extended message body to obtain multiple service messages, so as to execute corresponding tasks according to the multiple service messages.

[0131] In step S303, after the second rendering process receives the first extended message body sent by the first rendering process and forwarded by the main process, it needs to parse the first extended message body. The specific steps of parsing are as follows:

[0132] 1. Call the message parsing (parse) module to parse the first extended message body into a business message. The input parameter of the message parsing module is the first extended message body.

[0133] 2. Execute relevant tasks or methods according to the multiple business messages obtained by parsing the first extended message body.

[0134] In the embodiment of the present invention, the pseudo code for implementing the specific execution process of the above steps S301 to S303 is as follows:

[0135]

[0136] In the embodiment of the present invention, the second rendering process receives and parses the first extended message body through a shared channel, parses the first extended message body into multiple business messages before encapsulation, and then executes related tasks or methods according to the multiple business messages obtained by parsing. When the communication task instructions between rendering processes increase, the second rendering process does not need to receive business messages through a specific message channel every time. Fig.12As shown, by comparing the pseudo code of the traditional IPC with the pseudo code of the second rendering process in the inter-process communication method based on the Electron framework provided by an embodiment of the present invention, it can be found that the workload of the second rendering process is greatly reduced, code redundancy is reduced, and the coupling degree between the main process and the second rendering process is reduced.

[0137] It should be noted that ipcRenderer.on() in the above pseudo code is the API method provided by the main process to all rendering processes. It specifically registers a shared channel in the rendering process to receive notification instructions from the main process. After registration, the extended message body forwarded by the main process can be received.

[0138] The specific process executed in the second rendering process is as follows Fig.13 As shown, after the second rendering process monitors the notification instruction sent by the main process, it receives the first extended message body forwarded by the main process and calls the message parsing module to parse it, and executes related tasks or methods through multiple business messages obtained by parsing.

[0139] In this embodiment, the inter-process communication based on the Electron framework is introduced by taking the communication between the main process, the first rendering process, and the second rendering process as an example. In actual operation, the inter-process communication is complicated. When a rendering process needs to send an extended message body, there must be at least one rendering process to receive the extended message body. In the inter-process communication, the number of rendering processes is at least two.

[0140] It should be noted that, in this embodiment, the first rendering process and the second rendering process are used to distinguish between the message sender and the message receiver, but in fact all rendering processes can send and receive messages, that is, they all contain a message encapsulation module and a message parsing module, and all rendering processes can communicate and interact through the shared channel of the main process. Therefore, in the process of inter-process communication in this embodiment, the first rendering process also includes the following work content:

[0141] According to the sharing identifier, monitoring the shared channel;

[0142] receiving a second extended message body sent by the shared channel; the second extended message body includes the first rendering process identifier, the multiple service messages and their task identifiers;

[0143] The second extended message body is parsed to obtain multiple service messages, so as to execute corresponding tasks according to the multiple service messages.

[0144] In this embodiment, the second rendering process sends a second extended message body encapsulated by the second rendering process to the shared channel of the main process, the second extended message body contains the first rendering process identifier, and the shared channel sends a notification instruction to the first rendering process according to the first rendering process identifier in the second extended message body. After receiving the notification instruction, the first rendering process that is listening to the shared channel parses the received second extended message body and executes related tasks according to the business message obtained by the analysis.

[0145] Embodiment 2

[0146] Based on the same inventive concept, the embodiment of the present invention also provides an inter-process communication device based on the Electron framework, which is applied to the main process, referring to Fig.14 As shown, the device includes a first monitoring module 101, a first receiving module 102, and a first sending module 103, wherein:

[0147] A first monitoring module 101 is used to monitor a shared channel created according to a shared identifier; the shared channel is provided with a shared identifier;

[0148] A first receiving module 102 is configured to receive a first extended message body sent by a first rendering process through the shared channel; the first extended message body includes a second rendering process identifier, a plurality of service messages and their task identifiers;

[0149] The first sending module 103 is used to send the first extended message body of the shared channel to the second rendering process monitoring the shared channel according to the second rendering process identifier, so that the second rendering process parses the first extended message body to obtain the multiple service messages.

[0150] Embodiment 3

[0151] Based on the same inventive concept, the embodiment of the present invention also provides an inter-process communication device based on the Electron framework, which is applied to the first rendering process, referring to Fig.15 As shown, the device includes a message encapsulation module 201 and a second sending module 202, wherein:

[0152] The message encapsulation module 201 is used for encapsulating the multiple business messages, task identifiers and the second rendering process identifier to obtain a first extended message body if multiple business messages and task identifiers thereof are received;

[0153] The second sending module 202 is used to send the first extended message body to the shared channel of the main process.

[0154] Embodiment 4

[0155] Based on the same inventive concept, the embodiment of the present invention also provides an inter-process communication device based on the Electron framework, which is applied to the second rendering process, referring to Fig.16 As shown, the device includes a second monitoring module 301, a second receiving module 302, and a message parsing module 303, wherein:

[0156] A second monitoring module 301 is used to monitor the shared channel according to the shared identifier of the shared channel;

[0157] The second receiving module 302 is used to receive a first extended message body sent by the shared channel; the first extended message body includes a second rendering process identifier, the multiple service messages and their task identifiers;

[0158] The message parsing module 303 is used to parse the first extended message body to obtain multiple service messages so as to execute corresponding tasks according to the multiple service messages.

[0159] Embodiment 5

[0160] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the inter-process communication method based on the Electron framework as described in the above-mentioned embodiment 1.

[0161] Embodiment 6

[0162] Based on the same inventive concept, an embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the inter-process communication method based on the Electron framework as described in the above-mentioned embodiment 1 is implemented.

[0163] Embodiment 7

[0164] Based on the same inventive concept, an embodiment of the present invention further provides a computer program product comprising instructions. When the computer program product is run on a computer device, the computer device executes the inter-process communication method based on the Electron framework as described in the above-mentioned embodiment 1.

[0165] Embodiment 8

[0166] Based on the same inventive concept, an embodiment of the present invention also provides a chip, the chip includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement the inter-process communication method based on the Electron framework as described in the above embodiment one.

[0167] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.

[0168] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0169] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0170] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0171] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. An inter-process communication method based on the Electron framework, characterized in that: Applied to the main process, including: The shared channel created by monitoring according to the shared identifier; the shared channel is provided with the shared identifier; receiving, through the shared channel, a first extended message body sent by the first rendering process; the first extended message body including a second rendering process identifier, a plurality of service messages and task identifiers thereof; According to the second rendering process identifier, the first extended message body of the shared channel is sent to the second rendering process monitoring the shared channel, so that the second rendering process parses the first extended message body to obtain the multiple service messages.

2. The method according to claim 1, characterized in that The shared channel created by monitoring includes: During the life cycle of the application, according to the sharing identifier, the sharing channel is monitored to see whether a first rendering process initiates a connection request thereto, and a notification instruction is sent to the first rendering process and the second rendering process.

3. The method according to claim 1, characterized in that The number of the second rendering processes is at least two; The step of sending the first extended message body of the shared channel to the second rendering process monitoring the shared channel according to the second rendering process identifier, so that the second rendering process parses the first extended message body to obtain the multiple service messages, includes: The second rendering process sent by the target is determined according to the second rendering process identifier in the first extended message body, and the first extended message body is sent to the second rendering process sent by the target that monitors the shared channel, so that the second rendering process sent by the target parses the first extended message body to obtain the multiple service messages.

4. The method according to claim 3, characterized in that The second rendering process monitors the shared channel; the method further includes: According to the monitoring event of the second rendering process sent by the target, a notification instruction is sent to the second rendering process sent by the target, so that the second rendering process parses the first extended message body according to the parsing instruction.

5. An inter-process communication method based on the Electron framework, characterized in that: Applied to the first rendering process, including: If multiple service messages and their task identifiers are received, the multiple service messages, the multiple task identifiers and the second rendering process identifier are encapsulated to obtain a first extended message body; The first extended message body is sent to the shared channel of the main process according to the shared identifier of the shared channel.

6. The method according to claim 1, characterized in that Also includes: According to the sharing identifier, monitoring the shared channel; receiving a second extended message body sent by the shared channel; The second extended message body includes the first rendering process identifier, the multiple business messages and their task identifiers; The second extended message body is parsed to obtain multiple service messages, so as to execute corresponding tasks according to the multiple service messages.

7. An inter-process communication method based on the Electron framework, characterized in that: Applied to the second rendering process, including: Monitoring the shared channel according to the shared identifier of the shared channel; receiving a first extended message body sent by the shared channel; the first extended message body includes a second rendering process identifier, a plurality of service messages and task identifiers thereof; The first extended message body is parsed to obtain the multiple service messages, so as to execute corresponding tasks according to the multiple service messages.

8. An inter-process communication device based on the Electron framework, characterized in that: Applied to the main process, the device includes: A first monitoring module, configured to monitor a created shared channel according to a shared identifier; the shared channel is provided with a shared identifier; A first receiving module, configured to receive a first extended message body sent by a first rendering process through the shared channel; the first extended message body includes a second rendering process identifier, a plurality of service messages and task identifiers thereof; The first sending module is used to send the first extended message body of the shared channel to the second rendering process monitoring the shared channel according to the second rendering process identifier, so that the second rendering process parses the first extended message body to obtain the multiple service messages.

9. An inter-process communication device based on the Electron framework, characterized in that: Applied to a first rendering process, the device comprises: A message encapsulation module, configured to encapsulate the multiple business messages, the task identifiers and the second rendering process identifier to obtain a first extended message body if multiple business messages and their task identifiers are received; The second sending module is used to send the first extended message body to the shared channel of the main process.

10. An inter-process communication device based on the Electron framework, characterized in that: Applied to the second rendering process, the device comprises: A second monitoring module, configured to monitor the shared channel according to the shared identifier of the shared channel; A second receiving module is configured to receive a first extended message body sent by the shared channel; the first extended message body includes a second rendering process identifier, the multiple service messages and their task identifiers; The message parsing module is used to parse the first extended message body to obtain multiple business messages so as to execute corresponding tasks according to the multiple business messages.

11. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the inter-process communication method based on the Electron framework as described in any one of claims 1-4, 5-6 or 7.

12. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the inter-process communication method based on the Electron framework as described in any one of claims 1-4, 5-6 or 7 is implemented.

13. A computer program product comprising instructions, which, when executed on a computer device, enables the computer device to execute the inter-process communication method based on the Electron framework as described in any one of claims 1-4, 5-6 or 7.

14. A chip, comprising a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement the inter-process communication method based on the Electron framework as described in any one of claims 1-4, 5-6 or 7.

Citation Information

Cited By

  • Method for realizing cross-process communication in Electron based on pipeline

    CN119149270A