Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/fix-unspeficied-dev-host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tauri-apps/cli": patch:bug
"tauri-cli": patch:bug
---

Resolve local IP address when `tauri.conf.json > build > devUrl` host is `0.0.0.0`.
19 changes: 17 additions & 2 deletions crates/tauri-cli/src/mobile/android/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ use cargo_mobile2::{
opts::{FilterLevel, NoiseLevel, Profile},
target::TargetTrait,
};
use url::Host;

use std::{env::set_current_dir, path::PathBuf};
use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf};

#[derive(Debug, Clone, Parser)]
#[clap(
Expand Down Expand Up @@ -231,12 +232,26 @@ fn run_dev(
metadata: &AndroidMetadata,
noise_level: NoiseLevel,
) -> Result<()> {
// when running on an actual device we must use the network IP
// when --host is provided or running on a physical device or resolving 0.0.0.0 we must use the network IP
if options.host.0.is_some()
|| device
.as_ref()
.map(|device| !device.serial_no().starts_with("emulator"))
.unwrap_or(false)
|| tauri_config
.lock()
.unwrap()
.as_ref()
.unwrap()
.build
.dev_url
.as_ref()
.is_some_and(|url| {
matches!(
url.host(),
Some(Host::Ipv4(i)) if i == Ipv4Addr::UNSPECIFIED
)
})
{
use_network_address_for_dev_url(&tauri_config, &mut dev_options, options.force_ip_prompt)?;
}
Expand Down
19 changes: 17 additions & 2 deletions crates/tauri-cli/src/mobile/ios/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use cargo_mobile2::{
env::Env,
opts::{NoiseLevel, Profile},
};
use url::Host;

use std::{env::set_current_dir, path::PathBuf};
use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf};

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

Expand Down Expand Up @@ -271,12 +272,26 @@ fn run_dev(
config: &AppleConfig,
noise_level: NoiseLevel,
) -> Result<()> {
// when running on an actual device we must use the network IP
// when --host is provided or running on a physical device or resolving 0.0.0.0 we must use the network IP
if options.host.0.is_some()
|| device
.as_ref()
.map(|device| !matches!(device.kind(), DeviceKind::Simulator))
.unwrap_or(false)
|| tauri_config
.lock()
.unwrap()
.as_ref()
.unwrap()
.build
.dev_url
.as_ref()
.is_some_and(|url| {
matches!(
url.host(),
Some(Host::Ipv4(i)) if i == Ipv4Addr::UNSPECIFIED
)
})
{
use_network_address_for_dev_url(&tauri_config, &mut dev_options, options.force_ip_prompt)?;
}
Expand Down
4 changes: 1 addition & 3 deletions crates/tauri-cli/src/mobile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ fn use_network_address_for_dev_url(
let ip = if let Some(url) = &mut dev_url {
let localhost = match url.host() {
Some(url::Host::Domain(d)) => d == "localhost",
Some(url::Host::Ipv4(i)) => {
i == std::net::Ipv4Addr::LOCALHOST || i == std::net::Ipv4Addr::UNSPECIFIED
}
Some(url::Host::Ipv4(i)) => i == Ipv4Addr::LOCALHOST || i == Ipv4Addr::UNSPECIFIED,
_ => false,
};

Expand Down
Loading