@ -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 < R : Runtime > ( & self , app : & AppHandle < R > ) -> 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 < S : Into < String > > From < S > 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 < String > ,
app_name : PreferedName ,
app_name : Option < String > ,
}
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 < PreferedName > ) -> 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 ap p_name = self . app_name . unwrap_or( app . package_info ( ) . name . clone ( ) ) ;
builder . set_app_name ( & ap p_name) ;
builder . set_args ( & self . args ) ;