Skip to content

Commit

Permalink
feat: change default interface to be nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Mar 16, 2024
1 parent a6fce1e commit b49fe0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions packages/desktop/src/providers/network/provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use anyhow::{anyhow, Result};
use anyhow::Result;
use async_trait::async_trait;
use tokio::{sync::Mutex, task::AbortHandle};

Expand Down Expand Up @@ -108,16 +108,19 @@ impl IntervalProvider for NetworkProvider {
) -> Result<ProviderVariables> {
let interfaces = netdev::get_interfaces();

let default_interface =
netdev::get_default_interface().map_err(|e| anyhow!(e))?;
let default_interface = netdev::get_default_interface().ok();

let variables = NetworkVariables {
default_interface: Self::transform_interface(&default_interface),
default_gateway: default_interface.gateway.and_then(|gateway| {
default_gateway_wifi()
.map(|wifi| Self::transform_gateway(&gateway, wifi))
.ok()
}),
default_interface: default_interface
.as_ref()
.map(Self::transform_interface),
default_gateway: default_interface
.and_then(|interface| interface.gateway)
.and_then(|gateway| {
default_gateway_wifi()
.map(|wifi| Self::transform_gateway(&gateway, wifi))
.ok()
}),
interfaces: interfaces
.iter()
.map(Self::transform_interface)
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/network/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Serialize;
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct NetworkVariables {
pub default_interface: NetworkInterface,
pub default_interface: Option<NetworkInterface>,
pub default_gateway: Option<NetworkGateway>,
pub interfaces: Vec<NetworkInterface>,
}
Expand Down

0 comments on commit b49fe0b

Please sign in to comment.