WIP NetworkManager tile

This commit is contained in:
Artemis Tosini 2023-12-14 23:29:46 +00:00
parent 49facf67c3
commit c0f832bcef
Signed by: artemist
GPG key ID: EE5227935FE3FF18
6 changed files with 68 additions and 2 deletions

View file

@ -12,7 +12,12 @@ fn main() {
println!("cargo:rerun-if-env-changed=DBUS_XML_PATH");
println!("cargo:rerun-if-changed=build.rs");
let required_files = HashSet::from(["org.freedesktop.hostname1.xml"]);
let required_files = HashSet::from([
"org.freedesktop.NetworkManager.AccessPoint.xml",
"org.freedesktop.NetworkManager.Connection.Active.xml",
"org.freedesktop.NetworkManager.xml",
"org.freedesktop.hostname1.xml",
]);
let required_interfaces = required_files
.iter()
.map(|name| name.strip_suffix(".xml").unwrap().to_string())

View file

@ -13,7 +13,7 @@
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
dbusPaths = lib.makeSearchPathOutput "out" "share/dbus-1/interfaces"
(with pkgs; [ systemd ]);
(with pkgs; [ systemd networkmanager ]);
in rec {
packages.rustybar = with pkgs;
rustPlatform.buildRustPackage {

View file

@ -60,6 +60,7 @@ pub enum TileConfig {
LocalTime(LocalTimeConfig),
InternetTime(InternetTimeConfig),
Iwd(IwdConfig),
NetworkManager(NetworkManagerConfig),
}
#[derive(SmartDefault, Deserialize, Clone, Debug)]
@ -151,6 +152,14 @@ pub struct InternetTimeConfig {
// No update field, update on the, uuh, wtf is metric time
}
#[derive(SmartDefault, Deserialize, Clone, Debug)]
#[serde(default)]
pub struct NetworkManagerConfig {
#[default(true)]
pub use_symbols: bool,
// No update field, we listen for events
}
#[derive(Debug, StructOpt)]
#[structopt(
name = "rustybar",
@ -209,6 +218,9 @@ pub fn launch_tile(
TileConfig::SystemTime(c) => tiles::system_time(c, output_chan).await,
TileConfig::LocalTime(c) => tiles::local_time(c, output_chan).await,
TileConfig::InternetTime(c) => tiles::internet_time(c, output_chan).await,
TileConfig::NetworkManager(c) => {
tiles::network_manager(c, output_chan, dbus_conn).await
}
};
match result {
Ok(_) => warn!("Tile {} exited without error", tile_id),

View file

@ -1,3 +1,4 @@
#![allow(clippy::needless_borrow)]
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/generated.rs"));

View file

@ -5,6 +5,7 @@ pub mod iwd;
pub mod load;
pub mod local_time;
pub mod memory;
pub mod network_manager;
pub mod system_time;
pub mod utc_time;
pub use battery::battery;
@ -14,5 +15,6 @@ pub use iwd::iwd;
pub use load::load;
pub use local_time::local_time;
pub use memory::memory;
pub use network_manager::network_manager;
pub use system_time::system_time;
pub use utc_time::utc_time;

View file

@ -0,0 +1,46 @@
use crate::config::NetworkManagerConfig;
use crate::generated::OrgFreedesktopNetworkManager;
use crate::generated::OrgFreedesktopNetworkManagerAccessPoint;
use crate::generated::OrgFreedesktopNetworkManagerConnectionActive;
use crate::output::OutputChannel;
use crate::tile::Block;
use dbus::nonblock::{Proxy, SyncConnection};
use std::sync::Arc;
use std::time::Duration;
pub async fn network_manager(
config: NetworkManagerConfig,
output: OutputChannel,
dbus_conn: Arc<SyncConnection>,
) -> eyre::Result<()> {
let root_proxy = Proxy::new(
"org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
Duration::from_secs(5),
dbus_conn.clone(),
);
let primary_connection = root_proxy.primary_connection().await?;
let primary_connection_proxy = Proxy::new(
"org.freedesktop.NetworkManager",
primary_connection,
Duration::from_secs(5),
dbus_conn.clone(),
);
let specific_object = primary_connection_proxy.specific_object().await?;
let specific_object_proxy = Proxy::new(
"org.freedesktop.NetworkManager",
specific_object,
Duration::from_secs(5),
dbus_conn.clone(),
);
let ssid = specific_object_proxy.ssid().await?;
log::warn!("got ssid: {}", String::from_utf8_lossy(&ssid));
loop {
tokio::time::sleep(Duration::from_secs(3600)).await;
}
}