diff --git a/plugins/autostart/README.md b/plugins/autostart/README.md index 4d9185e5..bdd556cd 100644 --- a/plugins/autostart/README.md +++ b/plugins/autostart/README.md @@ -62,7 +62,7 @@ fn main() { tauri::Builder::default() .plugin(tauri_plugin_autostart::Builder::new() .args(["--flag1", "--flag2"]) - .app_name(tauri_plugin_autostart::PreferedName::AppName) + .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 f1a59f3c..3b73c1be 100644 --- a/plugins/autostart/src/lib.rs +++ b/plugins/autostart/src/lib.rs @@ -15,7 +15,7 @@ use serde::{ser::Serializer, Serialize}; use tauri::{ command, plugin::{Builder as PluginBuilder, TauriPlugin}, - AppHandle, Manager, Runtime, State, + Manager, Runtime, State, }; use std::env::current_exe; @@ -29,16 +29,6 @@ pub enum MacosLauncher { AppleScript, } -#[derive(Default)] -pub enum PreferedName { - #[default] - AppName, - CrateName, - Identifier, - ProductName, - Custom(String), -} - #[derive(Debug, thiserror::Error)] pub enum Error { #[error(transparent)] @@ -56,28 +46,6 @@ impl Serialize for Error { } } -impl PreferedName { - pub fn get_value(&self, app: &AppHandle) -> String { - match self { - PreferedName::AppName => app.package_info().name.to_string(), - PreferedName::CrateName => app.package_info().crate_name.to_string(), - PreferedName::Identifier => app.config().identifier.to_string(), - PreferedName::ProductName => app - .config() - .product_name - .clone() - .unwrap_or("TauriAPP".to_string()), - PreferedName::Custom(s) => s.clone(), - } - } -} - -impl> From for PreferedName { - fn from(name: S) -> Self { - PreferedName::Custom(name.into()) - } -} - pub struct AutoLaunchManager(AutoLaunch); impl AutoLaunchManager { @@ -135,7 +103,7 @@ pub struct Builder { #[cfg(target_os = "macos")] macos_launcher: MacosLauncher, args: Vec, - app_name: PreferedName, + app_name: Option, } impl Builder { @@ -193,17 +161,11 @@ impl Builder { /// /// ```no_run /// Builder::new() - /// .app_name(PreferedName::AppName) - /// .build(); - /// ``` - /// - /// ```no_run - /// Builder::new() /// .app_name("My Custom Name")) /// .build(); /// ``` - pub fn app_name(mut self, app_name: impl Into) -> Self { - self.app_name = app_name.into(); + pub fn app_name(mut self, app_name: &str) -> Self { + self.app_name = Some(app_name.to_string()); self } @@ -213,8 +175,8 @@ impl Builder { .setup(move |app, _api| { let mut builder = AutoLaunchBuilder::new(); - let prefered_name = self.app_name.get_value(app); - builder.set_app_name(&prefered_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);