@@ -393,27 +393,40 @@ impl Default for TauriConfig {
393393 }
394394}
395395
396+ /// The `dev_path` and `dist_dir` options.
397+ #[ derive( PartialEq , Debug , Clone , Deserialize ) ]
398+ #[ serde( untagged) ]
399+ #[ non_exhaustive]
400+ pub enum AppUrl {
401+ /// A url or file path.
402+ Url ( WindowUrl ) ,
403+ /// An array of files.
404+ Files ( Vec < PathBuf > ) ,
405+ }
406+
396407/// The Build configuration object.
397408#[ derive( PartialEq , Deserialize , Debug ) ]
398409#[ serde( rename_all = "camelCase" ) ]
399410pub struct BuildConfig {
400411 /// the devPath config.
401412 #[ serde( default = "default_dev_path" ) ]
402- pub dev_path : WindowUrl ,
413+ pub dev_path : AppUrl ,
403414 /// the dist config.
404415 #[ serde( default = "default_dist_path" ) ]
405- pub dist_dir : WindowUrl ,
416+ pub dist_dir : AppUrl ,
406417 /// Whether we should inject the Tauri API on `window.__TAURI__` or not.
407418 #[ serde( default ) ]
408419 pub with_global_tauri : bool ,
409420}
410421
411- fn default_dev_path ( ) -> WindowUrl {
412- WindowUrl :: External ( Url :: parse ( "http://localhost:8080" ) . unwrap ( ) )
422+ fn default_dev_path ( ) -> AppUrl {
423+ AppUrl :: Url ( WindowUrl :: External (
424+ Url :: parse ( "http://localhost:8080" ) . unwrap ( ) ,
425+ ) )
413426}
414427
415- fn default_dist_path ( ) -> WindowUrl {
416- WindowUrl :: App ( "../dist" . into ( ) )
428+ fn default_dist_path ( ) -> AppUrl {
429+ AppUrl :: Url ( WindowUrl :: App ( "../dist" . into ( ) ) )
417430}
418431
419432impl Default for BuildConfig {
@@ -465,7 +478,7 @@ pub struct PluginConfig(pub HashMap<String, JsonValue>);
465478/// application using tauri while only parsing it once (in the build script).
466479#[ cfg( feature = "build" ) ]
467480mod build {
468- use std:: convert:: identity;
481+ use std:: { convert:: identity, path :: Path } ;
469482
470483 use proc_macro2:: TokenStream ;
471484 use quote:: { quote, ToTokens , TokenStreamExt } ;
@@ -511,6 +524,15 @@ mod build {
511524 quote ! { vec![ #( #items) , * ] }
512525 }
513526
527+ /// Create a `PathBuf` constructor `TokenStream`.
528+ ///
529+ /// e.g. `"Hello World" -> String::from("Hello World").
530+ /// This takes a `&String` to reduce casting all the `&String` -> `&str` manually.
531+ fn path_buf_lit ( s : impl AsRef < Path > ) -> TokenStream {
532+ let s = s. as_ref ( ) . to_string_lossy ( ) . into_owned ( ) ;
533+ quote ! { :: std:: path:: PathBuf :: from( #s) }
534+ }
535+
514536 /// Create a map constructor, mapping keys and values with other `TokenStream`s.
515537 ///
516538 /// This function is pretty generic because the types of keys AND values get transformed.
@@ -612,8 +634,8 @@ mod build {
612634
613635 tokens. append_all ( match self {
614636 Self :: App ( path) => {
615- let path = path . to_string_lossy ( ) . to_string ( ) ;
616- quote ! { #prefix:: App ( :: std :: path :: PathBuf :: from ( #path) ) }
637+ let path = path_buf_lit ( & path ) ;
638+ quote ! { #prefix:: App ( #path) }
617639 }
618640 Self :: External ( url) => {
619641 let url = url. as_str ( ) ;
@@ -779,6 +801,22 @@ mod build {
779801 }
780802 }
781803
804+ impl ToTokens for AppUrl {
805+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
806+ let prefix = quote ! { :: tauri:: api:: config:: AppUrl } ;
807+
808+ tokens. append_all ( match self {
809+ Self :: Url ( url) => {
810+ quote ! { #prefix:: Url ( #url) }
811+ }
812+ Self :: Files ( files) => {
813+ let files = vec_lit ( files, path_buf_lit) ;
814+ quote ! { #prefix:: Files ( #files) }
815+ }
816+ } )
817+ }
818+ }
819+
782820 impl ToTokens for BuildConfig {
783821 fn to_tokens ( & self , tokens : & mut TokenStream ) {
784822 let dev_path = & self . dev_path ;
@@ -810,8 +848,7 @@ mod build {
810848
811849 impl ToTokens for SystemTrayConfig {
812850 fn to_tokens ( & self , tokens : & mut TokenStream ) {
813- let icon_path = self . icon_path . to_string_lossy ( ) . to_string ( ) ;
814- let icon_path = quote ! { :: std:: path:: PathBuf :: from( #icon_path) } ;
851+ let icon_path = path_buf_lit ( & self . icon_path ) ;
815852 literal_struct ! ( tokens, SystemTrayConfig , icon_path) ;
816853 }
817854 }
@@ -936,8 +973,10 @@ mod test {
936973
937974 // create a build config
938975 let build = BuildConfig {
939- dev_path : WindowUrl :: External ( Url :: parse ( "http://localhost:8080" ) . unwrap ( ) ) ,
940- dist_dir : WindowUrl :: App ( "../dist" . into ( ) ) ,
976+ dev_path : AppUrl :: Url ( WindowUrl :: External (
977+ Url :: parse ( "http://localhost:8080" ) . unwrap ( ) ,
978+ ) ) ,
979+ dist_dir : AppUrl :: Url ( WindowUrl :: App ( "../dist" . into ( ) ) ) ,
941980 with_global_tauri : false ,
942981 } ;
943982
@@ -948,7 +987,9 @@ mod test {
948987 assert_eq ! ( d_updater, tauri. updater) ;
949988 assert_eq ! (
950989 d_path,
951- WindowUrl :: External ( Url :: parse( "http://localhost:8080" ) . unwrap( ) )
990+ AppUrl :: Url ( WindowUrl :: External (
991+ Url :: parse( "http://localhost:8080" ) . unwrap( )
992+ ) )
952993 ) ;
953994 assert_eq ! ( d_title, tauri. windows[ 0 ] . title) ;
954995 assert_eq ! ( d_windows, tauri. windows) ;
0 commit comments