-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal]: Plugin Builder #2959
Comments
I think this is a good approach overall but the naming of |
Yeah I'm not happy with that name either. What do you think about this note:
|
I must have missed that note. I think |
Recently I wrote a plugin for sentry and custom titlebar and they need the initialization script. Also I think |
I guess there are situations like this where accessing the global is nice, you're right.
I have been struggling with making the api like sketched out above work. (The macro does not work with a vec as input) so this makes sense yes. I have one question though: We now export these 3 things (and others) from the plugin module |
I like the idea of the plugin builder returning a trait impl btw. I think we can improve the trait usage in the future, allowing the plugin's self instance to be accessed. |
I don't like the naming right now though, use tauri::plugin::{Builder, TauriPlugin};
pub fn init() -> TauriPlugin {
Builder::new("foo").build()
} just feels weird, I'd prefer: use tauri::plugin::{Builder, Plugin};
pub fn init() -> Plugin {
Builder::new("foo").build()
} accessing the builder could even be a static method on the plugin struct or something: use tauri::plugin::Plugin;
pub fn init() -> Plugin {
Plugin::new("foo").build()
} This would mean renaming the trait though, so a breaking change. Wdyt @lucasfernog ?
|
I think renaming Maybe the trait could be |
How about keeping |
I like |
Let's move the discussion to the PR everyone! |
Co-authored-by: Amr Bashir <[email protected]> Co-authored-by: Lucas Nogueira <[email protected]>
Is your feature request related to a problem? Please describe.
There are several observations I made about the current
Plugin
trait that I would like to address:app.manage
andapp.state
methods. (This state is also accessible in commands while plugin struct fields are not)Plugin
method names are not super self explanatory and naming is somewhat inconsistent (created
is an event callback but is not namedon_created
whileon_event
andon_page_load
are)invoke_handler
field and aextend_api
to register commands is not obviousconfig
property taken from thetauri.conf.json
file had little use and makes plugins more confusing rather than easier to use. It has shown that exporting a builder and having configuration "in-code" is better.In general I think the current Plugin api leads to unnecessarily verbose and complex plugins, so I would like to propose an improved builder based API:
Describe the solution you'd like
Introduce a
PluginBuilder
struct to streamline the plugin creation:Instead of the current api:
The proposed builder methods closely resemble the traits methods, with a few differences:
js
instead ofinitiailization_script
,commands
instead ofextend_api
andsetup
instead ofinitialize
.with the prefix
on_
The
PluginBuilder
struct could just be wrapper returningPlugin
trait implementations, so this proposal would have a clear implementation path.Notes
init
(as shown in the example above). This function is free to receive any arguments, so plugin authors may use this to provide configuration options for end users.js
/initialization_script
methods all together. Plugins should expose corresponding js packages and not rely on extending the global object. The overwhelming majority of tauri projects also uses bundlers which make providing api packages is a no-brainer. For the few projects that don't, plugin can provide prebuilt browser bundles. See tauri-plugin-store for an example of this.Describe alternatives you've considered
Leave the trait as is.
Additional context
The builder pattern is inspired by
deno_core
sExtensionBuilder
.The
init
function is inspired by denos extensions and the convention among rollup plugins to export a single creation function.The text was updated successfully, but these errors were encountered: