Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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
20 changes: 19 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,29 @@ 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: &str) -> Self {
self.app_name = Some(app_name.to_string());
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.unwrap_or(app.package_info().name.clone());
builder.set_app_name(&app_name);

builder.set_args(&self.args);

let current_exe = current_exe()?;
Expand Down
Loading