Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/autostart-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
autostart: minor
---

Added a new builder method app_name() to allow customizing the application name in the autostart entry.
6 changes: 5 additions & 1 deletion plugins/autostart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ First you need to register the core plugin with Tauri:
`src-tauri/src/lib.rs`

```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");
}
Expand Down
23 changes: 22 additions & 1 deletion plugins/autostart/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct Builder {
#[cfg(target_os = "macos")]
macos_launcher: MacosLauncher,
args: Vec<String>,
app_name: Option<String>,
}

impl Builder {
Expand Down Expand Up @@ -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<S: Into<String>>(mut self, app_name: S) -> Self {
self.app_name = Some(app_name.into());
self
}

pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
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()?;
Expand Down
Loading