Skip to content

Commit

Permalink
feat: add target_os conditional compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Feb 27, 2024
1 parent 55ece4f commit 43e4d79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
7 changes: 5 additions & 2 deletions packages/desktop/src/providers/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use serde::Deserialize;

#[cfg(windows)]
use super::komorebi::KomorebiProviderConfig;
use super::{
battery::BatteryProviderConfig, cpu::CpuProviderConfig,
host::HostProviderConfig, ip::IpProviderConfig,
komorebi::KomorebiProviderConfig, memory::MemoryProviderConfig,
network::NetworkProviderConfig, weather::WeatherProviderConfig,
memory::MemoryProviderConfig, network::NetworkProviderConfig,
weather::WeatherProviderConfig,
};

#[derive(Deserialize, Debug)]
Expand All @@ -14,6 +16,7 @@ pub enum ProviderConfig {
Cpu(CpuProviderConfig),
Host(HostProviderConfig),
Ip(IpProviderConfig),
#[cfg(windows)]
Komorebi(KomorebiProviderConfig),
Memory(MemoryProviderConfig),
Network(NetworkProviderConfig),
Expand Down
13 changes: 9 additions & 4 deletions packages/desktop/src/providers/manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use serde::Serialize;
use sysinfo::System;
use tauri::{App, AppHandle, Manager, Runtime};
Expand All @@ -15,11 +15,13 @@ use tracing::info;

use crate::providers::provider::Provider;

#[cfg(windows)]
use super::komorebi::KomorebiProvider;
use super::{
battery::BatteryProvider, config::ProviderConfig, cpu::CpuProvider,
host::HostProvider, ip::IpProvider, komorebi::KomorebiProvider,
memory::MemoryProvider, network::NetworkProvider,
variables::ProviderVariables, weather::WeatherProvider,
host::HostProvider, ip::IpProvider, memory::MemoryProvider,
network::NetworkProvider, variables::ProviderVariables,
weather::WeatherProvider,
};

pub struct ListenProviderArgs {
Expand Down Expand Up @@ -167,6 +169,7 @@ fn create_provider(
Box::new(HostProvider::new(config, sysinfo))
}
ProviderConfig::Ip(config) => Box::new(IpProvider::new(config)),
#[cfg(windows)]
ProviderConfig::Komorebi(config) => {
Box::new(KomorebiProvider::new(config))
}
Expand All @@ -179,6 +182,8 @@ fn create_provider(
ProviderConfig::Weather(config) => {
Box::new(WeatherProvider::new(config))
}
#[allow(unreachable_patterns)]
_ => bail!("Provider not supported on this operating system."),
};

Ok(provider)
Expand Down
1 change: 1 addition & 0 deletions packages/desktop/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod cpu;
pub mod host;
pub mod interval_provider;
pub mod ip;
#[cfg(windows)]
pub mod komorebi;
pub mod manager;
pub mod memory;
Expand Down
7 changes: 5 additions & 2 deletions packages/desktop/src/providers/variables.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use serde::Serialize;

#[cfg(windows)]
use super::komorebi::KomorebiVariables;
use super::{
battery::BatteryVariables, cpu::CpuVariables, host::HostVariables,
ip::IpVariables, komorebi::KomorebiVariables, memory::MemoryVariables,
network::NetworkVariables, weather::WeatherVariables,
ip::IpVariables, memory::MemoryVariables, network::NetworkVariables,
weather::WeatherVariables,
};

#[derive(Serialize, Debug, Clone)]
Expand All @@ -13,6 +15,7 @@ pub enum ProviderVariables {
Cpu(CpuVariables),
Host(HostVariables),
Ip(IpVariables),
#[cfg(windows)]
Komorebi(KomorebiVariables),
Memory(MemoryVariables),
Network(NetworkVariables),
Expand Down

0 comments on commit 43e4d79

Please sign in to comment.