Skip to content

Commit b001242

Browse files
authored
fix(cli): resolve IP when dev URL host is unspecified, closes #13356 (#14115)
currently the `use_network_address_for_dev_url` function already detects Ipv4Addr::UNSPECIFIED to resolve the local IP address for mobile development when the dev URL host is 0.0.0.0, but we only call it when `--host` is provided or running on a physical device. This change detects the unspecified host early and force the resolution to run even for simulator builds
1 parent 06d4a4e commit b001242

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/cli": patch:bug
3+
"tauri-cli": patch:bug
4+
---
5+
6+
Resolve local IP address when `tauri.conf.json > build > devUrl` host is `0.0.0.0`.

crates/tauri-cli/src/mobile/android/dev.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ use cargo_mobile2::{
3333
opts::{FilterLevel, NoiseLevel, Profile},
3434
target::TargetTrait,
3535
};
36+
use url::Host;
3637

37-
use std::{env::set_current_dir, path::PathBuf};
38+
use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf};
3839

3940
#[derive(Debug, Clone, Parser)]
4041
#[clap(
@@ -231,12 +232,26 @@ fn run_dev(
231232
metadata: &AndroidMetadata,
232233
noise_level: NoiseLevel,
233234
) -> Result<()> {
234-
// when running on an actual device we must use the network IP
235+
// when --host is provided or running on a physical device or resolving 0.0.0.0 we must use the network IP
235236
if options.host.0.is_some()
236237
|| device
237238
.as_ref()
238239
.map(|device| !device.serial_no().starts_with("emulator"))
239240
.unwrap_or(false)
241+
|| tauri_config
242+
.lock()
243+
.unwrap()
244+
.as_ref()
245+
.unwrap()
246+
.build
247+
.dev_url
248+
.as_ref()
249+
.is_some_and(|url| {
250+
matches!(
251+
url.host(),
252+
Some(Host::Ipv4(i)) if i == Ipv4Addr::UNSPECIFIED
253+
)
254+
})
240255
{
241256
use_network_address_for_dev_url(&tauri_config, &mut dev_options, options.force_ip_prompt)?;
242257
}

crates/tauri-cli/src/mobile/ios/dev.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ use cargo_mobile2::{
3232
env::Env,
3333
opts::{NoiseLevel, Profile},
3434
};
35+
use url::Host;
3536

36-
use std::{env::set_current_dir, path::PathBuf};
37+
use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf};
3738

3839
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";
3940

@@ -271,12 +272,26 @@ fn run_dev(
271272
config: &AppleConfig,
272273
noise_level: NoiseLevel,
273274
) -> Result<()> {
274-
// when running on an actual device we must use the network IP
275+
// when --host is provided or running on a physical device or resolving 0.0.0.0 we must use the network IP
275276
if options.host.0.is_some()
276277
|| device
277278
.as_ref()
278279
.map(|device| !matches!(device.kind(), DeviceKind::Simulator))
279280
.unwrap_or(false)
281+
|| tauri_config
282+
.lock()
283+
.unwrap()
284+
.as_ref()
285+
.unwrap()
286+
.build
287+
.dev_url
288+
.as_ref()
289+
.is_some_and(|url| {
290+
matches!(
291+
url.host(),
292+
Some(Host::Ipv4(i)) if i == Ipv4Addr::UNSPECIFIED
293+
)
294+
})
280295
{
281296
use_network_address_for_dev_url(&tauri_config, &mut dev_options, options.force_ip_prompt)?;
282297
}

crates/tauri-cli/src/mobile/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ fn use_network_address_for_dev_url(
268268
let ip = if let Some(url) = &mut dev_url {
269269
let localhost = match url.host() {
270270
Some(url::Host::Domain(d)) => d == "localhost",
271-
Some(url::Host::Ipv4(i)) => {
272-
i == std::net::Ipv4Addr::LOCALHOST || i == std::net::Ipv4Addr::UNSPECIFIED
273-
}
271+
Some(url::Host::Ipv4(i)) => i == Ipv4Addr::LOCALHOST || i == Ipv4Addr::UNSPECIFIED,
274272
_ => false,
275273
};
276274

0 commit comments

Comments
 (0)