From 764e8f7719247da515243d9c9cafa6d087d21769 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Tue, 20 May 2025 23:51:36 +0800 Subject: [PATCH] feat(autostart): add app name configuration for auto start entry (#2707) * feat(autostart): add prefered name configuration for auto start entry - Add PreferedName enum to support different naming strategies - Implement Default trait for PreferedName with PackageInfoName as default - Add prefered_name builder method with documentation and examples - Integrate prefered name into auto start configuration This change allows users to customize the name of their application in the auto start entry using various naming strategies like package info name, crate name, config identifier, or custom name. * refactor(autostart): rename prefered_name to app_name and update related logic - Change prefered_name to app_name in the Builder struct and methods - Update PreferedName enum to include new variants and set AppName as default - Modify documentation to reflect the new app_name usage for auto start entry This refactor improves clarity in naming conventions and enhances the configuration options for auto start entries. * refactor(autostart): update app_name handling in README and lib.rs - Change app_name usage in README to a custom string - Simplify app_name handling in lib.rs by removing PreferedName enum - Update Builder struct to accept app_name as an optional string This refactor enhances the clarity and usability of the auto start configuration. * feat(autostart): add app_name builder method for custom application naming - Introduced a new builder method app_name() to customize the application name in the autostart entry. - Updated app_name handling in the Builder struct to accept a generic string type. This enhancement allows for greater flexibility in defining application names for autostart configurations. * Update .changes/autostart-feature.md Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * [skip ci] format --------- Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> --- .changes/autostart-feature.md | 6 ++++++ plugins/autostart/README.md | 5 ++++- plugins/autostart/src/lib.rs | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .changes/autostart-feature.md 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()?;