From 682d224747be8e4e77262519f42101f3940e5bab Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Mon, 4 Sep 2023 10:36:41 -0300 Subject: [PATCH] fix(cli): prevent creating interface twice --- examples/api/src-tauri/Cargo.lock | 14 ++-- examples/api/src-tauri/src/lib.rs | 4 +- tooling/cli/src/build.rs | 23 +++--- tooling/cli/src/dev.rs | 19 ++--- tooling/cli/src/icon.rs | 3 +- tooling/cli/src/interface/mod.rs | 3 +- tooling/cli/src/interface/rust.rs | 28 +++++--- .../mobile/android/android_studio_script.rs | 12 +++- tooling/cli/src/mobile/android/build.rs | 37 ++++++---- tooling/cli/src/mobile/android/dev.rs | 70 ++++++++++++------- tooling/cli/src/mobile/android/open.rs | 12 +++- tooling/cli/src/mobile/init.rs | 10 +-- tooling/cli/src/mobile/ios/build.rs | 2 +- tooling/cli/src/mobile/ios/xcode_script.rs | 8 ++- tooling/cli/src/mobile/mod.rs | 14 ++-- 15 files changed, 160 insertions(+), 99 deletions(-) diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 01f36e50fd94..8096a8ed059f 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -3399,7 +3399,7 @@ checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" [[package]] name = "tauri" -version = "2.0.0-alpha.10" +version = "2.0.0-alpha.11" dependencies = [ "anyhow", "bytes", @@ -3449,7 +3449,7 @@ dependencies = [ [[package]] name = "tauri-build" -version = "2.0.0-alpha.6" +version = "2.0.0-alpha.8" dependencies = [ "anyhow", "cargo_toml", @@ -3469,7 +3469,7 @@ dependencies = [ [[package]] name = "tauri-codegen" -version = "2.0.0-alpha.6" +version = "2.0.0-alpha.7" dependencies = [ "base64", "brotli", @@ -3493,7 +3493,7 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "2.0.0-alpha.6" +version = "2.0.0-alpha.7" dependencies = [ "heck", "proc-macro2", @@ -3549,7 +3549,7 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "0.13.0-alpha.6" +version = "1.0.0-alpha.0" dependencies = [ "gtk", "http", @@ -3568,7 +3568,7 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "0.13.0-alpha.6" +version = "1.0.0-alpha.0" dependencies = [ "cocoa 0.24.1", "gtk", @@ -3587,7 +3587,7 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "2.0.0-alpha.6" +version = "2.0.0-alpha.7" dependencies = [ "aes-gcm", "brotli", diff --git a/examples/api/src-tauri/src/lib.rs b/examples/api/src-tauri/src/lib.rs index 8af633098e91..afeae29ddfb5 100644 --- a/examples/api/src-tauri/src/lib.rs +++ b/examples/api/src-tauri/src/lib.rs @@ -63,8 +63,8 @@ pub fn run_app) + Send + 'static>( #[cfg(desktop)] app.manage(PopupMenu( tauri::menu::MenuBuilder::new(app) - .check("Tauri is awesome!") - .text("Do something") + .check("awesome", "Tauri is awesome!") + .text("do", "Do something") .copy() .build()?, )); diff --git a/tooling/cli/src/build.rs b/tooling/cli/src/build.rs index 74d33d3bf3af..4709c352ce77 100644 --- a/tooling/cli/src/build.rs +++ b/tooling/cli/src/build.rs @@ -65,9 +65,15 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> { options.ci = options.ci || std::env::var("CI").is_ok(); let ci = options.ci; - let mut interface = setup(&mut options, false)?; - let config = get_config(options.config.as_deref())?; + + let mut interface = AppInterface::new( + config.lock().unwrap().as_ref().unwrap(), + options.target.clone(), + )?; + + setup(&interface, &mut options, false)?; + let config_guard = config.lock().unwrap(); let config_ = config_guard.as_ref().unwrap(); @@ -208,7 +214,7 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> { Ok(()) } -pub fn setup(options: &mut Options, mobile: bool) -> Result { +pub fn setup(interface: &AppInterface, options: &mut Options, mobile: bool) -> Result<()> { let (merge_config, merge_config_path) = resolve_merge_config(&options.config)?; options.config = merge_config; @@ -220,8 +226,6 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result { let config_guard = config.lock().unwrap(); let config_ = config_guard.as_ref().unwrap(); - let interface = AppInterface::new(config_, options.target.clone())?; - let bundle_identifier_source = match config_.find_bundle_identifier_overwriter() { Some(source) if source == MERGE_CONFIG_EXTENSION_NAME => merge_config_path.unwrap_or(source), Some(source) => source, @@ -252,12 +256,7 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result { } if let Some(before_build) = config_.build.before_build_command.clone() { - run_hook( - "beforeBuildCommand", - before_build, - &interface, - options.debug, - )?; + run_hook("beforeBuildCommand", before_build, interface, options.debug)?; } if let AppUrl::Url(WindowUrl::App(web_asset_path)) = &config_.build.dist_dir { @@ -300,7 +299,7 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result { .extend(config_.build.features.clone().unwrap_or_default()); interface.build_options(&mut options.args, &mut options.features, mobile); - Ok(interface) + Ok(()) } fn run_hook(name: &str, hook: HookCommand, interface: &AppInterface, debug: bool) -> Result<()> { diff --git a/tooling/cli/src/dev.rs b/tooling/cli/src/dev.rs index 02f6977859cb..4c0d178a5de6 100644 --- a/tooling/cli/src/dev.rs +++ b/tooling/cli/src/dev.rs @@ -84,7 +84,15 @@ pub fn command(options: Options) -> Result<()> { } fn command_internal(mut options: Options) -> Result<()> { - let mut interface = setup(&mut options, false)?; + let config = get_config(options.config.as_deref())?; + + let mut interface = AppInterface::new( + config.lock().unwrap().as_ref().unwrap(), + options.target.clone(), + )?; + + setup(&interface, &mut options, false)?; + let exit_on_panic = options.exit_on_panic; let no_watch = options.no_watch; interface.dev(options.into(), move |status, reason| { @@ -135,7 +143,7 @@ pub fn local_ip_address(force: bool) -> &'static IpAddr { }) } -pub fn setup(options: &mut Options, mobile: bool) -> Result { +pub fn setup(interface: &AppInterface, options: &mut Options, mobile: bool) -> Result<()> { let (merge_config, _merge_config_path) = resolve_merge_config(&options.config)?; options.config = merge_config; @@ -144,11 +152,6 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result { let tauri_path = tauri_dir(); set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?; - let interface = AppInterface::new( - config.lock().unwrap().as_ref().unwrap(), - options.target.clone(), - )?; - let mut dev_path = config .lock() .unwrap() @@ -384,7 +387,7 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result { } } - Ok(interface) + Ok(()) } pub fn wait_dev_process< diff --git a/tooling/cli/src/icon.rs b/tooling/cli/src/icon.rs index d176aa464c9b..c8aa24199ccf 100644 --- a/tooling/cli/src/icon.rs +++ b/tooling/cli/src/icon.rs @@ -4,6 +4,7 @@ use crate::{ helpers::{app_paths::tauri_dir, config::get as get_tauri_config}, + interface::{AppInterface, Interface}, Result, }; @@ -367,7 +368,7 @@ fn png(source: &DynamicImage, out_dir: &Path, ios_color: Rgba) -> Result<()> let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); crate::mobile::android::get_config( - &crate::mobile::get_app(tauri_config_), + &crate::mobile::get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?), tauri_config_, &Default::default(), ) diff --git a/tooling/cli/src/interface/mod.rs b/tooling/cli/src/interface/mod.rs index c5805cbac0a8..126746b467a0 100644 --- a/tooling/cli/src/interface/mod.rs +++ b/tooling/cli/src/interface/mod.rs @@ -8,6 +8,7 @@ use std::{ collections::HashMap, path::{Path, PathBuf}, process::ExitStatus, + sync::Arc, }; use crate::helpers::config::Config; @@ -87,7 +88,7 @@ pub trait Interface: Sized { type AppSettings: AppSettings; fn new(config: &Config, target: Option) -> crate::Result; - fn app_settings(&self) -> &Self::AppSettings; + fn app_settings(&self) -> Arc; fn env(&self) -> HashMap<&str, String>; fn build(&mut self, options: Options) -> crate::Result<()>; fn dev, ExitReason) + Send + Sync + 'static>( diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 239a2a48ed10..ecbe7fac98d7 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -96,7 +96,7 @@ pub struct Target { } pub struct Rust { - app_settings: RustAppSettings, + app_settings: Arc, config_features: Vec, product_name: Option, available_targets: Option>, @@ -138,15 +138,15 @@ impl Interface for Rust { let app_settings = RustAppSettings::new(config, manifest, target)?; Ok(Self { - app_settings, + app_settings: Arc::new(app_settings), config_features: config.build.features.clone().unwrap_or_default(), product_name: config.package.product_name.clone(), available_targets: None, }) } - fn app_settings(&self) -> &Self::AppSettings { - &self.app_settings + fn app_settings(&self) -> Arc { + self.app_settings.clone() } fn build(&mut self, options: Options) -> crate::Result<()> { @@ -360,6 +360,8 @@ fn shared_options( args.push("--bins".into()); let all_features = app_settings .manifest + .lock() + .unwrap() .all_enabled_features(if let Some(f) = features { f } else { &[] }); if !all_features.contains(&"tauri/rustls-tls".into()) { features @@ -392,7 +394,7 @@ fn dev_options( shared_options(mobile, args, features, app_settings); if !args.contains(&"--no-default-features".into()) { - let manifest_features = app_settings.manifest.features(); + let manifest_features = app_settings.manifest.lock().unwrap().features(); let enable_features: Vec = manifest_features .get("default") .cloned() @@ -514,7 +516,7 @@ impl Rust { match reload_config(config.as_deref()) { Ok(config) => { info!("Tauri configuration changed. Rewriting manifest..."); - self.app_settings.manifest = + *self.app_settings.manifest.lock().unwrap() = rewrite_manifest(config.lock().unwrap().as_ref().unwrap())? } Err(err) => { @@ -679,7 +681,7 @@ impl CargoSettings { } pub struct RustAppSettings { - manifest: Manifest, + manifest: Mutex, cargo_settings: CargoSettings, cargo_package_settings: CargoPackageSettings, package_settings: PackageSettings, @@ -697,7 +699,11 @@ impl AppSettings for RustAppSettings { config: &Config, features: &[String], ) -> crate::Result { - tauri_config_to_bundle_settings(&self.manifest, features, config.tauri.bundle.clone()) + tauri_config_to_bundle_settings( + &self.manifest.lock().unwrap(), + features, + config.tauri.bundle.clone(), + ) } fn app_binary_path(&self, options: &Options) -> crate::Result { @@ -831,6 +837,8 @@ impl AppSettings for RustAppSettings { fn app_name(&self) -> Option { self .manifest + .lock() + .unwrap() .inner .as_table() .get("package") @@ -843,6 +851,8 @@ impl AppSettings for RustAppSettings { fn lib_name(&self) -> Option { self .manifest + .lock() + .unwrap() .inner .as_table() .get("lib") @@ -956,7 +966,7 @@ impl RustAppSettings { }); Ok(Self { - manifest, + manifest: Mutex::new(manifest), cargo_settings, cargo_package_settings, package_settings, diff --git a/tooling/cli/src/mobile/android/android_studio_script.rs b/tooling/cli/src/mobile/android/android_studio_script.rs index f6e300a46a5d..d14564082c67 100644 --- a/tooling/cli/src/mobile/android/android_studio_script.rs +++ b/tooling/cli/src/mobile/android/android_studio_script.rs @@ -3,7 +3,11 @@ // SPDX-License-Identifier: MIT use super::{detect_target_ok, ensure_init, env, get_app, get_config, read_options, MobileTarget}; -use crate::{helpers::config::get as get_tauri_config, Result}; +use crate::{ + helpers::config::get as get_tauri_config, + interface::{AppInterface, Interface}, + Result, +}; use clap::{ArgAction, Parser}; use tauri_mobile::{ @@ -42,7 +46,11 @@ pub fn command(options: Options) -> Result<()> { let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); let cli_options = read_options(&tauri_config_.tauri.bundle.identifier); - let (config, metadata) = get_config(&get_app(tauri_config_), tauri_config_, &cli_options); + let (config, metadata) = get_config( + &get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?), + tauri_config_, + &cli_options, + ); (config, metadata, cli_options) }; ensure_init(config.project_dir(), MobileTarget::Android)?; diff --git a/tooling/cli/src/mobile/android/build.rs b/tooling/cli/src/mobile/android/build.rs index 762ee16b8fe9..9a8ed2c73b9b 100644 --- a/tooling/cli/src/mobile/android/build.rs +++ b/tooling/cli/src/mobile/android/build.rs @@ -13,7 +13,7 @@ use crate::{ config::{get as get_tauri_config, ConfigHandle}, flock, resolve_merge_config, }, - interface::{AppSettings, Interface, Options as InterfaceOptions}, + interface::{AppInterface, AppSettings, Interface, Options as InterfaceOptions}, mobile::{write_options, CliOptions}, Result, }; @@ -84,13 +84,25 @@ pub fn command(mut options: Options, noise_level: NoiseLevel) -> Result<()> { let (merge_config, _merge_config_path) = resolve_merge_config(&options.config)?; options.config = merge_config; + let mut build_options: BuildOptions = options.clone().into(); + build_options.target = Some( + Target::all() + .get(Target::DEFAULT_KEY) + .unwrap() + .triple + .into(), + ); + let tauri_config = get_tauri_config(options.config.as_deref())?; - let (app, config, metadata) = { + let (interface, app, config, metadata) = { let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); - let app = get_app(tauri_config_); + + let interface = AppInterface::new(tauri_config_, build_options.target.clone())?; + + let app = get_app(tauri_config_, &interface); let (config, metadata) = get_config(&app, tauri_config_, &Default::default()); - (app, config, metadata) + (interface, app, config, metadata) }; set_var("WRY_RUSTWEBVIEWCLIENT_CLASS_EXTENSION", ""); @@ -126,7 +138,9 @@ pub fn command(mut options: Options, noise_level: NoiseLevel) -> Result<()> { let open = options.open; run_build( + interface, options, + build_options, tauri_config, profile, &config, @@ -141,8 +155,11 @@ pub fn command(mut options: Options, noise_level: NoiseLevel) -> Result<()> { Ok(()) } +#[allow(clippy::too_many_arguments)] fn run_build( + interface: AppInterface, mut options: Options, + mut build_options: BuildOptions, tauri_config: ConfigHandle, profile: Profile, config: &AndroidConfig, @@ -155,15 +172,7 @@ fn run_build( options.aab = true; } - let mut build_options: BuildOptions = options.clone().into(); - build_options.target = Some( - Target::all() - .get(Target::DEFAULT_KEY) - .unwrap() - .triple - .into(), - ); - let interface = crate::build::setup(&mut build_options, true)?; + crate::build::setup(&interface, &mut build_options, true)?; let interface_options = InterfaceOptions { debug: build_options.debug, @@ -194,7 +203,7 @@ fn run_build( cli_options, )?; - options + build_options .features .get_or_insert(Vec::new()) .push("custom-protocol".into()); diff --git a/tooling/cli/src/mobile/android/dev.rs b/tooling/cli/src/mobile/android/dev.rs index 058d8da7e80a..e34f1394035b 100644 --- a/tooling/cli/src/mobile/android/dev.rs +++ b/tooling/cli/src/mobile/android/dev.rs @@ -13,7 +13,7 @@ use crate::{ config::{get as get_tauri_config, ConfigHandle}, flock, resolve_merge_config, }, - interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions}, + interface::{AppInterface, AppSettings, Interface, MobileOptions, Options as InterfaceOptions}, mobile::{write_options, CliOptions, DevChild, DevProcess}, Result, }; @@ -112,12 +112,35 @@ fn run_command(mut options: Options, noise_level: NoiseLevel) -> Result<()> { let tauri_config = get_tauri_config(options.config.as_deref())?; - let (app, config, metadata) = { + let env = env()?; + let device = if options.open { + None + } else { + match device_prompt(&env, options.device.as_deref()) { + Ok(d) => Some(d), + Err(e) => { + log::error!("{e}"); + None + } + } + }; + + let mut dev_options: DevOptions = options.clone().into(); + let target_triple = device + .as_ref() + .map(|d| d.target().triple.to_string()) + .unwrap_or_else(|| Target::all().values().next().unwrap().triple.into()); + dev_options.target = Some(target_triple.clone()); + + let (interface, app, config, metadata) = { let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); - let app = get_app(tauri_config_); + + let interface = AppInterface::new(tauri_config_, dev_options.target.clone())?; + + let app = get_app(tauri_config_, &interface); let (config, metadata) = get_config(&app, tauri_config_, &Default::default()); - (app, config, metadata) + (interface, app, config, metadata) }; set_var( @@ -130,38 +153,36 @@ fn run_command(mut options: Options, noise_level: NoiseLevel) -> Result<()> { set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?; ensure_init(config.project_dir(), MobileTarget::Android)?; - run_dev(options, tauri_config, &app, &config, &metadata, noise_level) + run_dev( + interface, + options, + dev_options, + tauri_config, + device, + env, + &app, + &config, + &metadata, + noise_level, + ) } +#[allow(clippy::too_many_arguments)] fn run_dev( + mut interface: AppInterface, mut options: Options, + mut dev_options: DevOptions, tauri_config: ConfigHandle, + device: Option, + mut env: Env, app: &App, config: &AndroidConfig, metadata: &AndroidMetadata, noise_level: NoiseLevel, ) -> Result<()> { setup_dev_config(&mut options.config, options.force_ip_prompt)?; - let mut env = env()?; - let device = if options.open { - None - } else { - match device_prompt(&env, options.device.as_deref()) { - Ok(d) => Some(d), - Err(e) => { - log::error!("{e}"); - None - } - } - }; - let mut dev_options: DevOptions = options.clone().into(); - let target_triple = device - .as_ref() - .map(|d| d.target().triple.to_string()) - .unwrap_or_else(|| Target::all().values().next().unwrap().triple.into()); - dev_options.target = Some(target_triple.clone()); - let mut interface = crate::dev::setup(&mut dev_options, true)?; + crate::dev::setup(&interface, &mut dev_options, true)?; let interface_options = InterfaceOptions { debug: !dev_options.release_mode, @@ -177,6 +198,7 @@ fn run_dev( configure_cargo(app, Some((&mut env, config)))?; // run an initial build to initialize plugins + let target_triple = dev_options.target.as_ref().unwrap(); let target = Target::all() .values() .find(|t| t.triple == target_triple) diff --git a/tooling/cli/src/mobile/android/open.rs b/tooling/cli/src/mobile/android/open.rs index a058cbdddc7c..2f06b79444ae 100644 --- a/tooling/cli/src/mobile/android/open.rs +++ b/tooling/cli/src/mobile/android/open.rs @@ -3,7 +3,11 @@ // SPDX-License-Identifier: MIT use super::{ensure_init, env, get_app, get_config, inject_assets, MobileTarget}; -use crate::{helpers::config::get as get_tauri_config, Result}; +use crate::{ + helpers::config::get as get_tauri_config, + interface::{AppInterface, Interface}, + Result, +}; use tauri_mobile::os; @@ -13,7 +17,11 @@ pub fn command() -> Result<()> { let (config, _metadata) = { let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); - get_config(&get_app(tauri_config_), tauri_config_, &Default::default()) + get_config( + &get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?), + tauri_config_, + &Default::default(), + ) }; ensure_init(config.project_dir(), MobileTarget::Android)?; inject_assets(&config, tauri_config.lock().unwrap().as_ref().unwrap())?; diff --git a/tooling/cli/src/mobile/init.rs b/tooling/cli/src/mobile/init.rs index 6d903d6c6478..d04f5796108f 100644 --- a/tooling/cli/src/mobile/init.rs +++ b/tooling/cli/src/mobile/init.rs @@ -3,8 +3,11 @@ // SPDX-License-Identifier: MIT use super::{get_app, Target}; -use crate::helpers::{config::get as get_tauri_config, template::JsonMap}; -use crate::Result; +use crate::{ + helpers::{config::get as get_tauri_config, template::JsonMap}, + interface::{AppInterface, Interface}, + Result, +}; use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError}; use tauri_mobile::{ android::{ @@ -93,7 +96,7 @@ pub fn exec( let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); - let app = get_app(tauri_config_); + let app = get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?); let (handlebars, mut map) = handlebars(&app); @@ -163,7 +166,6 @@ pub fn exec( // Generate Android Studio project Target::Android => match AndroidEnv::new() { Ok(_env) => { - let app = get_app(tauri_config_); let (config, metadata) = super::android::get_config(&app, tauri_config_, &Default::default()); map.insert("android", &config); diff --git a/tooling/cli/src/mobile/ios/build.rs b/tooling/cli/src/mobile/ios/build.rs index 5ee74fbfe9ed..05298f9171c9 100644 --- a/tooling/cli/src/mobile/ios/build.rs +++ b/tooling/cli/src/mobile/ios/build.rs @@ -13,7 +13,7 @@ use crate::{ config::{get as get_tauri_config, ConfigHandle}, flock, resolve_merge_config, }, - interface::{AppSettings, Interface, Options as InterfaceOptions}, + interface::{AppInterface, AppSettings, Interface, Options as InterfaceOptions}, mobile::{write_options, CliOptions}, Result, }; diff --git a/tooling/cli/src/mobile/ios/xcode_script.rs b/tooling/cli/src/mobile/ios/xcode_script.rs index d9e5ef1390bf..09807f5feedf 100644 --- a/tooling/cli/src/mobile/ios/xcode_script.rs +++ b/tooling/cli/src/mobile/ios/xcode_script.rs @@ -5,7 +5,7 @@ use super::{env, get_app, get_config, read_options}; use crate::{ helpers::config::get as get_tauri_config, - interface::{AppInterface, AppSettings, Interface, Options as InterfaceOptions}, + interface::{AppInterface, AppSettings, Interface, Interface, Options as InterfaceOptions}, Result, }; @@ -74,7 +74,11 @@ pub fn command(options: Options) -> Result<()> { let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); let cli_options = read_options(&tauri_config_.tauri.bundle.identifier); - let (config, metadata) = get_config(&get_app(tauri_config_), tauri_config_, &cli_options); + let (config, metadata) = get_config( + &get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?), + tauri_config_, + &cli_options, + ); (config, metadata, cli_options) }; diff --git a/tooling/cli/src/mobile/mod.rs b/tooling/cli/src/mobile/mod.rs index 94a7824179ac..83a6b927a57e 100644 --- a/tooling/cli/src/mobile/mod.rs +++ b/tooling/cli/src/mobile/mod.rs @@ -262,7 +262,7 @@ fn read_options(identifier: &str) -> CliOptions { options } -pub fn get_app(config: &TauriConfig) -> App { +pub fn get_app(config: &TauriConfig, interface: &AppInterface) -> App { let mut s = config.tauri.bundle.identifier.rsplit('.'); let app_name = s.next().unwrap_or("app").to_string(); let mut domain = String::new(); @@ -282,13 +282,6 @@ pub fn get_app(config: &TauriConfig) -> App { domain.pop(); } - let interface = AppInterface::new( - config, - // the target triple is not relevant - Some("".into()), - ) - .expect("failed to load interface"); - let app_name = interface.app_settings().app_name().unwrap_or(app_name); let lib_name = interface .app_settings() @@ -303,11 +296,12 @@ pub fn get_app(config: &TauriConfig) -> App { asset_dir: None, template_pack: None, }; + + let app_settings = interface.app_settings(); App::from_raw(tauri_dir(), raw) .unwrap() .with_target_dir_resolver(move |target, profile| { - let bin_path = interface - .app_settings() + let bin_path = app_settings .app_binary_path(&InterfaceOptions { debug: matches!(profile, Profile::Debug), target: Some(target.into()),