From 82f29f2bd6394f085966b6bf712b786d17a178b4 Mon Sep 17 00:00:00 2001 From: lars-berger Date: Tue, 17 Sep 2024 17:31:21 +0800 Subject: [PATCH] refactor: rename provider-related files (#106) --- .../{provider.rs => battery_provider.rs} | 22 +++++++++- .../desktop/src/providers/battery/config.rs | 7 ---- packages/desktop/src/providers/battery/mod.rs | 8 +--- .../src/providers/battery/variables.rs | 15 ------- packages/desktop/src/providers/cpu/config.rs | 7 ---- .../cpu/{provider.rs => cpu_provider.rs} | 18 +++++++- packages/desktop/src/providers/cpu/mod.rs | 8 +--- .../desktop/src/providers/cpu/variables.rs | 11 ----- packages/desktop/src/providers/host/config.rs | 7 ---- .../host/{provider.rs => host_provider.rs} | 19 ++++++++- packages/desktop/src/providers/host/mod.rs | 8 +--- .../desktop/src/providers/host/variables.rs | 12 ------ packages/desktop/src/providers/ip/config.rs | 7 ---- .../ip/{provider.rs => ip_provider.rs} | 19 ++++++++- packages/desktop/src/providers/ip/mod.rs | 8 +--- .../desktop/src/providers/ip/variables.rs | 11 ----- .../desktop/src/providers/keyboard/config.rs | 7 ---- .../{provider.rs => keyboard_provider.rs} | 14 ++++++- .../desktop/src/providers/keyboard/mod.rs | 8 +--- .../src/providers/keyboard/variables.rs | 7 ---- .../desktop/src/providers/komorebi/config.rs | 5 --- .../{provider.rs => komorebi_provider.rs} | 15 ++++++- .../{variables.rs => komorebi_res.rs} | 7 ---- .../desktop/src/providers/komorebi/mod.rs | 10 ++--- .../desktop/src/providers/memory/config.rs | 7 ---- .../{provider.rs => memory_provider.rs} | 20 ++++++++- packages/desktop/src/providers/memory/mod.rs | 8 +--- .../desktop/src/providers/memory/variables.rs | 13 ------ packages/desktop/src/providers/mod.rs | 8 ++-- .../desktop/src/providers/network/config.rs | 7 ---- packages/desktop/src/providers/network/mod.rs | 10 ++--- .../network/{variables.rs => netdev_res.rs} | 9 ---- .../{provider.rs => network_provider.rs} | 21 ++++++++-- .../{config.rs => provider_config.rs} | 0 .../{variables.rs => provider_output.rs} | 0 .../desktop/src/providers/weather/config.rs | 9 ---- packages/desktop/src/providers/weather/mod.rs | 8 +--- .../src/providers/weather/variables.rs | 28 ------------- .../{provider.rs => weather_provider.rs} | 41 +++++++++++++++++-- 39 files changed, 200 insertions(+), 249 deletions(-) rename packages/desktop/src/providers/battery/{provider.rs => battery_provider.rs} (72%) delete mode 100644 packages/desktop/src/providers/battery/config.rs delete mode 100644 packages/desktop/src/providers/battery/variables.rs delete mode 100644 packages/desktop/src/providers/cpu/config.rs rename packages/desktop/src/providers/cpu/{provider.rs => cpu_provider.rs} (71%) delete mode 100644 packages/desktop/src/providers/cpu/variables.rs delete mode 100644 packages/desktop/src/providers/host/config.rs rename packages/desktop/src/providers/host/{provider.rs => host_provider.rs} (62%) delete mode 100644 packages/desktop/src/providers/host/variables.rs delete mode 100644 packages/desktop/src/providers/ip/config.rs rename packages/desktop/src/providers/ip/{provider.rs => ip_provider.rs} (72%) delete mode 100644 packages/desktop/src/providers/ip/variables.rs delete mode 100644 packages/desktop/src/providers/keyboard/config.rs rename packages/desktop/src/providers/keyboard/{provider.rs => keyboard_provider.rs} (82%) delete mode 100644 packages/desktop/src/providers/keyboard/variables.rs delete mode 100644 packages/desktop/src/providers/komorebi/config.rs rename packages/desktop/src/providers/komorebi/{provider.rs => komorebi_provider.rs} (93%) rename packages/desktop/src/providers/komorebi/{variables.rs => komorebi_res.rs} (93%) delete mode 100644 packages/desktop/src/providers/memory/config.rs rename packages/desktop/src/providers/memory/{provider.rs => memory_provider.rs} (71%) delete mode 100644 packages/desktop/src/providers/memory/variables.rs delete mode 100644 packages/desktop/src/providers/network/config.rs rename packages/desktop/src/providers/network/{variables.rs => netdev_res.rs} (91%) rename packages/desktop/src/providers/network/{provider.rs => network_provider.rs} (89%) rename packages/desktop/src/providers/{config.rs => provider_config.rs} (100%) rename packages/desktop/src/providers/{variables.rs => provider_output.rs} (100%) delete mode 100644 packages/desktop/src/providers/weather/config.rs delete mode 100644 packages/desktop/src/providers/weather/variables.rs rename packages/desktop/src/providers/weather/{provider.rs => weather_provider.rs} (78%) diff --git a/packages/desktop/src/providers/battery/provider.rs b/packages/desktop/src/providers/battery/battery_provider.rs similarity index 72% rename from packages/desktop/src/providers/battery/provider.rs rename to packages/desktop/src/providers/battery/battery_provider.rs index ff76e28d..21316295 100644 --- a/packages/desktop/src/providers/battery/provider.rs +++ b/packages/desktop/src/providers/battery/battery_provider.rs @@ -1,4 +1,5 @@ use anyhow::Context; +use serde::{Deserialize, Serialize}; use starship_battery::{ units::{ electric_potential::volt, power::watt, ratio::percent, @@ -7,9 +8,28 @@ use starship_battery::{ Manager, State, }; -use super::{BatteryOutput, BatteryProviderConfig}; use crate::{impl_interval_provider, providers::ProviderOutput}; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct BatteryProviderConfig { + pub refresh_interval: u64, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct BatteryOutput { + pub charge_percent: f32, + pub health_percent: f32, + pub state: String, + pub is_charging: bool, + pub time_till_full: Option, + pub time_till_empty: Option, + pub power_consumption: f32, + pub voltage: f32, + pub cycle_count: Option, +} + pub struct BatteryProvider { config: BatteryProviderConfig, } diff --git a/packages/desktop/src/providers/battery/config.rs b/packages/desktop/src/providers/battery/config.rs deleted file mode 100644 index 85da02f8..00000000 --- a/packages/desktop/src/providers/battery/config.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct BatteryProviderConfig { - pub refresh_interval: u64, -} diff --git a/packages/desktop/src/providers/battery/mod.rs b/packages/desktop/src/providers/battery/mod.rs index 8434e838..6ece1145 100644 --- a/packages/desktop/src/providers/battery/mod.rs +++ b/packages/desktop/src/providers/battery/mod.rs @@ -1,7 +1,3 @@ -mod config; -mod provider; -mod variables; +mod battery_provider; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use battery_provider::*; diff --git a/packages/desktop/src/providers/battery/variables.rs b/packages/desktop/src/providers/battery/variables.rs deleted file mode 100644 index 6588d051..00000000 --- a/packages/desktop/src/providers/battery/variables.rs +++ /dev/null @@ -1,15 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct BatteryOutput { - pub charge_percent: f32, - pub health_percent: f32, - pub state: String, - pub is_charging: bool, - pub time_till_full: Option, - pub time_till_empty: Option, - pub power_consumption: f32, - pub voltage: f32, - pub cycle_count: Option, -} diff --git a/packages/desktop/src/providers/cpu/config.rs b/packages/desktop/src/providers/cpu/config.rs deleted file mode 100644 index e186ce4b..00000000 --- a/packages/desktop/src/providers/cpu/config.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct CpuProviderConfig { - pub refresh_interval: u64, -} diff --git a/packages/desktop/src/providers/cpu/provider.rs b/packages/desktop/src/providers/cpu/cpu_provider.rs similarity index 71% rename from packages/desktop/src/providers/cpu/provider.rs rename to packages/desktop/src/providers/cpu/cpu_provider.rs index b384d784..5f9e6bdc 100644 --- a/packages/desktop/src/providers/cpu/provider.rs +++ b/packages/desktop/src/providers/cpu/cpu_provider.rs @@ -1,11 +1,27 @@ use std::sync::Arc; +use serde::{Deserialize, Serialize}; use sysinfo::System; use tokio::sync::Mutex; -use super::{CpuOutput, CpuProviderConfig}; use crate::{impl_interval_provider, providers::ProviderOutput}; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct CpuProviderConfig { + pub refresh_interval: u64, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct CpuOutput { + pub frequency: u64, + pub usage: f32, + pub logical_core_count: usize, + pub physical_core_count: usize, + pub vendor: String, +} + pub struct CpuProvider { config: CpuProviderConfig, sysinfo: Arc>, diff --git a/packages/desktop/src/providers/cpu/mod.rs b/packages/desktop/src/providers/cpu/mod.rs index 8434e838..165fa5c0 100644 --- a/packages/desktop/src/providers/cpu/mod.rs +++ b/packages/desktop/src/providers/cpu/mod.rs @@ -1,7 +1,3 @@ -mod config; -mod provider; -mod variables; +mod cpu_provider; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use cpu_provider::*; diff --git a/packages/desktop/src/providers/cpu/variables.rs b/packages/desktop/src/providers/cpu/variables.rs deleted file mode 100644 index ee799796..00000000 --- a/packages/desktop/src/providers/cpu/variables.rs +++ /dev/null @@ -1,11 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct CpuOutput { - pub frequency: u64, - pub usage: f32, - pub logical_core_count: usize, - pub physical_core_count: usize, - pub vendor: String, -} diff --git a/packages/desktop/src/providers/host/config.rs b/packages/desktop/src/providers/host/config.rs deleted file mode 100644 index f56a1431..00000000 --- a/packages/desktop/src/providers/host/config.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct HostProviderConfig { - pub refresh_interval: u64, -} diff --git a/packages/desktop/src/providers/host/provider.rs b/packages/desktop/src/providers/host/host_provider.rs similarity index 62% rename from packages/desktop/src/providers/host/provider.rs rename to packages/desktop/src/providers/host/host_provider.rs index e1ba316b..9b26a4b2 100644 --- a/packages/desktop/src/providers/host/provider.rs +++ b/packages/desktop/src/providers/host/host_provider.rs @@ -1,8 +1,25 @@ +use serde::{Deserialize, Serialize}; use sysinfo::System; -use super::{HostOutput, HostProviderConfig}; use crate::{impl_interval_provider, providers::ProviderOutput}; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct HostProviderConfig { + pub refresh_interval: u64, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct HostOutput { + pub hostname: Option, + pub os_name: Option, + pub os_version: Option, + pub friendly_os_version: Option, + pub boot_time: u64, + pub uptime: u64, +} + pub struct HostProvider { config: HostProviderConfig, } diff --git a/packages/desktop/src/providers/host/mod.rs b/packages/desktop/src/providers/host/mod.rs index 8434e838..0d116bd2 100644 --- a/packages/desktop/src/providers/host/mod.rs +++ b/packages/desktop/src/providers/host/mod.rs @@ -1,7 +1,3 @@ -mod config; -mod provider; -mod variables; +mod host_provider; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use host_provider::*; diff --git a/packages/desktop/src/providers/host/variables.rs b/packages/desktop/src/providers/host/variables.rs deleted file mode 100644 index 4043501f..00000000 --- a/packages/desktop/src/providers/host/variables.rs +++ /dev/null @@ -1,12 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct HostOutput { - pub hostname: Option, - pub os_name: Option, - pub os_version: Option, - pub friendly_os_version: Option, - pub boot_time: u64, - pub uptime: u64, -} diff --git a/packages/desktop/src/providers/ip/config.rs b/packages/desktop/src/providers/ip/config.rs deleted file mode 100644 index c2d8a597..00000000 --- a/packages/desktop/src/providers/ip/config.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct IpProviderConfig { - pub refresh_interval: u64, -} diff --git a/packages/desktop/src/providers/ip/provider.rs b/packages/desktop/src/providers/ip/ip_provider.rs similarity index 72% rename from packages/desktop/src/providers/ip/provider.rs rename to packages/desktop/src/providers/ip/ip_provider.rs index bf259b06..590769ed 100644 --- a/packages/desktop/src/providers/ip/provider.rs +++ b/packages/desktop/src/providers/ip/ip_provider.rs @@ -1,9 +1,26 @@ use anyhow::Context; use reqwest::Client; +use serde::{Deserialize, Serialize}; -use super::{ipinfo_res::IpinfoRes, IpOutput, IpProviderConfig}; +use super::ipinfo_res::IpinfoRes; use crate::{impl_interval_provider, providers::ProviderOutput}; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct IpProviderConfig { + pub refresh_interval: u64, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct IpOutput { + pub address: String, + pub approx_city: String, + pub approx_country: String, + pub approx_latitude: f32, + pub approx_longitude: f32, +} + pub struct IpProvider { config: IpProviderConfig, http_client: Client, diff --git a/packages/desktop/src/providers/ip/mod.rs b/packages/desktop/src/providers/ip/mod.rs index 97db5f81..29de3178 100644 --- a/packages/desktop/src/providers/ip/mod.rs +++ b/packages/desktop/src/providers/ip/mod.rs @@ -1,8 +1,4 @@ -mod config; +mod ip_provider; mod ipinfo_res; -mod provider; -mod variables; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use ip_provider::*; diff --git a/packages/desktop/src/providers/ip/variables.rs b/packages/desktop/src/providers/ip/variables.rs deleted file mode 100644 index 0474e46b..00000000 --- a/packages/desktop/src/providers/ip/variables.rs +++ /dev/null @@ -1,11 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct IpOutput { - pub address: String, - pub approx_city: String, - pub approx_country: String, - pub approx_latitude: f32, - pub approx_longitude: f32, -} diff --git a/packages/desktop/src/providers/keyboard/config.rs b/packages/desktop/src/providers/keyboard/config.rs deleted file mode 100644 index dbc6fc1f..00000000 --- a/packages/desktop/src/providers/keyboard/config.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct KeyboardProviderConfig { - pub refresh_interval: u64, -} diff --git a/packages/desktop/src/providers/keyboard/provider.rs b/packages/desktop/src/providers/keyboard/keyboard_provider.rs similarity index 82% rename from packages/desktop/src/providers/keyboard/provider.rs rename to packages/desktop/src/providers/keyboard/keyboard_provider.rs index 5409923f..31d2d00b 100644 --- a/packages/desktop/src/providers/keyboard/provider.rs +++ b/packages/desktop/src/providers/keyboard/keyboard_provider.rs @@ -1,4 +1,5 @@ use anyhow::bail; +use serde::{Deserialize, Serialize}; use windows::Win32::{ Globalization::{LCIDToLocaleName, LOCALE_ALLOW_NEUTRAL_NAMES}, System::SystemServices::LOCALE_NAME_MAX_LENGTH, @@ -8,9 +9,20 @@ use windows::Win32::{ }, }; -use super::{KeyboardOutput, KeyboardProviderConfig}; use crate::{impl_interval_provider, providers::ProviderOutput}; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct KeyboardProviderConfig { + pub refresh_interval: u64, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct KeyboardOutput { + pub layout: String, +} + pub struct KeyboardProvider { config: KeyboardProviderConfig, } diff --git a/packages/desktop/src/providers/keyboard/mod.rs b/packages/desktop/src/providers/keyboard/mod.rs index 8434e838..9d85468c 100644 --- a/packages/desktop/src/providers/keyboard/mod.rs +++ b/packages/desktop/src/providers/keyboard/mod.rs @@ -1,7 +1,3 @@ -mod config; -mod provider; -mod variables; +mod keyboard_provider; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use keyboard_provider::*; diff --git a/packages/desktop/src/providers/keyboard/variables.rs b/packages/desktop/src/providers/keyboard/variables.rs deleted file mode 100644 index c85ce379..00000000 --- a/packages/desktop/src/providers/keyboard/variables.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct KeyboardOutput { - pub layout: String, -} diff --git a/packages/desktop/src/providers/komorebi/config.rs b/packages/desktop/src/providers/komorebi/config.rs deleted file mode 100644 index 1ee2e048..00000000 --- a/packages/desktop/src/providers/komorebi/config.rs +++ /dev/null @@ -1,5 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct KomorebiProviderConfig {} diff --git a/packages/desktop/src/providers/komorebi/provider.rs b/packages/desktop/src/providers/komorebi/komorebi_provider.rs similarity index 93% rename from packages/desktop/src/providers/komorebi/provider.rs rename to packages/desktop/src/providers/komorebi/komorebi_provider.rs index c7364baf..900dc7cb 100644 --- a/packages/desktop/src/providers/komorebi/provider.rs +++ b/packages/desktop/src/providers/komorebi/komorebi_provider.rs @@ -8,18 +8,29 @@ use async_trait::async_trait; use komorebi_client::{ Container, Monitor, SocketMessage, Window, Workspace, }; +use serde::{Deserialize, Serialize}; use tokio::{sync::mpsc::Sender, time}; use tracing::debug; use super::{ KomorebiContainer, KomorebiLayout, KomorebiLayoutFlip, KomorebiMonitor, - KomorebiOutput, KomorebiProviderConfig, KomorebiWindow, - KomorebiWorkspace, + KomorebiWindow, KomorebiWorkspace, }; use crate::providers::{Provider, ProviderOutput, ProviderResult}; const SOCKET_NAME: &str = "zebar.sock"; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct KomorebiProviderConfig {} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct KomorebiOutput { + pub all_monitors: Vec, + pub focused_monitor_index: usize, +} + pub struct KomorebiProvider { _config: KomorebiProviderConfig, } diff --git a/packages/desktop/src/providers/komorebi/variables.rs b/packages/desktop/src/providers/komorebi/komorebi_res.rs similarity index 93% rename from packages/desktop/src/providers/komorebi/variables.rs rename to packages/desktop/src/providers/komorebi/komorebi_res.rs index 14b252a4..b88cb574 100644 --- a/packages/desktop/src/providers/komorebi/variables.rs +++ b/packages/desktop/src/providers/komorebi/komorebi_res.rs @@ -1,13 +1,6 @@ use komorebi_client::{Axis, DefaultLayout, Layout, Rect}; use serde::Serialize; -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct KomorebiOutput { - pub all_monitors: Vec, - pub focused_monitor_index: usize, -} - #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct KomorebiMonitor { diff --git a/packages/desktop/src/providers/komorebi/mod.rs b/packages/desktop/src/providers/komorebi/mod.rs index 8434e838..9b740856 100644 --- a/packages/desktop/src/providers/komorebi/mod.rs +++ b/packages/desktop/src/providers/komorebi/mod.rs @@ -1,7 +1,5 @@ -mod config; -mod provider; -mod variables; +mod komorebi_provider; +mod komorebi_res; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use komorebi_provider::*; +pub use komorebi_res::*; diff --git a/packages/desktop/src/providers/memory/config.rs b/packages/desktop/src/providers/memory/config.rs deleted file mode 100644 index 2fa8b11e..00000000 --- a/packages/desktop/src/providers/memory/config.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct MemoryProviderConfig { - pub refresh_interval: u64, -} diff --git a/packages/desktop/src/providers/memory/provider.rs b/packages/desktop/src/providers/memory/memory_provider.rs similarity index 71% rename from packages/desktop/src/providers/memory/provider.rs rename to packages/desktop/src/providers/memory/memory_provider.rs index 8f00bea8..077c8f4d 100644 --- a/packages/desktop/src/providers/memory/provider.rs +++ b/packages/desktop/src/providers/memory/memory_provider.rs @@ -1,11 +1,29 @@ use std::sync::Arc; +use serde::{Deserialize, Serialize}; use sysinfo::System; use tokio::sync::Mutex; -use super::{MemoryOutput, MemoryProviderConfig}; use crate::{impl_interval_provider, providers::ProviderOutput}; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct MemoryProviderConfig { + pub refresh_interval: u64, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct MemoryOutput { + pub usage: f32, + pub free_memory: u64, + pub used_memory: u64, + pub total_memory: u64, + pub free_swap: u64, + pub used_swap: u64, + pub total_swap: u64, +} + pub struct MemoryProvider { config: MemoryProviderConfig, sysinfo: Arc>, diff --git a/packages/desktop/src/providers/memory/mod.rs b/packages/desktop/src/providers/memory/mod.rs index 8434e838..ba883136 100644 --- a/packages/desktop/src/providers/memory/mod.rs +++ b/packages/desktop/src/providers/memory/mod.rs @@ -1,7 +1,3 @@ -mod config; -mod provider; -mod variables; +mod memory_provider; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use memory_provider::*; diff --git a/packages/desktop/src/providers/memory/variables.rs b/packages/desktop/src/providers/memory/variables.rs deleted file mode 100644 index 2011b1d9..00000000 --- a/packages/desktop/src/providers/memory/variables.rs +++ /dev/null @@ -1,13 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct MemoryOutput { - pub usage: f32, - pub free_memory: u64, - pub used_memory: u64, - pub total_memory: u64, - pub free_swap: u64, - pub used_swap: u64, - pub total_swap: u64, -} diff --git a/packages/desktop/src/providers/mod.rs b/packages/desktop/src/providers/mod.rs index 3cfaad1b..05c1f98e 100644 --- a/packages/desktop/src/providers/mod.rs +++ b/packages/desktop/src/providers/mod.rs @@ -1,5 +1,4 @@ mod battery; -mod config; mod cpu; mod host; mod ip; @@ -10,13 +9,14 @@ mod komorebi; mod memory; mod network; mod provider; +mod provider_config; mod provider_manager; +mod provider_output; mod provider_ref; -mod variables; mod weather; -pub use config::*; pub use provider::*; +pub use provider_config::*; pub use provider_manager::*; +pub use provider_output::*; pub use provider_ref::*; -pub use variables::*; diff --git a/packages/desktop/src/providers/network/config.rs b/packages/desktop/src/providers/network/config.rs deleted file mode 100644 index b1eda959..00000000 --- a/packages/desktop/src/providers/network/config.rs +++ /dev/null @@ -1,7 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct NetworkProviderConfig { - pub refresh_interval: u64, -} diff --git a/packages/desktop/src/providers/network/mod.rs b/packages/desktop/src/providers/network/mod.rs index a4303490..dbad22ab 100644 --- a/packages/desktop/src/providers/network/mod.rs +++ b/packages/desktop/src/providers/network/mod.rs @@ -1,8 +1,6 @@ -mod config; -mod provider; -mod variables; +mod netdev_res; +mod network_provider; mod wifi_hotspot; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use netdev_res::*; +pub use network_provider::*; diff --git a/packages/desktop/src/providers/network/variables.rs b/packages/desktop/src/providers/network/netdev_res.rs similarity index 91% rename from packages/desktop/src/providers/network/variables.rs rename to packages/desktop/src/providers/network/netdev_res.rs index 75ce76ec..f1147578 100644 --- a/packages/desktop/src/providers/network/variables.rs +++ b/packages/desktop/src/providers/network/netdev_res.rs @@ -1,15 +1,6 @@ use netdev::interface::InterfaceType as NdInterfaceType; use serde::Serialize; -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct NetworkOutput { - pub default_interface: Option, - pub default_gateway: Option, - pub interfaces: Vec, - pub traffic: NetworkTraffic, -} - #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct NetworkTraffic { diff --git a/packages/desktop/src/providers/network/provider.rs b/packages/desktop/src/providers/network/network_provider.rs similarity index 89% rename from packages/desktop/src/providers/network/provider.rs rename to packages/desktop/src/providers/network/network_provider.rs index 7ca23bf9..d12e3587 100644 --- a/packages/desktop/src/providers/network/provider.rs +++ b/packages/desktop/src/providers/network/network_provider.rs @@ -1,14 +1,14 @@ use std::sync::Arc; -use anyhow::Context; use netdev::interface::get_interfaces; +use serde::{Deserialize, Serialize}; use sysinfo::Networks; use tokio::sync::Mutex; use super::{ wifi_hotspot::{default_gateway_wifi, WifiHotstop}, - InterfaceType, NetworkGateway, NetworkInterface, NetworkOutput, - NetworkProviderConfig, NetworkTraffic, NetworkTrafficMeasure, + InterfaceType, NetworkGateway, NetworkInterface, NetworkTraffic, + NetworkTrafficMeasure, }; use crate::{ common::{to_iec_bytes, to_si_bytes}, @@ -16,6 +16,21 @@ use crate::{ providers::ProviderOutput, }; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct NetworkProviderConfig { + pub refresh_interval: u64, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct NetworkOutput { + pub default_interface: Option, + pub default_gateway: Option, + pub interfaces: Vec, + pub traffic: NetworkTraffic, +} + pub struct NetworkProvider { config: NetworkProviderConfig, netinfo: Arc>, diff --git a/packages/desktop/src/providers/config.rs b/packages/desktop/src/providers/provider_config.rs similarity index 100% rename from packages/desktop/src/providers/config.rs rename to packages/desktop/src/providers/provider_config.rs diff --git a/packages/desktop/src/providers/variables.rs b/packages/desktop/src/providers/provider_output.rs similarity index 100% rename from packages/desktop/src/providers/variables.rs rename to packages/desktop/src/providers/provider_output.rs diff --git a/packages/desktop/src/providers/weather/config.rs b/packages/desktop/src/providers/weather/config.rs deleted file mode 100644 index bc24a2d3..00000000 --- a/packages/desktop/src/providers/weather/config.rs +++ /dev/null @@ -1,9 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct WeatherProviderConfig { - pub refresh_interval: u64, - pub latitude: f32, - pub longitude: f32, -} diff --git a/packages/desktop/src/providers/weather/mod.rs b/packages/desktop/src/providers/weather/mod.rs index 1abc812f..d378d685 100644 --- a/packages/desktop/src/providers/weather/mod.rs +++ b/packages/desktop/src/providers/weather/mod.rs @@ -1,8 +1,4 @@ -mod config; mod open_meteo_res; -mod provider; -mod variables; +mod weather_provider; -pub use config::*; -pub use provider::*; -pub use variables::*; +pub use weather_provider::*; diff --git a/packages/desktop/src/providers/weather/variables.rs b/packages/desktop/src/providers/weather/variables.rs deleted file mode 100644 index 4c16a616..00000000 --- a/packages/desktop/src/providers/weather/variables.rs +++ /dev/null @@ -1,28 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct WeatherOutput { - pub is_daytime: bool, - pub status: WeatherStatus, - pub celsius_temp: f32, - pub fahrenheit_temp: f32, - pub wind_speed: f32, -} - -#[derive(Debug, Clone, PartialEq, Serialize)] -#[serde(rename_all = "snake_case")] -pub enum WeatherStatus { - ClearDay, - ClearNight, - CloudyDay, - CloudyNight, - LightRainDay, - LightRainNight, - HeavyRainDay, - HeavyRainNight, - SnowDay, - SnowNight, - ThunderDay, - ThunderNight, -} diff --git a/packages/desktop/src/providers/weather/provider.rs b/packages/desktop/src/providers/weather/weather_provider.rs similarity index 78% rename from packages/desktop/src/providers/weather/provider.rs rename to packages/desktop/src/providers/weather/weather_provider.rs index f04bf9b5..24016b5d 100644 --- a/packages/desktop/src/providers/weather/provider.rs +++ b/packages/desktop/src/providers/weather/weather_provider.rs @@ -1,11 +1,44 @@ use reqwest::Client; +use serde::{Deserialize, Serialize}; -use super::{ - open_meteo_res::OpenMeteoRes, WeatherOutput, WeatherProviderConfig, - WeatherStatus, -}; +use super::open_meteo_res::OpenMeteoRes; use crate::{impl_interval_provider, providers::ProviderOutput}; +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct WeatherProviderConfig { + pub refresh_interval: u64, + pub latitude: f32, + pub longitude: f32, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct WeatherOutput { + pub is_daytime: bool, + pub status: WeatherStatus, + pub celsius_temp: f32, + pub fahrenheit_temp: f32, + pub wind_speed: f32, +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum WeatherStatus { + ClearDay, + ClearNight, + CloudyDay, + CloudyNight, + LightRainDay, + LightRainNight, + HeavyRainDay, + HeavyRainNight, + SnowDay, + SnowNight, + ThunderDay, + ThunderNight, +} + pub struct WeatherProvider { config: WeatherProviderConfig, http_client: Client,