Skip to content

Commit

Permalink
Remove redundant state calls
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewtapps committed Mar 9, 2024
1 parent c7f9b4b commit 64938c0
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions packages/desktop/src/providers/network/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,30 @@ use super::{
pub struct NetworkProvider {
pub config: Arc<NetworkProviderConfig>,
abort_handle: Option<AbortHandle>,
netdev_data: Arc<Mutex<NetdevData>>,
}

pub struct NetdevData {
pub default_interface: Arc<Mutex<Interface>>,
pub interfaces: Arc<Mutex<Vec<Interface>>>,
state: Arc<Mutex<()>>,
}

impl NetworkProvider {
pub fn new(config: NetworkProviderConfig) -> NetworkProvider {
NetworkProvider {
config: Arc::new(config),
abort_handle: None,
netdev_data: Arc::new(Mutex::new(NetdevData {
default_interface: Arc::new(Mutex::new(
get_default_interface().unwrap(),
)),
interfaces: Arc::new(Mutex::new(get_interfaces())),
})),
state: Arc::new(Mutex::new(())),
}
}
}

#[async_trait]
impl IntervalProvider for NetworkProvider {
type Config = NetworkProviderConfig;
type State = Mutex<NetdevData>;
type State = ();

fn config(&self) -> Arc<NetworkProviderConfig> {
self.config.clone()
}

fn state(&self) -> Arc<Mutex<NetdevData>> {
self.netdev_data.clone()
fn state(&self) -> Arc<()> {
Arc::new(())
}

fn abort_handle(&self) -> &Option<AbortHandle> {
Expand All @@ -66,13 +56,12 @@ impl IntervalProvider for NetworkProvider {

async fn get_refreshed_variables(
_: &NetworkProviderConfig,
netdev_data: &Mutex<NetdevData>,
state: &(),
) -> Result<ProviderVariables> {
let netdev = netdev_data.lock().await;

let default_interface = netdev.default_interface.lock().await.clone();
let default_interface = get_default_interface().unwrap();

let interfaces = netdev.interfaces.lock().await;
let interfaces = get_interfaces();

let default_gateway_ssid_and_strength =
get_primary_interface_ssid_and_strength()?; // Returns ssid = None, signal = None, connected = false if not on Windows for now
Expand Down

0 comments on commit 64938c0

Please sign in to comment.