Skip to content

Commit 764e8f7

Browse files
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 <[email protected]> * [skip ci] format --------- Co-authored-by: Tony <[email protected]>
1 parent 85635a2 commit 764e8f7

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.changes/autostart-feature.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
autostart: minor
3+
autostart-js: minor
4+
---
5+
6+
Added a new builder method app_name() to allow customizing the application name in the autostart entry.

plugins/autostart/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ First you need to register the core plugin with Tauri:
5959
```rust
6060
fn main() {
6161
tauri::Builder::default()
62-
.plugin(tauri_plugin_autostart::Builder::new().args((["--flag1", "--flag2"])).build()))
62+
.plugin(tauri_plugin_autostart::Builder::new()
63+
.args(["--flag1", "--flag2"])
64+
.app_name("My Custom Name")
65+
.build())
6366
.run(tauri::generate_context!())
6467
.expect("error while running tauri application");
6568
}

plugins/autostart/src/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub struct Builder {
103103
#[cfg(target_os = "macos")]
104104
macos_launcher: MacosLauncher,
105105
args: Vec<String>,
106+
app_name: Option<String>,
106107
}
107108

108109
impl Builder {
@@ -154,12 +155,32 @@ impl Builder {
154155
self
155156
}
156157

158+
/// Sets the app name to be used for the auto start entry.
159+
///
160+
/// ## Examples
161+
///
162+
/// ```no_run
163+
/// Builder::new()
164+
/// .app_name("My Custom Name"))
165+
/// .build();
166+
/// ```
167+
pub fn app_name<S: Into<String>>(mut self, app_name: S) -> Self {
168+
self.app_name = Some(app_name.into());
169+
self
170+
}
171+
157172
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
158173
PluginBuilder::new("autostart")
159174
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
160175
.setup(move |app, _api| {
161176
let mut builder = AutoLaunchBuilder::new();
162-
builder.set_app_name(&app.package_info().name);
177+
178+
let app_name = self
179+
.app_name
180+
.as_ref()
181+
.unwrap_or_else(|| &app.package_info().name);
182+
builder.set_app_name(app_name);
183+
163184
builder.set_args(&self.args);
164185

165186
let current_exe = current_exe()?;

0 commit comments

Comments
 (0)