mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-10 23:45:46 +03:00
fix(cli): builtin dev server should also be forwarded for Android (#10600)
This commit is contained in:
parent
f35bcda289
commit
f4cd68f040
6
.changes/fix-cli-dev-server-android.md
Normal file
6
.changes/fix-cli-dev-server-android.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-cli": patch:bug
|
||||
"@tauri-apps/cli": patch:bug
|
||||
---
|
||||
|
||||
Fixes `android dev` not working when using the builtin dev server.
|
@ -215,3 +215,20 @@ pub fn reload(merge_config: Option<&serde_json::Value>) -> crate::Result<ConfigH
|
||||
Err(anyhow::anyhow!("config not loaded"))
|
||||
}
|
||||
}
|
||||
|
||||
/// merges the loaded config with the given value
|
||||
pub fn merge_with(merge_config: &serde_json::Value) -> crate::Result<ConfigHandle> {
|
||||
let handle = config_handle();
|
||||
if let Some(config_metadata) = &mut *handle.lock().unwrap() {
|
||||
let merge_config_str = serde_json::to_string(merge_config).unwrap();
|
||||
set_var("TAURI_CONFIG", merge_config_str);
|
||||
|
||||
let mut value = serde_json::to_value(config_metadata.inner.clone())?;
|
||||
merge(&mut value, merge_config);
|
||||
config_metadata.inner = serde_json::from_value(value)?;
|
||||
|
||||
Ok(handle.clone())
|
||||
} else {
|
||||
Err(anyhow::anyhow!("config not loaded"))
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ use clap::{ArgAction, CommandFactory, FromArgMatches, Parser, Subcommand, ValueE
|
||||
use env_logger::fmt::style::{AnsiColor, Style};
|
||||
use env_logger::Builder;
|
||||
use log::Level;
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::{BufReader, Write};
|
||||
use std::process::{exit, Command, ExitStatus, Output, Stdio};
|
||||
use std::{
|
||||
@ -48,7 +48,7 @@ use std::{
|
||||
};
|
||||
|
||||
/// Tauri configuration argument option.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ConfigValue(pub(crate) serde_json::Value);
|
||||
|
||||
impl FromStr for ConfigValue {
|
||||
|
@ -59,6 +59,7 @@ pub fn command(options: Options) -> Result<()> {
|
||||
);
|
||||
(config, metadata, cli_options)
|
||||
};
|
||||
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
@ -66,6 +67,10 @@ pub fn command(options: Options) -> Result<()> {
|
||||
MobileTarget::Android,
|
||||
)?;
|
||||
|
||||
if let Some(config) = &cli_options.config {
|
||||
crate::helpers::config::merge_with(&config.0)?;
|
||||
}
|
||||
|
||||
let env = env()?;
|
||||
|
||||
if cli_options.dev {
|
||||
@ -77,6 +82,7 @@ pub fn command(options: Options) -> Result<()> {
|
||||
.build
|
||||
.dev_url
|
||||
.clone();
|
||||
|
||||
if let Some(port) = dev_url.and_then(|url| url.port_or_known_default()) {
|
||||
let forward = format!("tcp:{port}");
|
||||
// ignore errors in case we do not have a device available
|
||||
|
@ -201,6 +201,7 @@ fn run_build(
|
||||
args: build_options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
config: build_options.config.clone(),
|
||||
};
|
||||
let handle = write_options(
|
||||
&tauri_config.lock().unwrap().as_ref().unwrap().identifier,
|
||||
|
@ -222,7 +222,7 @@ fn run_dev(
|
||||
debug: !options.release_mode,
|
||||
features: options.features,
|
||||
args: Vec::new(),
|
||||
config: options.config,
|
||||
config: dev_options.config.clone(),
|
||||
no_watch: options.no_watch,
|
||||
},
|
||||
|options| {
|
||||
@ -232,6 +232,7 @@ fn run_dev(
|
||||
args: options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
config: dev_options.config.clone(),
|
||||
};
|
||||
|
||||
let _handle = write_options(
|
||||
|
@ -283,6 +283,7 @@ fn run_build(
|
||||
args: build_options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
config: build_options.config.clone(),
|
||||
};
|
||||
let handle = write_options(
|
||||
&tauri_config.lock().unwrap().as_ref().unwrap().identifier,
|
||||
|
@ -36,6 +36,8 @@ use std::{
|
||||
sync::OnceLock,
|
||||
};
|
||||
|
||||
const PHYSICAL_IPHONE_DEV_WARNING: &str = "To develop on physical phones you need the `--host` option (not required for Simulators). See the documentation for more information: https://v2.tauri.app/develop/#development-server";
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(
|
||||
about = "Run your app in development mode on iOS",
|
||||
@ -367,6 +369,8 @@ fn run_dev(
|
||||
let out_dir = bin_path.parent().unwrap();
|
||||
let _lock = flock::open_rw(out_dir.join("lock").with_extension("ios"), "iOS")?;
|
||||
|
||||
let set_host = options.host.is_some();
|
||||
|
||||
configure_cargo(app, None)?;
|
||||
|
||||
let open = options.open;
|
||||
@ -377,7 +381,7 @@ fn run_dev(
|
||||
debug: true,
|
||||
features: options.features,
|
||||
args: Vec::new(),
|
||||
config: options.config,
|
||||
config: dev_options.config.clone(),
|
||||
no_watch: options.no_watch,
|
||||
},
|
||||
|options| {
|
||||
@ -387,6 +391,7 @@ fn run_dev(
|
||||
args: options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
config: dev_options.config.clone(),
|
||||
};
|
||||
let _handle = write_options(
|
||||
&tauri_config.lock().unwrap().as_ref().unwrap().identifier,
|
||||
@ -394,6 +399,9 @@ fn run_dev(
|
||||
)?;
|
||||
|
||||
if open {
|
||||
if !set_host {
|
||||
log::warn!("{PHYSICAL_IPHONE_DEV_WARNING}");
|
||||
}
|
||||
open_and_wait(config, &env)
|
||||
} else if let Some(device) = &device {
|
||||
match run(device, options, config, &env) {
|
||||
@ -409,6 +417,9 @@ fn run_dev(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !set_host {
|
||||
log::warn!("{PHYSICAL_IPHONE_DEV_WARNING}");
|
||||
}
|
||||
open_and_wait(config, &env)
|
||||
}
|
||||
},
|
||||
|
@ -8,6 +8,7 @@ use crate::{
|
||||
config::{Config as TauriConfig, ConfigHandle},
|
||||
},
|
||||
interface::{AppInterface, AppSettings, DevProcess, Interface, Options as InterfaceOptions},
|
||||
ConfigValue,
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
use anyhow::Context;
|
||||
@ -141,6 +142,7 @@ pub struct CliOptions {
|
||||
pub args: Vec<String>,
|
||||
pub noise_level: NoiseLevel,
|
||||
pub vars: HashMap<String, OsString>,
|
||||
pub config: Option<ConfigValue>,
|
||||
}
|
||||
|
||||
impl Default for CliOptions {
|
||||
@ -151,6 +153,7 @@ impl Default for CliOptions {
|
||||
args: vec!["--lib".into()],
|
||||
noise_level: Default::default(),
|
||||
vars: Default::default(),
|
||||
config: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user