Skip to content

Change SetupHook from Box<dyn Fn(...)...> to Box<dyn FnOnce(...)...> #3061

@itsjunetime

Description

@itsjunetime

Is your feature request related to a problem? Please describe.
The SetupHook type utilizes Fn() instead of FnOnce(), even though it is only run once. This prevents users from moving values into the setup closure on tauri::Builder, and makes it so that users have to utilize extra workarounds to achieve the result that they're looking for.

Describe the solution you'd like
Change the SetupHook type to Box<dyn FnOnce(&mut App<R>) -> Result<(), Box<dyn std::error::Error + Send>> + Send>, and change the F generic parameter in tauri::Builder::setup to FnOnce(&mut App<R>) -> Result<(), Box<dyn std::error::Error + Send>> + Send + 'static. As far as I can tell (and have tested), this should be totally possible, since setup is only run once, here.

Describe alternatives you've considered
As far as I know, there aren't really any alternatives within tauri to produce the same result without this proposed solution. If there are any that I'm not thinking of, I'd love to hear and consider them.

Additional context
Nothing that I know of.

If I am incorrect in any assumptions here or not clear enough in any part of it, please let me know :) I would also be happy to submit a PR with the needed changes if this change is desired.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions