Skip to content

Commit 34abe49

Browse files
committed
fix: select local ip by default in adapteur network when no ip in config
1 parent fb1eaf7 commit 34abe49

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

RustApp/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{fmt::Display, net::IpAddr};
22

33
use clap::Parser;
44
use light_enum::Values;
5+
use local_ip_address::local_ip;
56
use serde::{Deserialize, Serialize};
67

78
use crate::fl;
@@ -89,6 +90,10 @@ impl Config {
8990
self.speex_dereverb_enabled = false;
9091
self.speex_dereverb_level = 0.5;
9192
}
93+
94+
pub fn ip_or_default(&self) -> Option<IpAddr> {
95+
self.ip.or(local_ip().ok())
96+
}
9297
}
9398

9499
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Values)]

RustApp/src/ui/app.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cpal::{
77
Device, Host,
88
traits::{DeviceTrait, HostTrait},
99
};
10-
use local_ip_address::{list_afinet_netifas, local_ip};
10+
use local_ip_address::list_afinet_netifas;
1111
use notify_rust::Notification;
1212
use rtrb::RingBuffer;
1313
use tokio::sync::mpsc::Sender;
@@ -202,11 +202,22 @@ impl AppState {
202202

203203
let connect_options = match config.connection_mode {
204204
ConnectionMode::Tcp => {
205-
let ip = config.ip.unwrap_or(local_ip().unwrap());
205+
let Some(ip) = config.ip_or_default() else {
206+
let e = "no address ip found";
207+
208+
error!("failed to start audio stream: {e}");
209+
return self.add_log(&e.to_string());
210+
};
211+
206212
ConnectOption::Tcp { ip }
207213
}
208214
ConnectionMode::Udp => {
209-
let ip = config.ip.unwrap_or(local_ip().unwrap());
215+
let Some(ip) = config.ip_or_default() else {
216+
let e = "no address ip found";
217+
218+
error!("failed to start audio stream: {e}");
219+
return self.add_log(&e.to_string());
220+
};
210221
ConnectOption::Udp { ip }
211222
}
212223
#[cfg(feature = "adb")]
@@ -308,7 +319,7 @@ impl Application for AppState {
308319
ip: *ip,
309320
})
310321
.collect::<Vec<_>>();
311-
let network_adapter = match &flags.config.data().ip {
322+
let network_adapter = match &flags.config.data().ip_or_default() {
312323
Some(ip) => match network_adapters.iter().find(|adapter| adapter.ip == *ip) {
313324
Some(adapter) => Some(adapter.clone()),
314325
None => {

0 commit comments

Comments
 (0)