fix(cli): use local ip addr for built-in server on mobile, closes #6454 (#6631)

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio>
fix(cli): use local ip addr for built-in server on mobile, closes #6454
This commit is contained in:
Amr Bashir
2023-04-04 14:59:29 +02:00
committed by GitHub
parent 29ee62342a
commit 7fec0f083c
3 changed files with 19 additions and 4 deletions

View File

@@ -0,0 +1,6 @@
---
'cli.rs': 'patch'
'cli.js': 'patch'
---
Use local ip address for built-in dev server on mobile.

View File

@@ -313,7 +313,12 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result<AppInterface> {
use crate::helpers::web_dev_server::start_dev_server;
if path.exists() {
let path = path.canonicalize()?;
let server_url = start_dev_server(path, options.port)?;
let ip = if mobile {
*local_ip_address(options.force_ip_prompt)
} else {
Ipv4Addr::new(127, 0, 0, 1).into()
};
let server_url = start_dev_server(path, ip, options.port)?;
let server_url = format!("http://{server_url}");
dev_path = AppUrl::Url(WindowUrl::External(server_url.parse().unwrap()));

View File

@@ -14,7 +14,7 @@ use kuchiki::{traits::TendrilSink, NodeRef};
use notify::RecursiveMode;
use notify_debouncer_mini::new_debouncer;
use std::{
net::{Ipv4Addr, SocketAddr},
net::{IpAddr, SocketAddr},
path::{Path, PathBuf},
sync::{mpsc::sync_channel, Arc},
thread,
@@ -31,7 +31,11 @@ struct State {
tx: Sender<()>,
}
pub fn start_dev_server<P: AsRef<Path>>(path: P, port: Option<u16>) -> crate::Result<SocketAddr> {
pub fn start_dev_server<P: AsRef<Path>>(
path: P,
ip: IpAddr,
port: Option<u16>,
) -> crate::Result<SocketAddr> {
let serve_dir = path.as_ref().to_path_buf();
let (server_url_tx, server_url_rx) = std::sync::mpsc::channel();
@@ -79,7 +83,7 @@ pub fn start_dev_server<P: AsRef<Path>>(path: P, port: Option<u16>) -> crate::Re
});
let (server, server_url) = loop {
let server_url = SocketAddr::new(Ipv4Addr::new(127, 0, 0, 1).into(), port);
let server_url = SocketAddr::new(ip, port);
let server = Server::try_bind(&server_url);
if !auto_port {