Add plugins support#24485
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
|
I'm not familiar with lua and this new plugin system. Here are some high level questions before taking a closer look.
|
No. This is a truly embedded engine, unlike the "crutches" with the launch of external programs as plugins, as we have used in the Search Engine subsystem. Plugins are executed in the qBittorrent process. And they are executed in the main thread, since the qBittorrent core is not multithreaded. Of course, this has certain disadvantages, but they are due to its advantages.
It's unlikely if you remember to catch exceptions when calling Lua.
Yes. Just like a regular function in qBittorrent. The advantage is that you can just stop using a bad plugin (or fix it) instead of waiting for the next update. It is supposed that when using plugins, the responsibility lies with the user himself.
Lua has no low level memory access. |
Sounds dangerous? Would it make sense to have a build-time option to enable/disable the lua plugin feature?
Lets say a newbie user installed a few lua plugins and one of them is faulty. Now qbt is unresponsive immediately after starting it. How can the user find out which one is faulty and remove it? |
Well, at least it can disable them all and enable one by one. |
Is it really that dangerous? Well, it will cause the program to freeze, so what? The user always has the option to disable the failed plugin. (If you don't know which one, then you can disable everything.) |
Then how do you propose to create official builds? With feature enabled, or not? I don't think it makes sense. If users want to use a plugin, they should be aware that we are not responsible for its workability and the overall workability of the application when using it. |
|
It still looks like there is a (indirect) way to control the execution time of Lua code, so I'll try to figure it out. But I still don't consider the current state to be blocking, so I'd rather do this as part of subsequent improvements when this PR is merged. |
359f78b to
b60c40e
Compare
cba0c8b to
338ba99
Compare
31be7eb to
3cbd268
Compare
@Chocobo1 |
|
On the face value of this PR, I don't reject it. Some thoughts on the technical questions raised (I haven't read any of the code):
Some questions because I've read only the description:
|
Lua only.
In fact, I intended to provide plugins with the possibility of some functions like start/stop torrents, change some properties like name, comment. Without this, it will hardly be possible to use them for something more or less useful. |
My thoughts on this topic are in the PR description. |
What exactly is bothering you? If it remains unclaimed, it will be worthless. The existing code will not require any care. Well, if it finds its audience, then most likely there will be user requests for its correction, improvement, extension. But what's unexpected about that? |
Don't forget that plugin has a deadline, so it will be interrupted anyway. |
As I said above:
In order for plugins to live in a separate thread, they must either
It should be clear that both of these methods are much more troublesome to implement than the current one. |
OK. I was probably overthinking about potential problems and threat level.
Forgive me if my following comment is wrong. I haven't read the code so I don't know exactly how the interface is implemented.
Sure. But I think it is good practice to have a killswitch.
OK. It was a suggestion. I was thinking about the ping/pong mechanism. That's why I made those 2 suggestions. |
I can't find a google reference for lua ATTOW. Is this source provided by https://www.lua.org/ ? Also put appropriate entries in the |
At The Time Of Writing |
This adds an experimental feature to support Lua plugins.
This is not a replacement/alternative to Search Plugins and has nothing to do with them. These are general purpose plugins.
Motivation
The idea of adding plugin support has been on my mind for a very long time, but I still haven't had time to take it seriously. It consists in providing users with the opportunity to integrate into their qBittorrent some additional functions that are useful to them, which are unlikely to be added to the core of qBittorrent (for example, due to the reluctance to overload it with features that have a very limited user audience. Users occasionally request some features that seem to be relevant only to themselves, so we usually reject them).
We also have some functions in qBittorrent that have limited integration with the main code, so they can easily be implemented by plugins, and can later be removed from the core. I mean, something like sending email notifications and launching external programs. These are all functions that do not have deep integration with the main logic of the application, they just obtain some data and transmit it to the outside world. In addition, they are unlikely to be used by most users. But at the same time, some individuals request their extension from time to time, for example, by executing at other events. I consider it highly undesirable to overload the core with such functions.
Note that it is not initially intended to provide any official plugins (except as plugin examples). However, this is quite possible in the future, if anyone wants to maintain them.
Interface
The main interface of plug-ins with the application core is "event handling". Event handlers are called for all installed plugins (provided, of course, that the plugin has a corresponding handler defined). At the same time, plug-ins (deliberately) live permanently during the lifetime of the application (well, either until they are uninstalled or updated), so they can store some data and track their changes.
Plugins can also be "user invocable" by providing the
invoke()function. In this case, they can also be invoked by the user (for example, through the Plugins menu).Implementation notes
The feature is based on the core Lua library (of the version 5.5 ATTOW) and LuaBridge3.
I deliberately chose to integrate their source code into the qBittorrent source tree in order to facilitate its building and distribution on different target platforms, and this should ensure more controlled compatibility with the plugins code, since we will always have a specific version of Lua and update it, if necessary, only in major qBittorrent updates.
Current state
Currently, all management functions are ready, such as installing, updating, and removing plug-ins, as well as enabling/disabling them. They are supported by GUI.
I have added support for most torrent-related events and their basic properties, so the rest can be added incrementally later.
"Invocable" plugins are listed under "Plugins" menu and can be invoked from there.
I have added several examples of plugins that demonstrate their main features and can serve as a basis for developing custom plug-ins.
Note for reviewers
Please refrain from suggesting any improvements that are not mandatory at the initial stage. Quite a lot of work has already been done to provide this PR, so I would prefer to focus on fixing the obvious bugs and merging it into the qBittorrent code. This would make it easier for me to maintain and improve it further.