CN112667246B - Application function expansion method and device and electronic equipment - Google Patents

Application function expansion method and device and electronic equipment Download PDF

Info

Publication number
CN112667246B
CN112667246B CN202110021572.8A CN202110021572A CN112667246B CN 112667246 B CN112667246 B CN 112667246B CN 202110021572 A CN202110021572 A CN 202110021572A CN 112667246 B CN112667246 B CN 112667246B
Authority
CN
China
Prior art keywords
plug
file
function
application
access path
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110021572.8A
Other languages
Chinese (zh)
Other versions
CN112667246A (en
Inventor
雷其榕
卢道和
林挺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202110021572.8A priority Critical patent/CN112667246B/en
Publication of CN112667246A publication Critical patent/CN112667246A/en
Application granted granted Critical
Publication of CN112667246B publication Critical patent/CN112667246B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention discloses a method and a device for expanding an application function and electronic equipment, wherein the method for expanding the application function comprises the following steps: binding a first hook function in a source code file of a first application with at least one corresponding plug-in; running the at least one plug-in bound to the first hook function under the condition that the first hook function is triggered when source codes in the source code file are executed; wherein the at least one plug-in is configured to extend a first function in the first application.

Description

Application function expansion method and device and electronic equipment
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for extending an application function, and an electronic device.
Background
With the development of computer technology, more and more technologies are applied in the financial field, and the traditional financial industry is gradually changed to the financial technology (Fintech), however, the financial technology also has higher requirements on the technology due to the requirements of safety and real-time performance of the financial industry. In the scenario of expanding web application functions of financial science and technology, the workload of modifying source code files is large, the coupling degree of source codes is high, the development cost is high, and the flexibility is poor.
Disclosure of Invention
In view of this, the embodiment of the invention is expected to provide a method, a device and an electronic device for expanding application functions, so as to solve the technical problems of higher development cost and poorer flexibility of expanding web application functions in the related technology.
In order to achieve the above purpose, the technical scheme of the invention is realized as follows:
the embodiment of the invention provides a method for expanding application functions, which comprises the following steps:
binding a first hook function in a source code file of a first application with at least one corresponding plug-in;
running the at least one plug-in bound to the first hook function under the condition that the first hook function is triggered when source codes in the source code file are executed; wherein,
the at least one plug-in is configured to extend a first function in the first application.
In the above solution, the binding the first hook function in the source code file of the first application with the corresponding at least one plug-in includes:
writing at least one function corresponding to the at least one plug-in into a monitoring function corresponding to the first hook function by calling a set binding function; the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
In the above solution, the running the at least one plug-in bound to the first hook function under the condition that the first hook function is triggered when the source code in the source code file is executed includes:
triggering the first hook function by calling a set trigger function when executing the source codes in the source code file;
and executing all function functions in the monitoring function written into the corresponding first hook function under the condition that the first hook function is triggered.
In the above scheme, the method further comprises:
initializing each plugin based on configuration files corresponding to all plugins of the first application to obtain plugin entry files corresponding to the first application; wherein,
the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on at least one of a client side and a server side of the first application;
the plug-in entry file is used for describing an access path of at least one of a client entry file and a server entry file included in each plug-in; the access path of the client side entry file is used for acquiring a function in the client side entry file included in the corresponding plug-in; the access path of the server side entry file is used for acquiring the function in the server side entry file included in the corresponding plug-in.
In the above scheme, the method further comprises:
determining at least one function corresponding to each plug-in at least one plug-in based on the plug-in entry file and the identification information of each plug-in at least one plug-in corresponding to the first hook function; wherein the determined at least one function is used for binding with the first hook function.
In the above solution, initializing each plug-in based on the configuration files corresponding to all plug-ins of the first application to obtain a plug-in entry file corresponding to the first application includes:
determining an access path of an entry file of the first plugin based on the configuration file of the first plugin;
determining an access path of an entry file of the second plugin based on the configuration file of the second plugin;
determining a plug-in entry file corresponding to the first application based on the access path of the entry file of the first plug-in and the access path of the entry file of the second plug-in; wherein,
the first plugin characterizes plugins stored under the project catalog of the first application;
a second plug-in characterizes plug-ins of the first application downloaded through a package manager tool;
The portal file includes at least one of a client portal file and a server portal file.
In the above scheme, the access path of the entry file of the first plug-in or the second plug-in is determined by the following method:
splicing the first access path, the second access path and the file name of the inlet file to obtain the access path of the inlet file; wherein,
the first access path characterizes an access path of a plug-in with respect to a root directory of the first application;
the second access path characterizes an access path of the plug-in.
The embodiment of the invention also provides a device for expanding the application function, which comprises:
the binding unit is used for binding the first hook function in the source code file of the first application with at least one corresponding plug-in;
the execution unit is used for running the at least one plug-in bound with the first hook function under the condition that the first hook function is triggered when the source codes in the source code file are executed; wherein,
the at least one plug-in is configured to extend a first function in the first application.
The embodiment of the invention also provides electronic equipment, which comprises: a processor and a memory for storing a computer program capable of running on the processor,
Wherein the processor is configured to execute the steps of any one of the methods for applying the function extension described above when running the computer program.
The embodiment of the invention also provides a storage medium, on which a computer program is stored, which when being executed by a processor, implements the steps of any of the above methods of applying function extensions.
According to the embodiment of the invention, a first hook function in a source code file of a first application is bound with at least one corresponding plugin; running the at least one plug-in bound to the first hook function under the condition that the first hook function is triggered when source codes in the source code file are executed; wherein the at least one plug-in is configured to extend a first function in the first application. According to the scheme, the function expansion is realized by running the plug-in unit bound with the first hook function, so that a developer can independently develop the expansion function, the coupling degree between the main program and the expansion program is reduced, and the flexibility of the function expansion is improved; the developer does not need to modify the source code file in a large amount, so that the development cost can be reduced; by binding the first hook function in the source code file with at least one plug-in, a developer can integrate the extended function into the first application according to actual requirements.
Drawings
Fig. 1 is a schematic implementation flow chart of a method for extending an application function according to an embodiment of the present invention;
FIG. 2 is a schematic flow chart of a method for implementing function extension according to another embodiment of the present invention;
fig. 3 is a schematic structural diagram of an apparatus for application function extension according to an embodiment of the present invention;
fig. 4 is a schematic diagram of a hardware composition structure of an electronic device according to an embodiment of the present invention.
Detailed Description
Web applications are typically developed in the related art in two ways:
front-to-back end separation mode: the front end and the rear end are mutually independent; the front end is responsible for rendering a User Interface (UI) of the web application and loading the data provided by the back end into the UI.
Front-back end non-split mode: the backend controls rendering or redirection of the UI of the front-end, display effects, etc.
When a developer modifies a source code file based on the mode to expand the functions of the web application, a large amount of source codes in the source code file are required to be modified, the development cost is high due to the large workload of modifying the source codes, and the flexibility is poor due to the fact that the coupling degree between a main program and an expansion program is high, and independent development cannot be conducted on the expansion functions.
In order to solve the above technical document, an embodiment of the present invention provides a method for extending an application function, including: binding a first hook function in a source code file of a first application with at least one corresponding plug-in; running the at least one plug-in bound to the first hook function under the condition that the first hook function is triggered when source codes in the source code file are executed; wherein the at least one plug-in is configured to extend a first function in the first application. According to the scheme, the function expansion is realized by running the plug-in unit bound with the first hook function, so that a developer can independently develop the expansion function, the coupling degree between the main program and the expansion program is reduced, and the flexibility of the function expansion is improved; the developer does not need to modify the source code file in a large amount, so that the development cost can be reduced; by binding the first hook function in the source code file with at least one plug-in, a developer can integrate the extended function into the first application according to actual requirements.
The technical scheme of the invention is further elaborated below by referring to the drawings in the specification and the specific embodiments.
Fig. 1 shows a schematic implementation flow diagram of a method for applying function extension according to an embodiment of the present invention. In the embodiment of the invention, an execution main body of the method for expanding the application function is electronic equipment, and the electronic equipment comprises a terminal and a server; the terminal comprises a mobile phone, a tablet personal computer, a desktop computer and the like.
Referring to fig. 1, the method for extending an application function provided by the embodiment of the present invention includes:
s101: binding a first hook function in a source code file of a first application with at least one corresponding plug-in; wherein the at least one plug-in is for adding a first function in the first application.
The method comprises the steps that the electronic equipment obtains all plug-ins of a first application, and at least one first hook function included in a source code file of the first application is determined; determining at least one plugin corresponding to each first hook function based on the obtained identification information of the hook function contained in the plugin and the determined identification information of each first hook function; binding each first hook function with a corresponding at least one plug-in. Wherein,
because the plug-in developed by the developer can be a built-in plug-in of the first application and can be issued to the package management tool (NPM, node Package Manager), the built-in plug-in is stored under the project catalog of the first application; the plug-in released to the NPM is downloaded to the local through the NPM under the condition that the electronic equipment starts the first application, and is stored in a file directory of the NPM; therefore, the electronic device acquires the first plugin from the project catalog of the first application, and acquires the second plugin from the file catalog of the NPM, so that all plugins of the first application are obtained. In practical applications, the file directory of the NPM may be node_modules. The plug-in is used to extend new first functions of the first application.
The first hook function generally refers to any hook function set by a developer in a source code file of a first application. The number of first hook functions is at least one. Each first hook function is used for providing an expansion point, so that a developer writes source codes for the corresponding expansion point, and therefore functions are expanded for the expansion point. The extension point characterizes the access point into which the plug-in is introduced.
In a practical application, the first application is a web application. The developer can set a corresponding first hook function for each source code module in the source code file of the first application, so that the developer can expand the functions of the source code modules based on setting the corresponding first hook function for each source code module.
The first hook function includes identification information, a type, and a listening function. The type characterization corresponds to the first hook function allowing binding once or running binding at least twice; the snoop function is used for writing a function in the plugin bound with the corresponding first hook function. In practical application, when the type of the first hook function is single, the first hook function is characterized in that the first hook function is allowed to be bound once, and the number of plug-ins corresponding to the first hook function is one; when the type of the first hook function is "multi", the first hook function is characterized in that the first hook function is allowed to be bound at least twice, and the number of plugins corresponding to the first hook function is at least two.
For example, a developer may set a corresponding first hook function for a source code module for implementing a "navigation menu" in a source code file of the first application, where the identification information of the hook function may be sub-nav.
It should be noted that the plug-in characterizes a relatively independent functional module, which may be integrated into the source code file of the first application.
In practical applications, the plug-in includes a configuration file and at least one entry file. The configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on at least one of a client side and a server side of the first application; the portal file may be a server portal file or a client portal file.
In practical applications, the configuration file may be index. Js; when the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on the client of the first application, the plug-in comprises a client entry file; when the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on the service end of the first application, the plug-in comprises a service end entry file; when the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on the client side and the server side of the first application, the plug-in comprises a client side entry file and a server side entry file.
In practical applications, the index. Js includes a first field and a second field, where the first field may be "client" and the second field may be "server". The first field characterizes whether the corresponding plug-in is used for performing function expansion on the client of the first application; the second field characterizes whether the corresponding plug-in is used for performing function expansion on the server side of the first application. When a first field client in index. Js is "true", the plugin includes client entry file client; when a second field server in index. Js is true, the plug-in comprises a server side entry file server. Js; when the first field client and the second field server in the index. Js are both "true", the client. Js and the server. Js are included in the plugin.
It should be noted that, the server side entry file and the client side entry file both include the corresponding function and the identification information of the hook function to be bound. The hook function to be bound is a hook function set in the source code file of the first application.
In some embodiments, the binding the first hook function in the source code file of the first application with the corresponding at least one plug-in includes:
writing at least one function corresponding to the at least one plug-in into a monitoring function corresponding to the first hook function by calling a set binding function; the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
Under the condition that the plugins corresponding to the first hook functions are determined, the electronic equipment calls the set binding function, writes the function in the plugin corresponding to the first hook function into the monitoring function in the first hook function, and binds the identification information of the first hook function and the function in the corresponding plugin, namely binds the first hook function and the corresponding plugin. The monitoring function in the first hook function is used for monitoring whether the corresponding first hook function is triggered or not, and executing all function functions in the monitoring function when the corresponding first hook function is triggered.
In practical applications, the binding function set may be a bind ('hook-name', function); 'hook-name' characterizes the identification information of the first hook function; the function characterizes the function in the plug-in.
In the scheme, the function in the plug-in corresponding to the first hook function is written into the monitoring function of the first hook function, so that the hook function in the source code file of the first application is bound with the corresponding plug-in. Monitoring whether the corresponding first hook function is triggered or not through the monitoring function in the first hook function, and executing all function functions in the monitoring function when the corresponding first hook function is triggered, so that the function functions in the plug-in are rapidly integrated to the first application, and the function expansion of the first application is realized, and the function expansion efficiency can be improved.
S102: running the at least one plug-in bound to the first hook function under the condition that the first hook function is triggered when source codes in the source code file are executed; wherein the at least one plug-in is configured to extend a first function in the first application.
The electronic device triggers the first hook function in the process of executing the source codes in the source code file of the first application, and runs at least one plug-in bound with the first hook function under the condition of triggering the first hook function, so that the function in the at least one plug-in bound with the first hook function is executed to expand the first function of the first application. It should be noted that, a first function may be extended in the first application by one plug-in that is bound to the first hook function, or a first function may be extended in the first application by at least two plug-ins that are bound to the first hook function.
In practical application, when the electronic device completes the execution of the source code module of the navigation menu, the corresponding first hook function is triggered and at least one plug-in unit bound with the first hook function is operated under the condition that the first hook function is arranged at the corresponding position of the source code module of the source code file of the first application for realizing the navigation menu. For example, when the plug-in bound to the first hook function is used to add a "document" option to the "navigation menu", the electronic device displays the "navigation menu" including the "document" option, with the function in the plug-in being executed.
In some embodiments, the running the at least one plug-in bound to the first hook function in a case that the first hook function is triggered when the source code in the source code file is executed includes:
triggering the first hook function by calling a set trigger function when executing the source codes in the source code file;
and executing all function functions in the monitoring function written into the corresponding first hook function under the condition that the first hook function is triggered.
Here, the electronic device triggers the first hook function by calling a set trigger function in the process of executing the source code in the source code file of the first application; the monitoring function in the first hook function monitors that the corresponding first hook function is triggered, and executes all function functions in the monitoring function written in the corresponding first hook function.
In practical applications, the set trigger function may be emittor ('hook-name').
In the scheme provided by the embodiment, a first hook function in a source code file of a first application is bound with at least one corresponding plug-in; and under the condition that the first hook function is triggered when the source code in the source code file is executed, running at least one plug-in bound with the first hook function, so as to expand the first function of the first application. According to the scheme, the function expansion is realized by running the plug-in unit bound with the first hook function, so that a developer can independently develop the expansion function, the coupling degree between the main program and the expansion program is reduced, and the flexibility of the function expansion is improved; the developer does not need to modify the source code file in a large amount, so that the development cost can be reduced; by binding the first hook function in the source code file with at least one plug-in, a developer can integrate the extended function into the first application according to actual requirements.
In some embodiments, the first application includes a plugin management file, where an identifier of the plugin management file may be plugin.js; the plug-in management file comprises a set binding function and a set triggering function; the plug-in management file is used for initializing the plug-in of the first application and calling a set binding function and a set triggering function by the electronic equipment. The set binding function is used for binding the first hook function and the corresponding plug-in; the set trigger function is used for triggering the first hook function.
Referring to fig. 2, fig. 2 is a schematic flow chart illustrating an implementation of a method for extending an application function according to another embodiment of the present invention. The embodiment corresponding to fig. 2 differs from the embodiment corresponding to fig. 1 in that the plug-in of the first application is initialized before binding the first hook function in the source code file of the first application with the corresponding at least one plug-in.
As shown in fig. 2, the method for applying the function extension includes:
s201: initializing each plugin based on configuration files corresponding to all plugins of a first application to obtain plugin entry files corresponding to the first application; wherein,
the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on at least one of a client side and a server side of the first application;
The plug-in entry file is used for describing an access path of at least one of a client entry file and a server entry file included in each plug-in; the access path of the client side entry file is used for acquiring a function in the client side entry file included in the corresponding plug-in; the access path of the server side entry file is used for acquiring the function in the server side entry file included in the corresponding plug-in.
In practical application, under the condition that the electronic equipment acquires all plugins of the first application, acquiring a configuration file contained in each plugin of the first application; and initializing each plug-in based on configuration files corresponding to all plug-ins of the first application by running plug-in management files plug in. Js to obtain plug-in entry files corresponding to the first application. Wherein,
the plug-ins of the first application include at least one of a first plug-in and a second plug-in;
when the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on the client of the first application, the corresponding plug-in comprises a client entry file, and the plug-in entry file comprises an access path of the client entry file of the corresponding plug-in;
when the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on the service end of the first application, the corresponding plug-in comprises a service end entry file, and the plug-in entry file comprises an access path of the service end entry file of the corresponding plug-in;
When the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on the client side and the server side of the first application, the corresponding plug-in comprises a client side entry file and a server side entry file, and the plug-in entry file comprises an access path of the client side entry file and an access path of the server side entry file of the corresponding plug-in.
It should be noted that, the plug-in entry file corresponding to the first application includes access paths of the entry files of all plug-ins of the first application. The portal file includes at least one of a client portal file and a server portal file. The identification information of the plug-in the plug-in entry file has a corresponding relationship with the access path of the corresponding entry file.
In some embodiments, in order to avoid that the first application cannot load a part of the extended functions developed by the developer, the success rate of adding the extended functions in the first application is improved; initializing each plug-in based on configuration files corresponding to all plug-ins of the first application to obtain a plug-in entry file corresponding to the first application, wherein the configuration files comprise:
determining an access path of an entry file of the first plugin based on the configuration file of the first plugin;
Determining an access path of an entry file of the second plugin based on the configuration file of the second plugin;
determining a plug-in entry file corresponding to the first application based on the access path of the entry file of the first plug-in and the access path of the entry file of the second plug-in; wherein,
the first plugin characterizes plugins stored under the project catalog of the first application;
a second plug-in characterizes plug-ins of the first application downloaded through a package manager tool;
the portal file includes at least one of a client portal file and a server portal file.
The electronic equipment traverses a project catalog of the first application to obtain a first plug-in stored under the project catalog of the first application; under the condition that the first plugin of the first application is obtained, the electronic equipment determines an entry file contained in the first plugin based on the configuration file of the first plugin, and determines an access path of the entry file of the first plugin based on a storage path of the first plugin and the name of the entry file.
The electronic equipment traverses a file directory of the package management tool to obtain all second plug-ins of the first application stored under the file directory of the package management tool; under the condition that the second plugin of the first application is obtained, the electronic equipment determines an entry file contained in the second plugin based on the configuration file of the second plugin, and determines an access path of the entry file of the second plugin based on a storage path of the second plugin and the name of the entry file.
And under the condition that the access paths of all the first plugins and the access paths of all the second plugins are determined, merging the access paths of the inlet files of the first plugins and the access paths of the inlet files of the second plugins to obtain plugin inlet files corresponding to the first application.
It should be noted that, in the case where the first plugin of the first application does not exist, the plugin entry file corresponding to the first application only includes the access path of the entry file of the second plugin. And under the condition that the second plugin of the first application does not exist, the plugin inlet file corresponding to the first application only comprises the access path of the inlet file of the first plugin.
In some embodiments, to more accurately determine the access path of the portal file to increase the probability of obtaining a function in the portal file included in the plug-in, the access path of the portal file of the first plug-in or the second plug-in is determined by:
splicing the first access path, the second access path and the file name of the inlet file to obtain the access path of the inlet file; wherein,
the first access path characterizes the access path of the corresponding plug-in relative to the root directory of the first application;
And the second access path characterizes the access path of the corresponding plug-in.
Illustratively, the access path of the first plug-in of the first application is as follows:
exts/apidesign-plugin-import-postman/client.js;
exts/apidesign-plugin-import-postman/server.js。
wherein "exts" characterizes an access path of the first plug-in relative to a root directory of the first application; "apersign-plug in-import-postman" characterizes the name of the first plugin, which includes the client portal file and the server portal file; "client. Js" characterizes the name of the client portal file included in the first plugin; "server. Js" characterizes the name of the server portal file included in the first plug-in.
Illustratively, the access path of the second plug-in of the first application is as follows:
node-modules/apidesign-plugin-import-har/server.js。
wherein "node-modules" characterizes the access path of the second plug-in with respect to the root directory of the first application; "apigenin-plug in-import-har" characterizes the name of the second plug-in, which includes the server portal file, excluding the client portal file; "server. Js" characterizes the name of the server portal file included in the second plugin.
S202: determining at least one function corresponding to each plug-in at least one plug-in based on the plug-in entry file and the identification information of each plug-in at least one plug-in corresponding to the first hook function; wherein the determined at least one function is used for binding with the first hook function.
The electronic device obtains an access path of the entry file corresponding to the identification information of each plug-in from the determined plug-in entry file based on the identification information of each plug-in the at least one plug-in corresponding to the first hook function, and obtains the access path of the entry file corresponding to each plug-in. And accessing the entry files contained in the corresponding plugins based on the access paths of the acquired entry files under the condition that the access paths of the entry files corresponding to the plugins are acquired, and acquiring the corresponding function functions from the accessed entry files, so that at least one function corresponding to each plugin is acquired. Wherein the function corresponding to the plug-in comprises at least one of a first function and a second function; the first function represents a function in a client inlet file included in the corresponding plug-in; the second function represents the function in the server side entry file included in the corresponding plug-in.
In practical application, when the access path of the entry file corresponding to the identification information of the plugin includes the access path of the client entry file, the electronic device accesses the client entry file in the corresponding plugin based on the access path of the client entry file, and reads the first function from the accessed client entry file to obtain the first function corresponding to the corresponding plugin.
When the access path of the entry file corresponding to the identification information of the plugin comprises the access path of the server entry file, the electronic equipment accesses the server entry file in the corresponding plugin based on the access path of the server entry file, and reads the second function from the accessed server entry file to obtain the second function corresponding to the corresponding plugin.
When an access path of an entry file corresponding to the identification information of the plugin comprises an access path of a client entry file and an access path of a server entry file, the electronic equipment accesses the client entry file in the corresponding plugin based on the access path of the client entry file, and reads a first function from the accessed client entry file; and accessing the service side entry file in the corresponding plugin based on the access path of the service side entry file, and reading the second function from the accessed service side entry file to obtain the first function and the second function corresponding to the corresponding plugin.
S203: writing at least one function corresponding to the at least one plug-in into a monitoring function corresponding to the first hook function by calling a set binding function; the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
Under the condition that the function corresponding to each plug-in corresponding to the first hook function is determined, the electronic equipment writes the function corresponding to each plug-in corresponding to the first hook function into the monitoring function corresponding to the corresponding first hook function by calling the set binding function in the plug-in management file plug in.
S204: and when executing the source codes in the source code file, triggering the first hook function by calling a set triggering function.
When the electronic equipment executes the source code in the source code file of the first application, the first hook function is triggered by calling a set trigger function in the plug-in management file plug in. Js.
S205: and executing all function functions in the monitoring function written into the corresponding first hook function under the condition that the first hook function is triggered.
Here, the listening function in the first hooking function listens that the corresponding first hooking function is triggered, and the electronic device executes all the function functions in the listening function written in the corresponding first hooking function.
It should be noted that, in the embodiment of the present invention, the electronic device determines, based on the source code file of the first application and all the plugins of the first application, a front-end static resource file of the first application; and performing static analysis according to the dependency relationship among all front-end static resource files of the first application through a front-end resource loading/packaging tool to obtain a static analysis result, generating corresponding static resources according to a specified rule by the front-end static resource files of the first application based on the static analysis result, and loading the generated static resources to obtain a front-end page.
Wherein,
the front-end resource loading/packaging tool may be Webpack, rollup, parcel or SystemJS.
The front-end static resource file comprises js source code file, css style file, picture, font file and the like.
The implementation process of generating the corresponding static resource according to the specified rule through Webpack is as follows:
traversing application entry file application. Js of the first application by using a weback tool, recursively analyzing the referenced front-end static resource file of the first application, and performing corresponding processing according to the file type of the front-end static resource file. Wherein,
the file type of the front-end static resource file is identified by the file suffix name. For example, when the suffix of the front-end static resource file is "js" or "jsx", the corresponding front-end static resource file is represented as a JavaScript script file; when the suffix name of the front-end static resource file is "png", "gif", "jpg" or "jpeg", the corresponding front-end static resource file is characterized as a picture file. When the suffix name of the front-end static resource file is "sass", "scss" or "css", the corresponding front-end static resource file is characterized as a style file; when the suffix name of the front-end static resource file is "woff", "woff2", "eot", "ttf" or "svg", the corresponding front-end static resource file is characterized as a font file.
When the front-end static resource file is a picture, determining whether to use base64 embedded according to the file size by utilizing weback; wherein when the file size is less than 50kb, the picture path is replaced by base 64.
When the front-end static resource file is a style file, the corresponding grammar translation and merging compressed files are used, and the file name is added with a hash to replace a reference path.
When the static resource file at the front end is a JS file, the corresponding grammar is utilized to translate, merge and compress the file and the file name is utilized to add a hash to replace a reference path. Wherein the front-end static resource file, either through the request, the sense, or the dynamic import, eventually forms an independent file, without being consolidated.
When the front-end static resource file is a font file, adding a hash to the file name of the font file by utilizing webapck, and replacing a path.
It should be noted that, the static resource after weback packaging ultimately generates a file under a directory, for example, a dist file. The style file after application of the portal file application.
It should be noted that, the server side of the first application is a nodebjs application, and the first application is introduced and executed by a requiring method when started.
The request is a method built in the NodeJS, and a module (related file) is introduced into the NodeJS application by using the request, so that module management is realized.
In a practical application, when the plug-in of the first application is published to npm, the electronic device adds the corresponding plug-in to the item of the first application through the command provided by npm when the first application is started, so as to initialize the corresponding plug-in.
In the scheme provided by the embodiment, based on configuration files corresponding to all plugins of the first application, each plugin is initialized to obtain a plugin entry file corresponding to the first application, and access paths of the entry files included in all plugins of the first application can be obtained; determining at least one function corresponding to each plug-in at least one plug-in corresponding to the first hook function based on the plug-in entry file and the identification information of each plug-in at least one plug-in corresponding to the first hook function; writing at least one function corresponding to at least one plug-in into a monitoring function corresponding to a first hook function by calling a set binding function; triggering a first hook function by calling a set trigger function when executing the source codes in the source code file; under the condition of triggering the first hook function, executing all function functions in the monitoring function written in the corresponding first hook function can avoid missing the function functions in the plug-in of the first application, further avoid that all new functions expanded by a developer cannot be added in the first application, and improve the success rate of adding the expanded functions in the first application.
In order to implement the method of the embodiment of the present invention, the embodiment of the present invention further provides an application function expansion device, which is disposed on an electronic device, as shown in fig. 3, where the application function expansion device includes:
a binding unit 31, configured to bind a first hook function in a source code file of a first application with a corresponding at least one plug-in;
an execution unit 32, configured to execute the at least one plug-in bound to the first hook function in a case that the first hook function is triggered when source codes in the source code file are executed; wherein,
the at least one plug-in is configured to extend a first function in the first application.
In some embodiments, the binding unit 31 is for:
writing at least one function corresponding to the at least one plug-in into a monitoring function corresponding to the first hook function by calling a set binding function; the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
In some embodiments, the execution unit 32 is configured to:
triggering the first hook function by calling a set trigger function when executing the source codes in the source code file;
And executing all function functions in the monitoring function written into the corresponding first hook function under the condition that the first hook function is triggered.
In some embodiments, the apparatus for applying a function extension further comprises:
the initialization unit is used for initializing each plug-in based on configuration files corresponding to all plug-ins of the first application to obtain plug-in entry files corresponding to the first application; wherein,
the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on at least one of a client side and a server side of the first application;
the plug-in entry file is used for describing an access path of at least one of a client entry file and a server entry file included in each plug-in; the access path of the client side entry file is used for acquiring a function in the client side entry file included in the corresponding plug-in; the access path of the server side entry file is used for acquiring the function in the server side entry file included in the corresponding plug-in.
In some embodiments, the apparatus for applying a function extension further comprises:
the determining unit is used for determining at least one function corresponding to each plug-in at least one plug-in based on the plug-in entry file and the identification information of each plug-in the at least one plug-in corresponding to the first hook function; wherein the determined at least one function is used for binding with the first hook function.
In some embodiments, the initialization unit is configured to:
determining an access path of an entry file of the first plugin based on the configuration file of the first plugin;
determining an access path of an entry file of the second plugin based on the configuration file of the second plugin;
determining a plug-in entry file corresponding to the first application based on the access path of the entry file of the first plug-in and the access path of the entry file of the second plug-in; wherein,
the first plugin characterizes plugins stored under the project catalog of the first application;
a second plug-in characterizes plug-ins of the first application downloaded through a package manager tool;
the portal file includes at least one of a client portal file and a server portal file.
In some embodiments, the initialization unit determines the access path of the entry file of the first plug-in or the second plug-in by:
splicing the first access path, the second access path and the file name of the inlet file to obtain the access path of the inlet file; wherein,
the first access path characterizes an access path of a plug-in with respect to a root directory of the first application;
the second access path characterizes an access path of the plug-in.
In practical application, each unit included in the device for applying the function extension can be implemented by a processor in the device for applying the function extension. Of course, the processor needs to execute the program stored in the memory to realize the functions of the program modules.
It should be noted that: in the application function expansion device provided in the above embodiment, only the division of each program module is used for illustrating the function expansion of the application, and in practical application, the processing allocation may be completed by different program modules according to needs, that is, the internal structure of the application function expansion device is divided into different program modules, so as to complete all or part of the processing described above. In addition, the device for extending the application function provided in the above embodiment and the method embodiment for extending the application function belong to the same concept, and the specific implementation process is detailed in the method embodiment, which is not repeated here.
Based on the hardware implementation of the program modules, and in order to implement the method of the embodiment of the present invention, the embodiment of the present invention further provides an electronic device. Fig. 4 is a schematic diagram of a hardware composition structure of an electronic device according to an embodiment of the present invention, where, as shown in fig. 4, the electronic device includes:
A communication interface 1 capable of information interaction with other devices such as a server or the like;
and the processor 2 is connected with the communication interface 1 to realize information interaction with other devices and is used for executing the application function expansion method provided by one or more technical schemes when running the computer program. And the computer program is stored on the memory 3.
Of course, in practice, the various components in the electronic device are coupled together by a bus system 4. It will be appreciated that the bus system 4 is used to enable connected communications between these components. The bus system 4 comprises, in addition to a data bus, a power bus, a control bus and a status signal bus. But for clarity of illustration the various buses are labeled as bus system 4 in fig. 4.
The memory 3 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program for operating on an electronic device.
It will be appreciated that the memory 3 may be either volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. Wherein the nonvolatile Memory may be Read Only Memory (ROM), programmable Read Only Memory (PROM, programmable Read-Only Memory), erasable programmable Read Only Memory (EPROM, erasable Programmable Read-Only Memory), electrically erasable programmable Read Only Memory (EEPROM, electrically Erasable Programmable Read-Only Memory), magnetic random access Memory (FRAM, ferromagnetic random access Memory), flash Memory (Flash Memory), magnetic surface Memory, optical disk, or compact disk Read Only Memory (CD-ROM, compact Disc Read-Only Memory); the magnetic surface memory may be a disk memory or a tape memory. The volatile memory may be random access memory (RAM, random Access Memory), which acts as external cache memory. By way of example, and not limitation, many forms of RAM are available, such as static random access memory (SRAM, static Random Access Memory), synchronous static random access memory (SSRAM, synchronous Static Random Access Memory), dynamic random access memory (DRAM, dynamic Random Access Memory), synchronous dynamic random access memory (SDRAM, synchronous Dynamic Random Access Memory), double data rate synchronous dynamic random access memory (ddr SDRAM, double Data Rate Synchronous Dynamic Random Access Memory), enhanced synchronous dynamic random access memory (ESDRAM, enhanced Synchronous Dynamic Random Access Memory), synchronous link dynamic random access memory (SLDRAM, sync Link Dynamic Random Access Memory), direct memory bus random access memory (DRRAM, direct Rambus Random Access Memory). The memory 3 described in the embodiments of the present invention is intended to comprise, without being limited to, these and any other suitable types of memory.
The method disclosed in the above embodiment of the present invention may be applied to the processor 2 or implemented by the processor 2. The processor 2 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in the processor 2 or by instructions in the form of software. The processor 2 described above may be a general purpose processor, DSP, or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor 2 may implement or perform the methods, steps and logic blocks disclosed in embodiments of the present invention. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in the embodiment of the invention can be directly embodied in the hardware of the decoding processor or can be implemented by combining hardware and software modules in the decoding processor. The software modules may be located in a storage medium in the memory 3 and the processor 2 reads the program in the memory 3 to perform the steps of the method described above in connection with its hardware.
The process corresponding to the multi-core processor in each method of the embodiment of the present invention is implemented when the processor 2 executes the program, and for brevity, will not be described herein.
In an exemplary embodiment, the present invention also provides a storage medium, i.e. a computer storage medium, in particular a computer readable storage medium, for example comprising a memory 3 storing a computer program executable by the processor 2 for performing the steps described in the embodiments corresponding to the foregoing fig. 1-2. The computer readable storage medium may be FRAM, ROM, PROM, EPROM, EEPROM, flash Memory, magnetic surface Memory, optical disk, or CD-ROM.
In the several embodiments provided by the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above described device embodiments are only illustrative, e.g. the division of the units is only one logical function division, and there may be other divisions in practice, such as: multiple units or components may be combined or may be integrated into another system, or some features may be omitted, or not performed. In addition, the various components shown or discussed may be coupled or directly coupled or communicatively coupled to each other via some interface, whether indirectly coupled or communicatively coupled to devices or units, whether electrically, mechanically, or otherwise.
The units described as separate units may or may not be physically separate, and units displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units; some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present invention may be integrated in one processing module, or each unit may be separately used as one unit, or two or more units may be integrated in one unit; the integrated units may be implemented in hardware or in hardware plus software functional units.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the above method embodiments may be implemented by hardware associated with program instructions, where the foregoing program may be stored in a computer readable storage medium, and when executed, the program performs steps including the above method embodiments; and the aforementioned storage medium includes: a mobile storage device, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk or an optical disk, or the like, which can store program codes.
The technical schemes described in the embodiments of the present invention may be arbitrarily combined without any collision.
The foregoing is merely illustrative of the present invention, and the present invention is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A method for applying a function extension, comprising:
binding a first hook function in a source code file of a first application with at least one corresponding plug-in;
running the at least one plug-in bound to the first hook function under the condition that the first hook function is triggered when source codes in the source code file are executed; wherein,
the at least one plug-in is used for expanding a first function in the first application; the at least one plug-in is a built-in plug-in of the first application and/or a plug-in issued to a package management tool;
determining a front-end static resource file of the first application based on the source code file of the first application and the at least one plug-in; the front-end static resource file comprises js source code files, css style files, pictures, font files and the like;
Performing static analysis according to the dependency relationship among all front-end static resource files of the first application through a front-end resource loading/packaging tool to obtain a static analysis result;
generating corresponding static resources according to a specified rule by using the front-end static resource file of the first application based on the static analysis result;
and loading the generated static resource to obtain a front-end page.
2. The method of claim 1, wherein binding the first hook function in the source code file of the first application with the corresponding at least one plug-in comprises:
writing at least one function corresponding to the at least one plug-in into a monitoring function corresponding to the first hook function by calling a set binding function; the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
3. The method of claim 2, wherein the running the at least one plug-in bound to the first hook function in the event that the first hook function is triggered when source code in the source code file is executed, comprises:
Triggering the first hook function by calling a set trigger function when executing the source codes in the source code file;
and executing all function functions in the monitoring function written into the corresponding first hook function under the condition that the first hook function is triggered.
4. A method according to any one of claims 1-3, wherein the method further comprises:
initializing each plugin based on configuration files corresponding to all plugins of the first application to obtain plugin entry files corresponding to the first application; wherein,
the configuration file is used for describing that the corresponding plug-in is used for carrying out function expansion on at least one of a client side and a server side of the first application;
the plug-in entry file is used for describing an access path of at least one of a client entry file and a server entry file included in each plug-in; the access path of the client side entry file is used for acquiring a function in the client side entry file included in the corresponding plug-in; the access path of the server side entry file is used for acquiring the function in the server side entry file included in the corresponding plug-in.
5. The method according to claim 4, wherein the method further comprises:
Determining at least one function corresponding to each plug-in at least one plug-in based on the plug-in entry file and the identification information of each plug-in at least one plug-in corresponding to the first hook function; wherein the determined at least one function is used for binding with the first hook function.
6. The method of claim 4, wherein initializing each plug-in based on configuration files corresponding to all plug-ins of the first application to obtain a plug-in entry file corresponding to the first application comprises:
determining an access path of an entry file of the first plugin based on the configuration file of the first plugin;
determining an access path of an entry file of the second plugin based on the configuration file of the second plugin;
determining a plug-in entry file corresponding to the first application based on the access path of the entry file of the first plug-in and the access path of the entry file of the second plug-in; wherein,
the first plugin characterizes plugins stored under the project catalog of the first application;
a second plug-in characterizes plug-ins of the first application downloaded through a package manager tool;
The portal file includes at least one of a client portal file and a server portal file.
7. The method of claim 6, wherein the access path of the entry file of the first plug-in or the second plug-in is determined by:
splicing the first access path, the second access path and the file name of the inlet file to obtain the access path of the inlet file; wherein,
the first access path characterizes an access path of a plug-in with respect to a root directory of the first application;
the second access path characterizes an access path of the plug-in.
8. An apparatus for applying a function extension, comprising:
the binding unit is used for binding the first hook function in the source code file of the first application with at least one corresponding plug-in;
the execution unit is used for running the at least one plug-in bound with the first hook function under the condition that the first hook function is triggered when the source codes in the source code file are executed; wherein the at least one plug-in is configured to extend a first function in the first application; the at least one plug-in is a built-in plug-in of the first application and/or a plug-in issued to a package management tool; determining a front-end static resource file of the first application based on the source code file of the first application and the at least one plug-in; the front-end static resource file comprises js source code files, css style files, pictures, font files and the like; performing static analysis according to the dependency relationship among all front-end static resource files of the first application through a front-end resource loading/packaging tool to obtain a static analysis result; generating corresponding static resources according to a specified rule by using the front-end static resource file of the first application based on the static analysis result; and loading the generated static resource to obtain a front-end page.
9. An electronic device, comprising: a processor and a memory for storing a computer program capable of running on the processor,
wherein the processor is adapted to perform the steps of the method of any of claims 1 to 7 when the computer program is run.
10. A storage medium having stored thereon a computer program, which when executed by a processor performs the steps of the method according to any of claims 1 to 7.
CN202110021572.8A 2021-01-08 2021-01-08 Application function expansion method and device and electronic equipment Active CN112667246B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110021572.8A CN112667246B (en) 2021-01-08 2021-01-08 Application function expansion method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110021572.8A CN112667246B (en) 2021-01-08 2021-01-08 Application function expansion method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN112667246A CN112667246A (en) 2021-04-16
CN112667246B true CN112667246B (en) 2024-03-01

Family

ID=75413565

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110021572.8A Active CN112667246B (en) 2021-01-08 2021-01-08 Application function expansion method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN112667246B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113176908A (en) * 2021-04-29 2021-07-27 广州嘉为科技有限公司 Method, system, device and medium for dynamically expanding web function and hot-pluggable
CN113064607A (en) * 2021-06-02 2021-07-02 统信软件技术有限公司 Installation method of operating system, computing equipment and storage medium
CN113656000B (en) * 2021-08-11 2024-01-09 北京达佳互联信息技术有限公司 Webpage processing method and device

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9129138B1 (en) * 2010-10-29 2015-09-08 Western Digital Technologies, Inc. Methods and systems for a portable data locker
CN105912362A (en) * 2016-04-11 2016-08-31 北京金山安全软件有限公司 Method and device for loading plug-in and electronic equipment
CN106251876A (en) * 2015-06-12 2016-12-21 徐文波 Audio mixed method based on HOOK technology and system
CN108595203A (en) * 2018-04-28 2018-09-28 努比亚技术有限公司 Application function executes method, mobile terminal and computer readable storage medium
CN110457049A (en) * 2019-06-27 2019-11-15 北京奇艺世纪科技有限公司 Realize method, apparatus, electronic equipment and the storage medium of plug-in unit automation
CN111367560A (en) * 2020-03-13 2020-07-03 苏州浪潮智能科技有限公司 Method, system, equipment and medium for expanding server function

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8458765B2 (en) * 2009-12-07 2013-06-04 Samsung Electronics Co., Ltd. Browser security standards via access control

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9129138B1 (en) * 2010-10-29 2015-09-08 Western Digital Technologies, Inc. Methods and systems for a portable data locker
CN106251876A (en) * 2015-06-12 2016-12-21 徐文波 Audio mixed method based on HOOK technology and system
CN105912362A (en) * 2016-04-11 2016-08-31 北京金山安全软件有限公司 Method and device for loading plug-in and electronic equipment
CN108595203A (en) * 2018-04-28 2018-09-28 努比亚技术有限公司 Application function executes method, mobile terminal and computer readable storage medium
CN110457049A (en) * 2019-06-27 2019-11-15 北京奇艺世纪科技有限公司 Realize method, apparatus, electronic equipment and the storage medium of plug-in unit automation
CN111367560A (en) * 2020-03-13 2020-07-03 苏州浪潮智能科技有限公司 Method, system, equipment and medium for expanding server function

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
Sai Krishna Sripada等.Architecting an extensible framework for Gamifying Software Engineering concepts.《ISEC '16: Proceedings of the 9th India Software Engineering Conference》.2016,全文. *
基于HTML5移动应用框架的研究及应用;连允庆;《中国优秀硕士学位论文全文数据库(信息科技辑)》(第3期);全文 *
基于软件插件的虚拟实验资源库系统的构建;张小龙;霍剑青;袁泉;王晓蒲;;中国科学技术大学学报(第03期);全文 *
适于永中Office二次开发的Java插件技术;吴良巧;;江南大学学报(自然科学版)(第05期);全文 *

Also Published As

Publication number Publication date
CN112667246A (en) 2021-04-16

Similar Documents

Publication Publication Date Title
CN112667246B (en) Application function expansion method and device and electronic equipment
US11556348B2 (en) Bootstrapping profile-guided compilation and verification
US20060064576A1 (en) Boot systems and methods
CN104049986A (en) Plugin loading method and device
CN111124288B (en) VPD storage management method, device, equipment and readable storage medium
CN104881318A (en) Interface calling method and device and terminal
CN110716845B (en) Log information reading method of Android system
CN112882694A (en) Program compiling method and device, electronic equipment and readable storage medium
CN116467015B (en) Mirror image generation method, system start verification method and related equipment
CN112764836A (en) Method and device for running fast application and electronic equipment
CN109918059B (en) Application function expansion method and device, terminal equipment and storage medium
CN115760391A (en) Intelligent contract changing method and device in block chain, electronic equipment and storage medium
CN111177624B (en) Website front-end and back-end communication method, device, computer equipment and storage medium
CN112328241B (en) Method and device for creating Android library module dependency relationship in application program development
CN113377376A (en) Data packet generation method, data packet generation device, electronic device, and storage medium
KR101140522B1 (en) System and Method for Managing Object
CN106897588B (en) Processing method and device of label function
CN110554915A (en) Information processing method and device, computer storage medium and terminal
CN114237626B (en) Method, system and equipment for non-invasively dynamically editing JVM parameters
CN114363387A (en) Application pull-alive method and device, electronic equipment and storage medium
CN118151944A (en) Application development method, device, equipment, storage medium and program product
CN115329227A (en) Block chain intelligent contract editor file management method and device in WebIDE
CN114238871A (en) Class member function protection method in SO, storage medium, electronic device and system
CN114338580A (en) Public account project development method, device and storage medium
CN118051421A (en) Injection method and device for IO time delay fault, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant