Allow to connect to the dev server from a physical Android device (#3634)

* fix(android): now dev server just works on devices

* fix: allow custom port for Android app development

* refactor: simplified URL creation in LaunchBuilder
This commit is contained in:
Andrew Voynov authored and GitHub committed 2025-01-31 14:29:54 -08:00
1 parent d7e64d5d24
commit 67515ce812
4 files changed
+55 -14

No files matched your search

+12 -3
View File
@@ -59,7 +59,8 @@ use std::{
pub const CLI_ENABLED_ENV: &str = "DIOXUS_CLI_ENABLED";
pub const SERVER_IP_ENV: &str = "IP";
pub const SERVER_PORT_ENV: &str = "PORT";
pub const DEVSERVER_RAW_ADDR_ENV: &str = "DIOXUS_DEVSERVER_ADDR";
pub const DEVSERVER_IP_ENV: &str = "DIOXUS_DEVSERVER_IP";
pub const DEVSERVER_PORT_ENV: &str = "DIOXUS_DEVSERVER_PORT";
pub const ALWAYS_ON_TOP_ENV: &str = "DIOXUS_ALWAYS_ON_TOP";
pub const ASSET_ROOT_ENV: &str = "DIOXUS_ASSET_ROOT";
pub const APP_TITLE_ENV: &str = "DIOXUS_APP_TITLE";
@@ -100,8 +101,16 @@ macro_rules! read_env_config {
/// For reference, the devserver typically lives on `127.0.0.1:8080` and serves the devserver websocket
/// on `127.0.0.1:8080/_dioxus`.
pub fn devserver_raw_addr() -> Option<SocketAddr> {
let addr = std::env::var(DEVSERVER_RAW_ADDR_ENV).ok()?;
addr.parse().ok()
let ip = std::env::var(DEVSERVER_IP_ENV).ok()?;
let port = std::env::var(DEVSERVER_PORT_ENV).ok()?;
if cfg!(target_os = "android") {
// Since `adb reverse` is used for Android, the 127.0.0.1 will always be
// the correct IP address.
return Some(format!("127.0.0.1:{}", port).parse().unwrap());
}
format!("{}:{}", ip, port).parse().ok()
}
/// Get the address of the devserver for use over a websocket