CN112667246A - Application function extension method and device and electronic equipment - Google Patents

Application function extension method and device and electronic equipment Download PDF

Info

Publication number
CN112667246A
CN112667246A CN202110021572.8A CN202110021572A CN112667246A CN 112667246 A CN112667246 A CN 112667246A CN 202110021572 A CN202110021572 A CN 202110021572A CN 112667246 A CN112667246 A CN 112667246A
Authority
CN
China
Prior art keywords
plug
function
file
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.)
Granted
Application number
CN202110021572.8A
Other languages
Chinese (zh)
Other versions
CN112667246B (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

Images

Abstract

The invention discloses a method and a device for application function expansion and electronic equipment, wherein the method for application function expansion 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 with the first hooking function in the case that the first hooking function is triggered when executing source code in the source code file; wherein the at least one plug-in is to extend a first function in the first application.

Description

Application function extension 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 changing to financial technology (Fintech), however, the financial technology also puts higher demands on the technology due to the requirements of security and real-time performance of the financial industry. Under the scenario of extending the web application function of financial technology, the workload of modifying the source code file is large and the coupling degree of the source code is high, which results in high development cost and poor flexibility.
Disclosure of Invention
In view of this, embodiments of the present invention are expected to provide a method, an apparatus, and an electronic device for extending an application function, so as to solve the technical problems of higher development cost and poorer flexibility in extending a web application function in the related art.
In order to achieve the 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 with the first hooking function in the case that the first hooking function is triggered when executing source code in the source code file; wherein the content of the first and second substances,
the at least one plug-in is to extend a first function in the first application.
In the above scheme, the binding a first hook function in a source code file of a first application with a 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; and the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
In the above scheme, the running the at least one plug-in bound to the first hooking function when the first hooking function is triggered when the source code in the source code file is executed includes:
when the source code in the source code file is executed, triggering the first hook function by calling a set trigger function;
and under the condition that the first hook function is triggered, executing all function functions written into the listening function of the corresponding first hook function.
In the above scheme, the method further comprises:
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 content of the first and second substances,
the configuration file is used for describing a corresponding plug-in for performing function extension on at least one of a client and a server 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 by each plug-in; the access path of the client entry file is used for acquiring a function in the client entry file included by the corresponding plug-in; and the access path of the server-side entry file is used for acquiring the function in the server-side entry file included by the corresponding plug-in.
In the above scheme, the method further comprises:
determining at least one function corresponding to each plug-in the 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; and the determined at least one function is used for binding with the first hook function.
In the foregoing solution, initializing each plugin based on configuration files corresponding to all plugins of the first application to obtain a plugin entry file corresponding to the first application includes:
determining an access path of an entry file of the first plug-in based on the configuration file of the first plug-in;
determining an access path of an entry file of the second plug-in based on the configuration file of the second plug-in;
determining an insert entry file corresponding to the first application based on the access path of the entry file of the first insert and the access path of the entry file of the second insert; wherein the content of the first and second substances,
the first plug-in represents a plug-in stored in an item catalog of the first application;
the second plug-in characterizes a plug-in of the first application downloaded through the 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:
splicing the first access path, the second access path and the file name of the entry file to obtain an access path of the entry file; wherein the content of the first and second substances,
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.
An embodiment of the present invention further provides an apparatus for extending an application function, including:
the binding unit is used for binding a first hook function in a source code file of a 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 code in the source code file is executed; wherein the content of the first and second substances,
the at least one plug-in is to extend a first function in the first application.
An embodiment of the present invention further provides an electronic device, including: a processor and a memory for storing a computer program capable of running on the processor,
wherein the processor is configured to execute any of the above method steps for extending application functions when running the computer program.
Embodiments of the present invention further provide a storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of any one of the above methods for application function extension.
In 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 plug-in; running the at least one plug-in bound with the first hooking function in the case that the first hooking function is triggered when executing source code in the source code file; wherein the at least one plug-in is to extend a first function in the first application. According to the scheme, function extension is realized by operating the plug-in bound with the first hook function, so that developers can independently develop extension functions, the coupling degree between the main program and the extension program is reduced, and the flexibility of function extension is improved; developers do not need to modify the source code files greatly, 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 flow chart illustrating an implementation process of a method for extending an application function according to an embodiment of the present invention;
fig. 2 is a schematic flow chart illustrating an implementation process of a method for extending an application function according to another embodiment of the present invention;
fig. 3 is a schematic structural diagram of an apparatus for extending application functions according to an embodiment of the present invention;
fig. 4 is a schematic diagram of a hardware component 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-rear end separation mode: the front end and the rear end are independent of each other; the front end is responsible for rendering a User Interface (UI) of the web application and loading data provided by the back end to the UI.
Front and rear end non-separated mode: the back-end controls rendering or redirection of the UI of the front-end, display effects, etc.
The source code file is modified by a developer based on the method, so that when the function of the web application is extended, a large amount of source codes in the source code file need to be modified, the workload for modifying the source codes is large, the development cost is high, the coupling degree between the main program and the extension program is high, independent development cannot be performed on the extension function, and the flexibility is poor.
In order to solve the technical documents, 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 with the first hooking function in the case that the first hooking function is triggered when executing source code in the source code file; wherein the at least one plug-in is to extend a first function in the first application. According to the scheme, function extension is realized by operating the plug-in bound with the first hook function, so that developers can independently develop extension functions, the coupling degree between the main program and the extension program is reduced, and the flexibility of function extension is improved; developers do not need to modify the source code files greatly, 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 solution of the present invention is further described in detail with reference to the drawings and the specific embodiments of the specification.
Fig. 1 shows a schematic implementation flow diagram of a method for extending an application function according to an embodiment of the present invention. In the embodiment of the invention, the 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 computer, a desktop computer and the like.
Referring to fig. 1, a method for extending an application function provided in an 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 to add a first function in the first application.
Here, the electronic device obtains all plug-ins of the first application and determines at least one first hook function included in a source code file of the first application; determining at least one plug-in corresponding to each first hook function based on the acquired identification information of the hook function contained in the plug-in and the determined identification information of each first hook function; and binding each first hook function and the corresponding at least one plug-in. Wherein the content of the first and second substances,
the plug-in developed by the developer can be a built-in plug-in of the first application, and can also be issued to a Package management tool (NPM), and the built-in plug-in is stored in a project directory of the first application; the plug-in issued 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 obtains a first plug-in from the item directory of the first application and a second plug-in from the file directory of the NPM, thereby obtaining all plug-ins of the first application. In practical applications, the file directory of the NPM may be node _ modules. The plug-in is used to extend a new first functionality of the first application.
The first hook function generally refers to any hook function set by a developer in a source code file of the first application. The number of first hook functions is at least one. Each first hook function is used for providing an extension point, so that a developer writes source code aiming at the corresponding extension point, and therefore the function extension is carried out aiming at the extension point. The extension point characterizes the access point to which the plug-in is introduced.
In a practical application, the first application is a web application. The developer may 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 extend the functions of the source code modules based on the corresponding first hook function set for each source code module.
The first hook function includes identification information, a type, and a listening function. The first hook function corresponding to the type representation allows binding once or runs binding at least twice; and the monitoring function is used for writing the function in the plug-in 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 represented to allow binding once, and the number of the 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 to be allowed to be bound at least twice, and the number of the plug-ins corresponding to the first hook function is at least two.
Illustratively, a developer may set a corresponding first hook function for a source code module in a source code file of the first application, where the source code module is used to implement a "navigation menu," and identification information of the hook function may be sub-nav.
It should be noted that the plug-in represents 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 a corresponding plug-in for performing function extension on at least one of a client and a server of the first application; the entry file may be a server-side entry file or a client-side entry file.
In practical applications, the configuration file may be index. js; when the configuration file is used for describing the corresponding plug-in for carrying out function extension 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 extension on the server of the first application, the plug-in comprises a server entry file; when the configuration file is used for describing that the corresponding plug-in is used for carrying out function extension on the client and the server of the first application, the plug-in comprises a client entry file and a server entry file.
Js includes a first field and a second field, the first field may be "client" and the second field may be "server" in practical applications. The first field represents whether the corresponding plug-in is used for carrying out function extension on the client of the first application or not; and the second field represents whether the corresponding plug-in is used for performing function extension on the server of the first application. When a first field client in the index.js is 'true', the plug-in comprises a client entry file client.js; when a second field server in index.js is 'true', the plugin comprises a server-side entry file server.js; when the first field client and the second field server in index.js are both "true", the plug-in includes client.js and server.js.
It should be noted that the server-side entry file and the client-side entry file both include corresponding function functions and identification information of hook functions that need 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; and the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
Here, the electronic device calls the set binding function when determining the plug-in corresponding to each first hook function, writes the function in the plug-in corresponding to the first hook function into the monitor function in the first hook function, and binds the identification information of the first hook function and the function in the corresponding plug-in, that is, binds the first hook function and the corresponding plug-in. And 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 set binding function may be a bindbook ('hook-name', function); 'hook-name' represents identification information of the first hook function; the function characterizes a function in the plug-in.
According to 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 and the corresponding plug-in are bound. Whether the corresponding first hook function is triggered is monitored through the monitoring function in the first hook function, and when the corresponding first hook function is triggered, all function functions in the monitoring function are executed, so that the function functions in the plug-in are quickly integrated into the first application, 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 with the first hooking function in the case that the first hooking function is triggered when executing source code in the source code file; wherein the at least one plug-in is to extend a first function in the first application.
Here, the electronic device triggers the first hooking function in the process of executing the source code in the source code file of the first application, and runs at least one plug-in bound with the first hooking function in the case of triggering the first hooking function, so as to execute a function in the at least one plug-in bound with the first hooking function 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 bound to the first hook function, or a first function may be extended in the first application by at least two plug-ins bound to the first hook function.
In practical application, under the condition that the first hook function is arranged at a corresponding position of a source code module used for realizing a 'navigation menu' in a source code file of the first application, when the electronic equipment finishes executing the source code of the source code module of the 'navigation menu', the corresponding first hook function is triggered, and at least one plug-in bound with the first hook function is operated. For example, when a plug-in bound to the first hook function is used to add a "document" option in a "navigation menu", the electronic device displays the "navigation menu" including the "document" option after the function in the plug-in is executed.
In some embodiments, said running said at least one plug-in bound to said first hooking function in case said first hooking function is triggered when executing source code in said source code file comprises:
when the source code in the source code file is executed, triggering the first hook function by calling a set trigger function;
and under the condition that the first hook function is triggered, executing all function functions written into the listening function of the corresponding first hook function.
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; and the monitoring function in the first hook function monitors that the corresponding first hook function is triggered, and executes all the function functions written into the monitoring function of the corresponding first hook function.
In practical applications, the set trigger function may be emithook ('hook-name').
In the scheme provided by this embodiment, a first hook function in a source code file of a first application is bound with at least one corresponding plug-in; in the event that a first hooking function is triggered when executing source code in the source code file, at least one plug-in bound to the first hooking function is run, thereby extending a first function of the first application. According to the scheme, function extension is realized by operating the plug-in bound with the first hook function, so that developers can independently develop extension functions, the coupling degree between the main program and the extension program is reduced, and the flexibility of function extension is improved; developers do not need to modify the source code files greatly, 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 plug-in management file, and the identification of the plug-in management file may be plugin. 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 is used for enabling the electronic equipment to call the set binding function and the set triggering function. 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 diagram illustrating an implementation flow 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 a plugin entry file corresponding to the first application; wherein the content of the first and second substances,
the configuration file is used for describing a corresponding plug-in for performing function extension on at least one of a client and a server 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 by each plug-in; the access path of the client entry file is used for acquiring a function in the client entry file included by the corresponding plug-in; and the access path of the server-side entry file is used for acquiring the function in the server-side entry file included by the corresponding plug-in.
In practical application, the electronic equipment acquires a configuration file contained in each plug-in of a first application under the condition of acquiring all plug-ins of the first application; and initializing each plug-in based on the configuration files corresponding to all the plug-ins of the first application by operating the plug-in management file plugin. Wherein the content of the first and second substances,
the plug-in of the first application comprises 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 extension 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 extension on the server of the first application, the corresponding plug-in comprises a server entry file, and the plug-in entry file comprises an access path of the server entry file of the corresponding plug-in;
when the configuration file is used for describing that the corresponding plug-in is used for performing function extension on the client and the server of the first application, the corresponding plug-in comprises a client entry file and a server entry file, and the plug-in entry file comprises an access path of the client entry file and an access path of the server 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 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 and the access path of the corresponding entry file have a corresponding relationship.
In some embodiments, in order to avoid that the first application cannot load part of the extended functions developed by developers, the success rate of adding the extended functions in the first application is improved; initializing each plugin based on the configuration files corresponding to all plugins of the first application to obtain a plugin entry file corresponding to the first application, including:
determining an access path of an entry file of the first plug-in based on the configuration file of the first plug-in;
determining an access path of an entry file of the second plug-in based on the configuration file of the second plug-in;
determining an insert entry file corresponding to the first application based on the access path of the entry file of the first insert and the access path of the entry file of the second insert; wherein the content of the first and second substances,
the first plug-in represents a plug-in stored in an item catalog of the first application;
the second plug-in characterizes a plug-in of the first application downloaded through the package manager tool;
the portal file includes at least one of a client portal file and a server portal file.
Here, the electronic device traverses the item directory of the first application, and acquires a first plug-in stored in the item directory of the first application; under the condition that the first plug-in of the first application is obtained, the electronic equipment determines an entry file contained in the first plug-in based on a configuration file of the first plug-in, and determines an access path of the entry file of the first plug-in based on a storage path of the first plug-in and a name of the entry file.
The electronic equipment traverses the file directory of the package management tool and acquires all second plug-ins of the first application stored in the file directory of the package management tool; under the condition that a second plug-in of the first application is obtained, the electronic equipment determines an entry file contained in the second plug-in based on a configuration file of the second plug-in, and determines an access path of the entry file of the second plug-in based on a storage path of the second plug-in and a name of the entry file.
And under the condition that the access paths of all the first plug-ins and the access paths of all the second plug-ins are determined, combining the access paths of the entry files of the first plug-ins and the access paths of the entry files of the second plug-ins to obtain the plug-in entry files corresponding to the first application.
In addition, in the case that the first plug-in of the first application does not exist, the plug-in entry file corresponding to the first application only includes the access path of the entry file of the second plug-in. And under the condition that the second plug-in of the first application does not exist, only the access path of the entry file of the first plug-in is included in the plug-in entry file corresponding to the first application.
In some embodiments, in order to more accurately determine an access path of a portal file to improve the probability of acquiring a function in the portal file included in a 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 entry file to obtain an access path of the entry file; wherein the content of the first and second substances,
the first access path characterizes an access path of a corresponding plug-in relative to a root directory of the first application;
the second access path characterizes an 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 with respect to a root directory of the first application; the method comprises the following steps that (1) identification-plug-in-import-postman represents the name of a first plug-in, wherein the first plug-in comprises a client side entry file and a server side entry file; js represents the name of a client entry file included in the first plug-in; js represents 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" characterize the access path of the second plug-in with respect to the root directory of the first application; "apidesign-plugin-import-har" represents the name of a second plugin, wherein the second plugin comprises a server-side entry file and does not comprise a client-side entry file; js represents the name of the server portal file included in the second plug-in.
S202: determining at least one function corresponding to each plug-in the 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; and the determined at least one function is used for binding with the first hook function.
Here, the electronic device obtains an access path of an entry file corresponding to the identification information of each plug-in from the determined plug-in entry files based on the identification information of each plug-in corresponding to the first hook function, and obtains an access path of an entry file corresponding to each plug-in. And under the condition that the access path of the entry file corresponding to the plug-in is obtained, accessing the entry file contained in the corresponding plug-in based on the obtained access path of the entry file, and obtaining the corresponding function from the accessed entry file, thereby obtaining at least one function corresponding to each plug-in. 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 entry file included by a corresponding plug-in; and the second function represents the function in the server entry file included by the corresponding plug-in.
In practical application, when the access path of the entry file corresponding to the identification information of the plug-in includes the access path of the client entry file, the electronic device accesses the client entry file in the corresponding plug-in 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 plug-in.
When the access path of the entry file corresponding to the identification information of the plug-in includes the access path of the server-side entry file, the electronic device accesses the server-side entry file in the corresponding plug-in based on the access path of the server-side entry file, reads the second function from the accessed server-side entry file, and obtains the second function corresponding to the corresponding plug-in.
When the access path of the entry file corresponding to the identification information of the plug-in comprises the access path of the client entry file and the access path of the server entry file, the electronic equipment accesses the client entry file in the corresponding plug-in based on the access path of the client entry file, and reads a first function from the accessed client entry file; and accessing the server side entry file in the corresponding plug-in based on the access path of the server side entry file, and reading the second function from the accessed server side entry file to obtain the first function and the second function corresponding to the corresponding plug-in.
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; and the monitoring function is used for executing all function functions in the monitoring function when the first hook function is triggered.
Here, when determining the function corresponding to each plug-in corresponding to the first hook function, the electronic device calls a set binding function in the plug-in management file plugin.
S204: and when the source code in the source code file is executed, triggering the first hook function by calling a set trigger 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 the set trigger function in the plug-in management file plugin.
S205: and under the condition that the first hook function is triggered, executing all function functions written into the listening function of the corresponding first hook function.
Here, the listening function in the first hook function listens that the corresponding first hook function is triggered, and the electronic device executes all function functions written in the listening function of the corresponding first hook 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 plug-ins 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 by a front-end resource loading/packaging tool to obtain a static analysis result, generating corresponding static resources from the front-end static resource files of the first application according to a specified rule based on the static analysis result, and loading the generated static resources to obtain a front-end page.
Wherein the content of the first and second substances,
the front-end resource loading/packaging tool may be Webpack, Rollup, Parcel, or SystemJS.
The front-end static resource files comprise js source code files, css style files, pictures, font files and the like.
The implementation process of generating the corresponding static resource according to the specified rule by the Webpack is as follows:
and traversing application entry files application.js of the first application by using a webpack tool, recursively analyzing the front-end static resource files referenced by the first application, and performing corresponding processing according to the file types of the front-end static resource files. Wherein the content of the first and second substances,
the front-end static resource file type is identified by a 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 characterized to be a JavaScript script file; when the suffix name of the front-end static resource file is "png", "gif", "jpg", or "jpeg", the representation of the corresponding front-end static resource file is a picture file. When the suffix name of the front-end static resource file is 'sass', 'scss' or 'css', representing that the corresponding front-end static resource file is a pattern file; when the suffix name of the front-end static resource file is "woff", "woff 2", "eot", "ttf" or "svg", it represents that the corresponding front-end static resource file is a font file.
When the front-end static resource file is a picture, whether base64 is embedded is determined according to the size of the file by using webpack; wherein, when the file size is smaller than 50kb, the picture path is replaced by base 64.
And when the front-end static resource file is a style file, translating and merging the compressed file by using the corresponding grammar, and adding a hash to the file name to replace a reference path.
And when the front-end static resource file is a JS file, translating, merging and compressing the file by using the corresponding grammar and adding a hash to the file name by using the webpack to replace a reference path. The front-end static resource files which are imported through require.
When the front-end static resource file is a font file, the webapc is used for adding hash to the file name of the font file, and a path is replaced.
It should be noted that the static resource after webpack finally generates a file under a directory, for example, a dist file. The style file after the application of the entry file is merged is added to the index.
It should be noted that the server of the first application is a NodeJS application, and the first application is introduced and executed by a require method when the first application is started.
The require is a built-in method of the NodeJS, and is used for introducing a module (related file) in the NodeJS application to realize module management.
In practical applications, when a plug-in of a first application is issued to npm, the electronic device adds the corresponding plug-in to an item of the first application through a command provided through npm when the first application is started, thereby initializing the corresponding plug-in.
In the scheme provided by this embodiment, each plugin is initialized based on configuration files corresponding to all plugins of a first application 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 the 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 the 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 the first hook function by calling the set binding function; when the source code in the source code file is executed, triggering a first hook function by calling a set trigger function; under the condition that the first hook function is triggered, all function functions written into the monitoring function of the corresponding first hook function are executed, so that the functional functions in the plug-in of the first application can be prevented from being omitted, all new functions which cannot be expanded by developers can be prevented from being added into the first application, and the success rate of adding the expanded functions into the first application can be improved.
In order to implement the method according to the embodiment of the present invention, an application function extension apparatus is further provided in an embodiment of the present invention, and as shown in fig. 3, the application function extension apparatus 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 run the at least one plug-in bound to the first hooking function when the first hooking function is triggered when executing the source code in the source code file; wherein the content of the first and second substances,
the at least one plug-in is to extend a first function in the first application.
In some embodiments, the binding unit 31 is configured to:
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; and 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:
when the source code in the source code file is executed, triggering the first hook function by calling a set trigger function;
and under the condition that the first hook function is triggered, executing all function functions written into the listening function of the corresponding first hook function.
In some embodiments, the apparatus for applying a function extension further comprises:
the initialization unit is used for initializing each plug-in based on the configuration files corresponding to all the plug-ins of the first application to obtain a plug-in entry file corresponding to the first application; wherein the content of the first and second substances,
the configuration file is used for describing a corresponding plug-in for performing function extension on at least one of a client and a server 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 by each plug-in; the access path of the client entry file is used for acquiring a function in the client entry file included by the corresponding plug-in; and the access path of the server-side entry file is used for acquiring the function in the server-side entry file included by the corresponding plug-in.
In some embodiments, the apparatus for applying a function extension further comprises:
a determining unit, configured to determine, based on the plug-in entry file and identification information of each of at least one plug-in corresponding to the first hook function, at least one function corresponding to each of the at least one plug-in; and the determined at least one function is used for binding with the first hook function.
In some embodiments, the initialization unit is to:
determining an access path of an entry file of the first plug-in based on the configuration file of the first plug-in;
determining an access path of an entry file of the second plug-in based on the configuration file of the second plug-in;
determining an insert entry file corresponding to the first application based on the access path of the entry file of the first insert and the access path of the entry file of the second insert; wherein the content of the first and second substances,
the first plug-in represents a plug-in stored in an item catalog of the first application;
the second plug-in characterizes a plug-in of the first application downloaded through the 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 an access path of an 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 entry file to obtain an access path of the entry file; wherein the content of the first and second substances,
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 applications, the device for applying the function extension includes units that can be implemented by a processor in the device for applying the function extension. Of course, the processor needs to run the program stored in the memory to realize the functions of the above-described program modules.
It should be noted that: in the device for extending application functions provided in the above embodiments, when the application is functionally extended, only the division of each program module is illustrated, and in practical applications, the above processing may be distributed and completed by different program modules as needed, that is, the internal structure of the device for extending application functions is divided into different program modules, so as to complete all or part of the above-described processing. In addition, the apparatus for extending an application function and the method for extending an application function provided in the foregoing embodiments belong to the same concept, and specific implementation processes thereof are detailed in the method embodiments and will not be described herein again.
Based on the hardware implementation of the program module, in order to implement the method according to the embodiment of the present invention, an embodiment of the present invention further provides an electronic device. Fig. 4 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention, and as shown in fig. 4, the electronic device includes:
a communication interface 1 capable of information interaction with other devices such as a server and the like;
and the processor 2 is connected with the communication interface 1 to realize information interaction with other equipment, and is used for executing the method for extending the application function provided by one or more technical schemes when running a computer program. And the computer program is stored on the memory 3.
In practice, of course, the various components in the electronic device are coupled together by the bus system 4. It will be appreciated that the bus system 4 is used to enable connection communication 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. For the sake of clarity, however, 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. Among them, the nonvolatile Memory may be a Read Only Memory (ROM), a Programmable Read Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a magnetic random access Memory (FRAM), a Flash Memory (Flash Memory), a magnetic surface Memory, an optical disk, or a Compact Disc Read-Only Memory (CD-ROM); the magnetic surface storage may be disk storage or tape storage. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of illustration and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM), Enhanced Synchronous Dynamic Random Access Memory (Enhanced Synchronous Dynamic Random Access Memory), Synchronous linked Dynamic Random Access Memory (DRAM, Synchronous Link Dynamic Random Access Memory), Direct Memory (DRmb 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 by the above embodiment of the present invention can be applied to the processor 2, or implemented by the processor 2. The processor 2 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 2. The processor 2 described above may be a general purpose processor, a 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. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed by the embodiment of the invention can be directly implemented by a hardware 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 located in the memory 3, and the processor 2 reads the program in the memory 3 and in combination with its hardware performs the steps of the aforementioned method.
When the processor 2 executes the program, the process corresponding to the multi-core processor in each method according to the embodiment of the present invention is realized, and for brevity, no further description is given here.
In an exemplary embodiment, the embodiment of the present invention further provides a storage medium, specifically a computer storage medium, which is a computer readable storage medium, for example, including a memory 3 storing a computer program, where the computer program is executable by a processor 2 to complete the steps in the foregoing embodiments corresponding to fig. 1 to 2. The computer readable storage medium may be Memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface Memory, optical disk, or CD-ROM.
In the embodiments provided in 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 merely illustrative, for example, the division of the unit is only a logical functional division, and there may be other division ways in actual implementation, such as: multiple units or components may be combined, or may be integrated into another system, or some features may be omitted, or not implemented. In addition, the coupling, direct coupling or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection between the devices or units may be electrical, mechanical or other forms.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed on a plurality of network units; some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, all the functional units in the embodiments of the present invention may be integrated into one processing module, or each unit may be separately used as one unit, or two or more units may be integrated into one unit; the integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: a mobile storage device, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The technical means described in the embodiments of the present invention may be arbitrarily combined without conflict.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.

Claims (10)

1. A method of applying a functionality 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 with the first hooking function in the case that the first hooking function is triggered when executing source code in the source code file; wherein the content of the first and second substances,
the at least one plug-in is to extend a first function in the first application.
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; and 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 executing the at least one plug-in bound to the first hooking function in the case that the first hooking function is triggered when executing source code in the source code file comprises:
when the source code in the source code file is executed, triggering the first hook function by calling a set trigger function;
and under the condition that the first hook function is triggered, executing all function functions written into the listening function of the corresponding first hook function.
4. The method according to any one of claims 1-3, further comprising:
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 content of the first and second substances,
the configuration file is used for describing a corresponding plug-in for performing function extension on at least one of a client and a server 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 by each plug-in; the access path of the client entry file is used for acquiring a function in the client entry file included by the corresponding plug-in; and the access path of the server-side entry file is used for acquiring the function in the server-side entry file included by the corresponding plug-in.
5. The method of claim 4, further comprising:
determining at least one function corresponding to each plug-in the 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; and the determined at least one function is used for binding with the first hook function.
6. The method according to claim 4, wherein initializing each plugin based on configuration files corresponding to all plugins of the first application to obtain a plugin entry file corresponding to the first application comprises:
determining an access path of an entry file of the first plug-in based on the configuration file of the first plug-in;
determining an access path of an entry file of the second plug-in based on the configuration file of the second plug-in;
determining an insert entry file corresponding to the first application based on the access path of the entry file of the first insert and the access path of the entry file of the second insert; wherein the content of the first and second substances,
the first plug-in represents a plug-in stored in an item catalog of the first application;
the second plug-in characterizes a plug-in of the first application downloaded through the 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 entry file to obtain an access path of the entry file; wherein the content of the first and second substances,
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 extending application functionality, comprising:
the binding unit is used for binding a first hook function in a source code file of a 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 code in the source code file is executed; wherein the content of the first and second substances,
the at least one plug-in is to extend a first function in the first application.
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 one of claims 1 to 7 when running the computer program.
10. A storage medium having a computer program stored thereon, the computer program, when being executed by a processor, realizing the steps of the method of any one 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 true CN112667246A (en) 2021-04-16
CN112667246B 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)

Cited By (3)

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

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110138174A1 (en) * 2009-12-07 2011-06-09 Samsung Electronics Co., Ltd. Browser security standards via access control
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

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110138174A1 (en) * 2009-12-07 2011-06-09 Samsung Electronics Co., Ltd. Browser security standards via access control
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 (5)

* 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》 *
SIKOGG: "钩子的应用和生命周期的实现", Retrieved from the Internet <URL:https://www.jianshu.com/p/c680defe0538> *
吴良巧;: "适于永中Office二次开发的Java插件技术", 江南大学学报(自然科学版), no. 05 *
张小龙;霍剑青;袁泉;王晓蒲;: "基于软件插件的虚拟实验资源库系统的构建", 中国科学技术大学学报, no. 03 *
连允庆: "基于HTML5移动应用框架的研究及应用", 《中国优秀硕士学位论文全文数据库(信息科技辑)》, no. 3 *

Cited By (4)

* 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
CN113656000A (en) * 2021-08-11 2021-11-16 北京达佳互联信息技术有限公司 Webpage processing method and device
CN113656000B (en) * 2021-08-11 2024-01-09 北京达佳互联信息技术有限公司 Webpage processing method and device

Also Published As

Publication number Publication date
CN112667246B (en) 2024-03-01

Similar Documents

Publication Publication Date Title
CN112667246B (en) Application function expansion method and device and electronic equipment
US7743228B2 (en) Information processing apparatus and method for obtaining software processing log
CN104049986A (en) Plugin loading method and device
CN111124288B (en) VPD storage management method, device, equipment and readable storage medium
CN111680253A (en) Page application data packet generation method and device, computer equipment and storage medium
CN107479868B (en) Interface loading method, device and equipment
CN112988284A (en) Application program starting method and device, computer equipment and storage medium
CN110716845A (en) Method for reading log information of Android system
CN112882694A (en) Program compiling method and device, electronic equipment and readable storage medium
CN112069468A (en) Method and equipment for dynamic watermarking of page
CN114048415A (en) Form generation method and device, electronic equipment and computer readable storage medium
CN113742623A (en) Page loading method, assembly, system, device and computer readable storage medium
CN112559026A (en) API interface-based native capability expansion method, device and storage medium
CN115576536A (en) Method and system for automatically generating interface document by analyzing byte codes
CN112148318B (en) Application package release method, application method, device, medium, server and equipment
CN112328241B (en) Method and device for creating Android library module dependency relationship in application program development
CN114416530A (en) Byte code modification method and device, computer equipment and storage medium
CN113377376A (en) Data packet generation method, data packet generation device, electronic device, and storage medium
CN106897588B (en) Processing method and device of label function
CN108089852B (en) Method, medium, apparatus and computing device for establishing attribute access
CN112068814A (en) Method, device, system and medium for generating executable file
CN117519691B (en) Application processing method, device, computer equipment and storage medium
CN111177624B (en) Website front-end and back-end communication method, device, computer equipment and storage medium
CN115329227A (en) Block chain intelligent contract editor file management method and device in WebIDE
CN115421785A (en) Application program migration processing method, device and 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