Skip to content

[feat]: Reduce boilerplate for command definitions in Tauri v2 #10075

@Norbiros

Description

@Norbiros

Describe the problem

I am currently updating a large project to Tauri v2, which involves around 100 commands. While doing so, I have encountered a significant amount of boilerplate code that I need to maintain across multiple files. Specifically, for each command, I need to:

  • Define the command in the plugin's init functiopatn:
.invoke_handler(tauri::generate_handler![auth_get_default_user, auth_set_default_user])
  • Include the command in build.rs:
.plugin(
    "auth",
        tauri_build::InlinedPlugin::new().commands(&["auth_get_default_user", "auth_set_default_user"]),
)
  • Allow for usage of my commands in capabilities.json:
"auth:allow-auth-get-default-user",
"auth:allow-auth-set-default-user"

This process is not only repetitive but also makes it challenging to maintain and scale the project.

Describe the solution you'd like

Anything that reduces boilerplate, for example:

  • New macro that works like tauri::generate_handler!, but also generates all permissions
  • Allowing for all plugin's commands (for example plugin:allow-all or plugin:allow-*)

Alternatives considered

No response

Additional context

I initially discussed this problem on Discord

Current "sub" problems:

  • There is no builder.plugins
  • InlinedPlugin requires &'static [&'static str] which requires using a lot of Box::leak

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions