Component application method based on Electron application program

By loading and mounting component method objects in Electron application, the problem of low efficiency of component application in Electron application is solved, the components are decoupled and combined, and the reusability and application efficiency are improved.

CN119645536AActive Publication Date: 2025-03-18CHINA MOBILE INTERNET CO LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411647770.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-03-18
Estimated Expiration
2044-11-18

AI Technical Summary

Technical Problem

Electron applications lack common component (or plug-in) access solutions, resulting in strong coupling between applications and plug-ins, bloated applications, and difficult to reuse and customize components.

Method used

By loading each component in the resource directory of the Electron application, obtain the method object exported by the main process of each component, and mount it on the preset object of the Electron application for call.

Benefits of technology

It realizes the decoupling and combination of component functions, meets the free customized product development needs of different users, improves the reusability of components, reduces the coupling between Electron applications and components, and improves the efficiency of component applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119645536A_ABST
    Figure CN119645536A_ABST
Patent Text Reader

Abstract

The invention discloses a component application method based on an Electron application program. The component application method comprises the following steps: loading each component in a resource directory of the Electron application program; obtaining a method object correspondingly exported by the host process of each component; and the method object is mounted on a preset object of the Electron application program, so that the method object can be called by the Electron application program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of Electron client development, and in particular to a component application method based on Electron application programs. Background Art

[0002] The Electron application is a framework for building desktop applications using Javascript, HTML, and CSS. It embeds the Chromium browser engine and the Node.js environment, has cross-platform features, and allows developers to quickly implement local client applications using Web development technology. Currently, in order to adapt to domestic systems, many desktop applications are built based on the Electron framework. As application scenarios become more and more diverse, different modules of the application need to be split into different components to facilitate business decoupling and on-demand combination.

[0003] Currently, Electron applications do not provide a solution for accessing general components (or plug-ins). Some developers have proposed directly introducing all components, which results in strong coupling between applications and plug-ins, and bloated applications.

[0004] How to introduce the required different components into the Electron application to develop customized products for users in scenarios where different users need different component modules, improve the reusability of components, reduce the coupling between Electron applications and components, and improve the efficiency of component application, is a technical problem that needs to be solved at present. Summary of the invention

[0005] The purpose of the embodiment of the present application is to provide a component application method based on the Electron application to solve the problem of low component application efficiency of the Electron application.

[0006] In order to solve the above technical problems, this specification is implemented as follows: In a first aspect, a component application method based on an Electron application is provided, comprising: Load the components in the resource directory of the Electron application; Get the exported method object corresponding to the main process of each component; The method object is mounted on a preset object of the Electron application so as to be called by the Electron application.

[0007] Optionally, the components in the resource directory of the Electron application are loaded, including: Introducing code for loading a main process script of a component into the main process code of the Electron application; Based on the code of the main process script for loading components, trigger the main process of the Electron application to scan the corresponding resource file path in the resource directory; By scanning the main process of the Electron application, each component under the resource file path is loaded.

[0008] Optionally, the scanning of the main process of the Electron application to load each component under the resource file path includes: By scanning the main process of the Electron application, searching for relevant codes and configuration files of each component under the resource file path; Based on the configuration file, determine the target component to be loaded through the main process of the Electron application; The relevant codes and configuration files of the target component are stored through the main process of the Electron application.

[0009] Optionally, the relevant code and configuration files of a component are packaged into an asar package. The scanning of the main process of the Electron application program to search for the relevant code and configuration files of each component under the resource file path includes: By scanning the main process of the Electron application, the asar package under the resource file path is searched to find the relevant code and configuration file of the corresponding component.

[0010] Optionally, the configuration file of the component includes the component name, component ID, and the relative path of the main process entry code of the component. Determining the target component to be loaded through the main process of the Electron application based on the configuration file includes: By judging whether the configuration file in the target asar package carries the component name, determining whether the target asar package is an asar package of the component; If yes, match the component ID in the configuration file of the target asar package with the preset trusted component ID list; If the match is successful, the component corresponding to the target asar package is determined as the target component to be loaded.

[0011] Optionally, obtaining the exported method object corresponding to the main process of each component includes: Based on the relative path of the main process entry code of the component in the configuration file, the main process entry code of the target component is executed through the main process of the Electron application to export the method object corresponding to the target component through the main process of the target component.

[0012] Optionally, mounting the method object onto a preset object of the Electron application comprises: Using the component name of the target component as the key and the method object exported by the main process of the target component as the value, the method object exported by the main process of the Electron application is mounted on the preset object of the Electron application through the main process of the Electron application.

[0013] Optionally, it also includes: When the Electron application starts a new window, load the preload scripts of each component; In the rendering process, it is called based on the preload scripts of each component loaded.

[0014] Optionally, when the Electron application starts a new window, loading the preload script of each component includes: Introducing the code of the preload script for loading the component into the preload script code of the Electron application; When the Electron application starts a new window, based on the code for loading the preload script of the component, the preload script of the Electron application is triggered to load the preload script of each component.

[0015] Optionally, in the rendering process, calling based on the preload scripts of each loaded component includes: In the rendering process, the method object carried in the preload script of each loaded component is called by the rendering process of the Electron application.

[0016] In an embodiment of the present application, by loading each component in the resource directory of the Electron application, obtaining the method object exported by the main process of each component, and mounting the method object on the preset object of the Electron application for calling by the Electron application, the existing components in the resource directory of the Electron application can be utilized to achieve decoupling and combination of component functions without changing too much code, thereby meeting the needs of different users to achieve free customized product development, improving the reusability of components, reducing the coupling between the Electron application and the components, and improving the efficiency of component application. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 It is a flowchart of a component application method based on an Electron application program according to an embodiment of the present application.

[0018] Figure 2 It is a schematic diagram of the corresponding functions of the Electron application program according to the embodiment of the present application.

[0019] Figure 3 It is a schematic diagram of the application architecture of the Electron application and corresponding components of an embodiment of the present application.

[0020] Figure 4 It is a schematic diagram of the overall process of the component application method based on the Electron application program in the embodiment of the present application.

[0021] Figure 5 It is a structural block diagram of a component application device based on an Electron application program according to an embodiment of the present application. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application. The numbering of the drawings in this application is only used to distinguish the various steps in the scheme, and is not used to limit the execution order of the various steps. The specific execution order is subject to the description in the specification.

[0023] In order to solve the problems existing in the prior art, the embodiment of the present application provides a component application method based on the Electron application program based on the development scenario of accessing multiple components in the Electron framework, such as Figure 1 As shown, the steps include steps 12 to 16.

[0024] Step 12: Load the components in the resource directory of the Electron application.

[0025] The component (i.e., application component) of the embodiment of the present application refers to an independent functional unit in an Electron application, which usually includes code, style, and configuration information related to the interface or business logic. The component is designed to promote the maintainability and reusability of the code.

[0026] The Electron application loading component can be provided in the form of a JavaScript tool library, including the main process function. Specifically, the loading of each component in the resource directory of the Electron application includes: introducing the code of the main process script for loading components in the main process code of the Electron application; based on the code of the main process script for loading components, triggering the main process of the Electron application to scan the corresponding resource file path in the resource directory; through the scanning of the main process of the Electron application, loading each component under the resource file path.

[0027] In this embodiment, the code of the main process script for loading components can be introduced at the beginning of the main process code of the Electron application. By modifying the main process code, after the Electron application is started, the main process of the Electron application can automatically scan which components are in the resource directory of the Electron application based on the introduced code. By scanning the corresponding resource file path in the resource directory, the corresponding component can be found and loaded.

[0028] Loading components mainly obtains data related to each component under the corresponding resource file path to facilitate subsequent component calls. Specifically, the components under the resource file path are loaded through scanning by the main process of the Electron application, including: searching for relevant codes and configuration files of each component under the resource file path through scanning by the main process of the Electron application; based on the configuration file, determining the target component to be loaded through the main process of the Electron application; storing the relevant code and configuration files of the target component through the main process of the Electron application.

[0029] The main process of the Electron application searches for existing components of the Electron application by scanning the resource file paths in the resource directory. After finding the components, it reads the relevant code and configuration files of the components. The relevant codes include the main process code, preloading code, rendering process code, etc. The configuration files of the components include configuration information that needs to be recognized by the main process of the Electron application, so that the main process of the Electron application can automatically identify the loadable components.

[0030] Optionally, the relevant code and configuration files of a component are packaged into an asar package, and the scanning of the main process of the Electron application to search for the relevant code and configuration files of each component under the resource file path includes: scanning the main process of the Electron application to search for the asar package under the resource file path to find the relevant code and configuration files of the corresponding component.

[0031] The components of the embodiment of the present application are provided in the form of an asar package. The components of the embodiment of the present application can be regarded as an independent Electron application. Since the Electron application can load and read the asar package, the components can be packaged into an asar package. When packaging, the main process code, preload code, rendering process code and configuration file of a component are packaged together into an asar package. Using a package file name other than the Electron application, the code in the asar package can be read and executed in the Electron application.

[0032] There are some things to note when packaging components. First, to reduce the size of the component asar package, you do not need to package the third-party libraries that the component depends on during the development process. You only need to package the component's main process code, preloading code, rendering process code, and configuration files into the asar.

[0033] For binary files, node-addon files can usually be packaged into asar and used directly. Files such as exe and dll can be handled using the following three strategies: 1. Package the binary file into asar and release it to the asar unpacking directory at the same time. The final component package includes a single file and a single folder; 2. Package the binary file into asar, and then copy the binary file to other system locations of the Electron application for calling at runtime. The component package includes a single file; 3. The binary file is not packaged into asar, and the binary file is downloaded from the network to other system locations at runtime. This method is somewhat similar to the second method, but the component package is smaller and needs to be connected to the Internet for normal execution.

[0034] In addition, although the asar package of the component provides a certain source code protection, it is still possible for someone to crack it using an asar unpacking tool. Therefore, when packaging the component, the source code can be further obfuscated and the asar package can be encrypted to increase the difficulty of cracking.

[0035] By packaging component data in this asar package, the release form of the component can be defined as a single asar file, ensuring that the core code of the component is not stolen or tampered with, reducing the size of the component package and facilitating distribution. It also complies with the operating specifications of the Electron application, making it easy to configure environment variables and reducing confusion caused by different system environments.

[0036] In this regard, when scanning, the main process of the Electron application can automatically identify the loadable components by automatically scanning the asar packages under the resource file path, and parse the asar packages to obtain the relevant code and configuration files of the loadable components.

[0037] In addition, in order to prevent disguised components from attacking Electron applications and ensure the security of component calls, the components that need to be loaded can be verified after obtaining the component configuration file.

[0038] The configuration file of the component includes the component name, component ID, and the relative path of the main process entry code of the component. Based on the configuration file, the target component to be loaded is determined through the main process of the Electron application, including: determining whether the target asar package is the asar package of the component by judging whether the configuration file in the target asar package carries the component name; if so, matching the component ID in the configuration file of the target asar package with the preset trusted component ID list; if the match is successful, determining the component corresponding to the target asar package as the target component to be loaded.

[0039] The configuration information of the component is specified in the embodiment of the present application, and needs to be configured in a configuration file such as package.json. The configuration information of the component is, for example: { ..., "componentMeta": { "name": "component name", "description": "Component description", "version": "component version number", "id": "component ID", "main": "relative path of the component main process entry code", "preload": "relative path of component preloading script entry code" }, ... } Among them, componentMeta is the configuration file name of the component, and the relative path of the component preloading script entry code will be described in the following embodiment.

[0040] As described above, the Electron application can load and read asar packages. In this embodiment, after the main process of the Electron application obtains an asar package, it needs to parse the asar package to obtain the corresponding configuration file, and then determine whether the asar package is the asar package of the component by whether the component name is recorded in the configuration file. If so, it is necessary to verify the component ID in the configuration file corresponding to the asar package, and it can be matched with the pre-set trusted component ID list during verification. If the match is successful, it means that the component of the asar package is a trusted component ID; if it does not match, it means that the component of the asar package may be a disguised component, and the main process of the Electron application will not load the asar package.

[0041] For a trusted component ID, the main process code entry path of the component in the configuration file is parsed and stored in the memory together with the component configuration file.

[0042] Only components with trusted component IDs can be loaded by the application. In the embodiment of the present application, the component ID needs to be kept confidential, and other verification methods can be added if necessary. The main process of the Electron application can set the trusted component ID list by calling the setTrustIds(ids) method. The above-mentioned method of loading components has the advantage of high security. Only components with trusted IDs will be loaded and executed, ensuring the security of the application.

[0043] Regarding the component development specifications, if there are multiple components in a project, multiple components may use the same Application Programming Interface (API) name, or listen to the same InterProcess Communication (IPC) channel. To avoid the above problems, attention should be paid to the namespace issue when developing components, and use API names and IPC channels that are different from other components.

[0044] After the component development is completed, interface definitions or development documents in the Typescript programming language can be provided so that developers can easily access the component.

[0045] Step 14, obtain the exported method object corresponding to the main process of each component.

[0046] After loading into the corresponding component through step 12, further obtain the method object under the component from the loaded component. Specifically, the method of obtaining the method object corresponding to the main process of each component includes: based on the relative path of the main process entry code of the component in the configuration file, executing the main process entry code of the target component through the main process of the Electron application to export the method object corresponding to the target component through the main process of the target component.

[0047] The main process of the Electron application executes the main process entry code of the component according to the relative path of the main process entry code of the component, so that the main process of the component can export the method object of the corresponding component and provide it to the main process of the Electron application.

[0048] Step 16: mount the method object to a preset object of the Electron application for calling by the Electron application.

[0049] After the method object of the corresponding component is obtained through step 14, it is further mounted on the object of the Electron application, that is, stored in the Electron application, so that the main process of the Electron application can call the method object of the mounted component from the object.

[0050] Optionally, mounting the method object on the preset object of the Electron application includes: using the component name of the target component as the key and the method object exported by the main process of the target component as the value, and mounting the method object exported by the main process of the target component on the preset object of the Electron application through the main process of the Electron application.

[0051] The main process of the Electron application can store the method objects exported by the main process of the component in the form of a key-value pair with the component name as the key and the component method object as the value. The object that stores the component key-value pair is a non-exposed object, and the method objects of different components can be implemented by defining a variable. Different keys represent different components, different values ​​represent different method objects, and the same key can correspond to multiple different values. Therefore, through different key-value pairs, the method objects of multiple components that need to be loaded can be mounted on the object of the Electron application for the Electron application to call.

[0052] In response to different user needs, Electron applications can select the required components from the various components that are called and mounted to achieve customized products with different components.

[0053] The mounted components are existing components in the resource directory of the Electron application. Therefore, the decoupling, combination and free customization of component functions can be achieved without changing too much code, which improves the reusability of components, reduces the coupling between Electron applications and components, and improves the efficiency of component application.

[0054] In order to improve the security of component calls in the rendering process of the Electron application, in one embodiment, the method also includes: when the Electron application starts a new window, loading the preload script of each component; in the rendering process, calling based on the loaded preload script of each component.

[0055] Specifically, when the Electron application starts a new window, loading the preloading script of each component includes: introducing code for loading the preloading script of the component into the preloading script code of the Electron application; when the Electron application starts a new window, based on the code for loading the preloading script of the component, triggering the preloading script of the Electron application to load the preloading script of each component.

[0056] In this embodiment, the code of the preload script for loading components can be introduced at the beginning of the preload script code of the Electron application. By modifying the preload script code, it can be realized that after the Electron application starts a new window in response to the user input of the desktop client, the preload script of the Electron application first obtains the list of loaded / mounted components through the main process of the Electron application based on the introduced code, and then loads and executes the preload script corresponding to each component in the list. The preload script carries the path of the method object that can be called by the rendering process. The method object under this path can be exposed to the API of the rendering process for the rendering process to call.

[0057] The calling in the rendering process based on the preloaded scripts of each loaded component includes: in the rendering process, calling the method object carried in the preloaded scripts of each loaded component through the rendering process of the Electron application.

[0058] In the embodiment of the present application, the rendering process of the Electron application can only call the component interface through the API exposed by the preload script of the component to call the function of the corresponding method object of the component, that is, only the component method loaded in the preload script of the component can be called in the rendering process. The preload script environment of the component and the page environment of the rendering process are isolated contexts, which means that it is safer to call external capabilities only in the preload script of the component, avoiding the problem that the rendering process directly calls the method object of the component, which may affect the global variables of the rendering process.

[0059] Combine the following Figure 2 The functions of the main process and preloaded script involved in the component application method based on the Electron application in an embodiment of the present application are described.

[0060] The main process of an Electron app 1000 provides the following functionality: Set the trusted component ID list via setTrustIds(ids) (101); Automatically scan and load components in the resource directory specified by the Electron application through loadComponents(resourcePath) (102); Get the loaded component information, i.e. the relevant code and configuration file, through listComponents() (103); Use hasComponent(name) to determine whether the specified component has been loaded: (104); Get the method object exported by the main process of the loaded specified component through getComponentExport(name) (105).

[0061] The preload script 1400 of the Electron application 1000 provides the following functionality: Automatically load and execute the component's preload script through initialization without exporting (108); Get the loaded component information through listComponents(). The method object of the preload script of the loaded component in the rendering process is mounted under the path of window.componentInterface.listComponents() (106); Through hasComponent(name), it is determined whether the specified component has been loaded (107).

[0062] The embodiment of the present application implements the function of calling the capabilities of a third-party component by respectively corresponding the main process and preloading script of the introduced component in the main process and preloading script of the Electron application.

[0063] The main process 1200, preload script 1400 and rendering process 1600 of the Electron application 1000 interact with the main processes and preload scripts of different components 3000 as shown in FIG. Figure 3 As shown, Figure 3 It is a schematic diagram of the application architecture of the Electron application and corresponding components of an embodiment of the present application.

[0064] For example, component A, component B, and component C in component 3000 are components in the resource directory of the Electron application. The main process 1200 of the Electron application 1000 can load component A, component B, and component C, obtain the methods exported by the main process of each component, and then store the component A method object, component B method object, and component C method object in the Electron application 1000. The main process of the Electron application 1000 calls the component and can call the method object of any component from the stored component A method object, component B method object, and component C method object.

[0065] The preload script 1400 of the Electron application 1000 can load the preload scripts of each component when the Electron application starts a new window, thereby providing the rendering process 1600 with the interface exposed by the preload script of component A, the interface exposed by the preload script of component B, and the interface exposed by the preload script of component C. The rendering process of the Electron application 1000 calls the component and can call the method object of any component through the interface exposed by the preload script of each component.

[0066] Figure 4 is a schematic diagram of the overall process of the component application method based on the Electron application program of the embodiment of the present application, such as Figure 4 As shown, it mainly includes the main process part and the rendering process part. The main process part involves calling the method object of the component, and the rendering process part involves calling the method object of the preload script of the component, which specifically includes the following steps: Step 1: Import the main process script of the loading component at the beginning of the main process code of the Electron application; Step 2: Call the setTrustIds(ids) method to set the trusted component ID list; Step 3: Call loadComponents(resourcePath) to automatically load components; Step 3.1: Scan the resource file path to find the asar package file, and jump to step 4 if it cannot be found; Step 3.2: After finding the asar file, read the configuration file package.json in the asar file; Step 3.3: Parse the configuration file package.json to determine whether the configuration file contains a componentMeta object; Step 3.4: If there is no componentMeta object, jump to step 3.1 to find the next asar file; Step 3.5: If there is a componentMeta object, check whether the component ID, that is, componentMeta.id, is a trusted component ID; Step 3.6: If componentMeta.id is empty or not in the preset trusted component ID list, jump to step 3.1 to find the next asar file; Step 3.7: If it is a trusted component ID, parse the main process code entry path and preload code entry path of the component and store them in memory together with the component information of componentMeta; Step 4: Execute the main process entry code of each component one by one, and mount the method object exported by the main process of the component to the object of the Electron application with the component name as the key; Step 5: Execute other main process logic; Step 6: When launching a new window, the Electron application sets a preload script. The preload script code must begin with the preload script for the loading component. Step 7: The preload script of the Electron application obtains the list of loaded component information from the main process; Step 8: Load and execute the preload scripts corresponding to each component one by one; Step 9: In the rendering process code, call each component preload script to expose the API to the rendering process, thereby realizing the calling of the component's internal capabilities.

[0067] The main process of the embodiment of the present application provides the ability to automatically detect the loading component and the main process export method of the mounting component, and the rendering process provides the ability to dynamically load the component preloading entry file in the preloading script.

[0068] In an embodiment of the present application, by loading each component in the resource directory of the Electron application, obtaining the method object exported by the main process of each component, and mounting the method object on the preset object of the Electron application for calling by the Electron application, the existing components in the resource directory of the Electron application can be utilized to achieve decoupling and combination of component functions without changing too much code, thereby meeting the needs of different users to achieve free customized product development, improving the reusability of components, reducing the coupling between the Electron application and the components, and improving the efficiency of component application.

[0069] Alternatively, if Figure 5 As shown, an embodiment of the present application also provides a component application device 2000 based on an Electron application, including a processor 2400 and a memory 2200, wherein the memory 2200 stores programs or instructions that can be run on the processor 2400, and when the program or instructions are executed by the processor 2400, the various steps of the above-mentioned component application method embodiment based on the Electron application are implemented, and the same technical effect can be achieved. To avoid repetition, they are not described here.

[0070] The embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by the processor, each process of any of the above-mentioned component application method embodiments based on the Electron application is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. Among them, the readable storage medium includes a computer-readable storage medium, such as a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0071] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program. The computer program is operable to enable a computer to implement each process of any one of the above-mentioned component application method embodiments based on an Electron application when executed, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0072] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0073] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0074] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A component application method based on Electron application, characterized in that: include: Load the components in the resource directory of the Electron application; Get the exported method object corresponding to the main process of each component; The method object is mounted on a preset object of the Electron application so as to be called by the Electron application.

2. The method according to claim 1, characterized in that The components in the resource directory of the Electron application are loaded, including: Introducing code for loading a main process script of a component into the main process code of the Electron application; Based on the code of the main process script for loading components, trigger the main process of the Electron application to scan the corresponding resource file path in the resource directory; By scanning the main process of the Electron application, each component under the resource file path is loaded.

3. The method according to claim 2, characterized in that The scanning of the main process of the Electron application to load the components under the resource file path includes: By scanning the main process of the Electron application, searching for relevant codes and configuration files of each component under the resource file path; Based on the configuration file, determine the target component to be loaded through the main process of the Electron application; The relevant codes and configuration files of the target component are stored through the main process of the Electron application.

4. The method according to claim 3, characterized in that The relevant code and configuration files of a component are packaged into an asar package. The scanning of the main process of the Electron application program to search for the relevant code and configuration files of each component under the resource file path includes: By scanning the main process of the Electron application, the asar package under the resource file path is searched to find the relevant code and configuration file of the corresponding component.

5. The method according to claim 4, characterized in that The component configuration file includes the component name, component ID, and the relative path of the component's main process entry code. Determining the target component to be loaded through the main process of the Electron application based on the configuration file includes: By judging whether the configuration file in the target asar package carries the component name, determining whether the target asar package is an asar package of the component; If yes, match the component ID in the configuration file of the target asar package with the preset trusted component ID list; If the match is successful, the component corresponding to the target asar package is determined as the target component to be loaded.

6. The method according to claim 5, characterized in that The method object corresponding to the main process of each component is obtained, including: Based on the relative path of the main process entry code of the component in the configuration file, the main process entry code of the target component is executed through the main process of the Electron application to export the method object corresponding to the target component through the main process of the target component.

7. The method according to claim 5, characterized in that The method object is mounted on a preset object of the Electron application, comprising: Using the component name of the target component as the key and the method object exported by the main process of the target component as the value, the method object exported by the main process of the Electron application is mounted on the preset object of the Electron application through the main process of the Electron application.

8. The method according to any one of claims 1 to 7, characterized in that Also includes: When the Electron application starts a new window, load the preload scripts of each component; In the rendering process, it is called based on the preload scripts of each component loaded.

9. The method according to claim 8, characterized in that When the Electron application starts a new window, the preload scripts of each component are loaded, including: Introducing the code of the preload script for loading the component into the preload script code of the Electron application; When the Electron application starts a new window, based on the code for loading the preload script of the component, the preload script of the Electron application is triggered to load the preload script of each component.

10. The method according to claim 8, characterized in that In the rendering process, the preload scripts of the loaded components are called, including: In the rendering process, the method object carried in the preload script of each loaded component is called by the rendering process of the Electron application.

Citation Information

Patent Citations

  • Plug-in application method and device of Enctron application program and storage medium

    CN112379943A

  • Plug-in compiling and calling method and device, equipment and storage medium

    CN114942796A

  • File running method and device

    CN117519813A

  • Application program starting method and device, computer equipment and storage medium

    CN118012518A