@@ -6,11 +6,12 @@ use crate::{
66 helpers:: {
77 app_paths:: { app_dir, tauri_dir} ,
88 command_env,
9- config:: { get as get_config, reload as reload_config, BeforeDevCommand , FrontendDist } ,
10- resolve_merge_config,
9+ config:: {
10+ get as get_config, reload as reload_config, BeforeDevCommand , ConfigHandle , FrontendDist ,
11+ } ,
1112 } ,
1213 interface:: { AppInterface , DevProcess , ExitReason , Interface } ,
13- CommandExt , Result ,
14+ CommandExt , ConfigValue , Result ,
1415} ;
1516
1617use anyhow:: { bail, Context } ;
@@ -59,7 +60,7 @@ pub struct Options {
5960 pub exit_on_panic : bool ,
6061 /// JSON string or path to JSON file to merge with tauri.conf.json
6162 #[ clap( short, long) ]
62- pub config : Option < String > ,
63+ pub config : Option < ConfigValue > ,
6364 /// Run the code in release mode
6465 #[ clap( long = "release" ) ]
6566 pub release_mode : bool ,
@@ -100,14 +101,14 @@ fn command_internal(mut options: Options) -> Result<()> {
100101 . map ( Target :: from_triple)
101102 . unwrap_or_else ( Target :: current) ;
102103
103- let config = get_config ( target, options. config . as_deref ( ) ) ?;
104+ let config = get_config ( target, options. config . as_ref ( ) . map ( |c| & c . 0 ) ) ?;
104105
105106 let mut interface = AppInterface :: new (
106107 config. lock ( ) . unwrap ( ) . as_ref ( ) . unwrap ( ) ,
107108 options. target . clone ( ) ,
108109 ) ?;
109110
110- setup ( target , & interface, & mut options, false ) ?;
111+ setup ( & interface, & mut options, config , false ) ?;
111112
112113 let exit_on_panic = options. exit_on_panic ;
113114 let no_watch = options. no_watch ;
@@ -160,16 +161,11 @@ pub fn local_ip_address(force: bool) -> &'static IpAddr {
160161}
161162
162163pub fn setup (
163- target : Target ,
164164 interface : & AppInterface ,
165165 options : & mut Options ,
166+ config : ConfigHandle ,
166167 mobile : bool ,
167168) -> Result < ( ) > {
168- let ( merge_config, _merge_config_path) = resolve_merge_config ( & options. config ) ?;
169- options. config = merge_config;
170-
171- let config = get_config ( target, options. config . as_deref ( ) ) ?;
172-
173169 let tauri_path = tauri_dir ( ) ;
174170 set_current_dir ( tauri_path) . with_context ( || "failed to change current working directory" ) ?;
175171
@@ -344,15 +340,26 @@ pub fn setup(
344340 let server_url = format ! ( "http://{server_url}" ) ;
345341 dev_url = Some ( server_url. parse ( ) . unwrap ( ) ) ;
346342
347- if let Some ( c) = & options. config {
348- let mut c: tauri_utils:: config:: Config = serde_json:: from_str ( c) ?;
349- c. build . dev_url = dev_url. clone ( ) ;
350- options. config = Some ( serde_json:: to_string ( & c) . unwrap ( ) ) ;
343+ if let Some ( c) = & mut options. config {
344+ if let Some ( build) = c
345+ . 0
346+ . as_object_mut ( )
347+ . and_then ( |root| root. get_mut ( "build" ) )
348+ . and_then ( |build| build. as_object_mut ( ) )
349+ {
350+ build. insert ( "devUrl" . into ( ) , server_url. into ( ) ) ;
351+ }
351352 } else {
352- options. config = Some ( format ! ( r#"{{ "build": {{ "devUrl": "{server_url}" }} }}"# ) )
353+ options
354+ . config
355+ . replace ( crate :: ConfigValue ( serde_json:: json!( {
356+ "build" : {
357+ "devUrl" : server_url
358+ }
359+ } ) ) ) ;
353360 }
354361
355- reload_config ( options. config . as_deref ( ) ) ?;
362+ reload_config ( options. config . as_ref ( ) . map ( |c| & c . 0 ) ) ?;
356363 }
357364 }
358365 }
0 commit comments