Compare commits
No commits in common. "2be0d5665508b27d1c129adba961ad67ae21d16e" and "a0d19b870c0a14ee5e6db84aba3eaa50ec69f532" have entirely different histories.
2be0d56655
...
a0d19b870c
@ -13,7 +13,7 @@ pub struct UnibarModuleMusic {
|
|||||||
|
|
||||||
impl UnibarModuleMusic {
|
impl UnibarModuleMusic {
|
||||||
// --------------------
|
// --------------------
|
||||||
pub fn new(o :common::AppOptions) -> Self {
|
pub fn new(o :common::AppOptions) -> UnibarModuleMusic {
|
||||||
UnibarModuleMusic {
|
UnibarModuleMusic {
|
||||||
opts: o,
|
opts: o,
|
||||||
current_stdout: "".to_string(),
|
current_stdout: "".to_string(),
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
use serde_json::json;
|
|
||||||
use serde_json::Value;
|
|
||||||
use std::process::{Stdio, Command};
|
|
||||||
|
|
||||||
use crate::common;
|
|
||||||
use crate::bar_modules;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct UnibarModuleNetwork {
|
|
||||||
opts: common::AppOptions,
|
|
||||||
ip_addr_stdout: String,
|
|
||||||
network_info: Value,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UnibarModuleNetwork {
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
pub fn new(o :common::AppOptions) -> Self {
|
|
||||||
UnibarModuleNetwork {
|
|
||||||
opts: o,
|
|
||||||
ip_addr_stdout: "".to_string(),
|
|
||||||
network_info: json!(serde_json::Value::Null),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl bar_modules::BarModuleActions for UnibarModuleNetwork {
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
fn generate_data(&mut self) {
|
|
||||||
// Output of 'ip -j address' command has network information
|
|
||||||
let ip_addr_output = Command::new("ip")
|
|
||||||
.arg("-j") // Output in json format
|
|
||||||
.arg("address")
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
self.ip_addr_stdout = String::from_utf8(ip_addr_output.stdout).unwrap();
|
|
||||||
self.ip_addr_stdout.pop();
|
|
||||||
|
|
||||||
self.network_info = serde_json::from_str::<Value>(self.ip_addr_stdout.as_str()).unwrap();
|
|
||||||
if self.opts.debug_json {
|
|
||||||
println!("-----> ip_addr - {:#?}", self.network_info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
fn get_content(&self) -> String {
|
|
||||||
if let Some(interfaces) = self.network_info.as_array() {
|
|
||||||
let up_intf :Vec<_> = interfaces.iter()
|
|
||||||
.filter(|el| el["operstate"].as_str().unwrap().contains("UP"))
|
|
||||||
.cloned().collect();
|
|
||||||
if up_intf.len() > 0 {
|
|
||||||
let inet_addr :Vec<_> = up_intf[0]["addr_info"].as_array().unwrap().iter()
|
|
||||||
.filter(|ai| ai["scope"].as_str().unwrap().contains("global"))
|
|
||||||
.cloned().collect();
|
|
||||||
if inet_addr.len() > 0 {
|
|
||||||
if self.opts.debug_json {
|
|
||||||
println!("-----> Inet Addr - {:#?}", inet_addr);
|
|
||||||
}
|
|
||||||
return inet_addr[0]["local"].as_str().unwrap().to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "None".to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
fn get_icon(&self) -> String {
|
|
||||||
if let Some(interfaces) = self.network_info.as_array() {
|
|
||||||
let up_intf :Vec<_> = interfaces.iter()
|
|
||||||
.filter(|el| el["operstate"].as_str().unwrap().contains("UP"))
|
|
||||||
.cloned().collect();
|
|
||||||
if up_intf.len() > 0 {
|
|
||||||
return "📶".to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "🌎".to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl bar_modules::BarModuleDebug for UnibarModuleNetwork {
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
fn post_debug(&self) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,7 +16,7 @@ pub struct UnibarModuleWeather {
|
|||||||
impl UnibarModuleWeather {
|
impl UnibarModuleWeather {
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
pub fn new(o :common::AppOptions) -> Self {
|
pub fn new(o :common::AppOptions) -> UnibarModuleWeather {
|
||||||
UnibarModuleWeather {
|
UnibarModuleWeather {
|
||||||
opts: o,
|
opts: o,
|
||||||
weather_info: json!(serde_json::Value::Null),
|
weather_info: json!(serde_json::Value::Null),
|
||||||
|
@ -19,4 +19,3 @@ pub trait BarModuleDebug {
|
|||||||
|
|
||||||
pub mod bar_module_weather;
|
pub mod bar_module_weather;
|
||||||
pub mod bar_module_music;
|
pub mod bar_module_music;
|
||||||
pub mod bar_module_network;
|
|
||||||
|
@ -40,6 +40,7 @@ struct CommandlineArgs {
|
|||||||
//
|
//
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Unibar {
|
struct Unibar {
|
||||||
|
// acts :UnibarActions
|
||||||
opts: common::AppOptions,
|
opts: common::AppOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +56,6 @@ impl Unibar {
|
|||||||
let bar_modules_enabled: Vec<Box<dyn bar_modules::BarModuleActions>> = vec! [
|
let bar_modules_enabled: Vec<Box<dyn bar_modules::BarModuleActions>> = vec! [
|
||||||
Box::new(bar_modules::bar_module_weather::UnibarModuleWeather::new(self.opts.clone())),
|
Box::new(bar_modules::bar_module_weather::UnibarModuleWeather::new(self.opts.clone())),
|
||||||
Box::new(bar_modules::bar_module_music::UnibarModuleMusic::new(self.opts.clone())),
|
Box::new(bar_modules::bar_module_music::UnibarModuleMusic::new(self.opts.clone())),
|
||||||
Box::new(bar_modules::bar_module_network::UnibarModuleNetwork::new(self.opts.clone())),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Get module's part to be displayed in the bar
|
// Get module's part to be displayed in the bar
|
||||||
@ -82,7 +82,6 @@ impl Unibar {
|
|||||||
let bar_modules_debugged: Vec<Box<dyn bar_modules::BarModuleDebug>> = vec! [
|
let bar_modules_debugged: Vec<Box<dyn bar_modules::BarModuleDebug>> = vec! [
|
||||||
Box::new(bar_modules::bar_module_weather::UnibarModuleWeather::new(self.opts.clone())),
|
Box::new(bar_modules::bar_module_weather::UnibarModuleWeather::new(self.opts.clone())),
|
||||||
Box::new(bar_modules::bar_module_music::UnibarModuleMusic::new(self.opts.clone())),
|
Box::new(bar_modules::bar_module_music::UnibarModuleMusic::new(self.opts.clone())),
|
||||||
Box::new(bar_modules::bar_module_network::UnibarModuleNetwork::new(self.opts.clone())),
|
|
||||||
];
|
];
|
||||||
for md in bar_modules_debugged {
|
for md in bar_modules_debugged {
|
||||||
md.post_debug();
|
md.post_debug();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user