diff --git a/.changes/autostart-feature.md b/.changes/autostart-feature.md new file mode 100644 index 00000000..1d5d956e --- /dev/null +++ b/.changes/autostart-feature.md @@ -0,0 +1,6 @@ +--- +autostart: minor +autostart-js: minor +--- + +Added a new builder method app_name() to allow customizing the application name in the autostart entry. \ No newline at end of file diff --git a/plugins/autostart/README.md b/plugins/autostart/README.md index bae2802a..cef284d6 100644 --- a/plugins/autostart/README.md +++ b/plugins/autostart/README.md @@ -59,7 +59,10 @@ First you need to register the core plugin with Tauri: ```rust fn main() { tauri::Builder::default() - .plugin(tauri_plugin_autostart::Builder::new().args((["--flag1", "--flag2"])).build())) + .plugin(tauri_plugin_autostart::Builder::new() + .args(["--flag1", "--flag2"]) + .app_name("My Custom Name") + .build()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/plugins/autostart/src/lib.rs b/plugins/autostart/src/lib.rs index 83cac89c..4b4c7c23 100644 --- a/plugins/autostart/src/lib.rs +++ b/plugins/autostart/src/lib.rs @@ -103,6 +103,7 @@ pub struct Builder { #[cfg(target_os = "macos")] macos_launcher: MacosLauncher, args: Vec, + app_name: Option, } impl Builder { @@ -154,12 +155,32 @@ impl Builder { self } + /// Sets the app name to be used for the auto start entry. + /// + /// ## Examples + /// + /// ```no_run + /// Builder::new() + /// .app_name("My Custom Name")) + /// .build(); + /// ``` + pub fn app_name>(mut self, app_name: S) -> Self { + self.app_name = Some(app_name.into()); + self + } + pub fn build(self) -> TauriPlugin { PluginBuilder::new("autostart") .invoke_handler(tauri::generate_handler![enable, disable, is_enabled]) .setup(move |app, _api| { let mut builder = AutoLaunchBuilder::new(); - builder.set_app_name(&app.package_info().name); + + let app_name = self + .app_name + .as_ref() + .unwrap_or_else(|| &app.package_info().name); + builder.set_app_name(app_name); + builder.set_args(&self.args); let current_exe = current_exe()?;