adding systemtray beginnings
This commit is contained in:
parent
ae1c1b82af
commit
42fdbe5df1
3 changed files with 218 additions and 36 deletions
39
src/main.rs
39
src/main.rs
|
@ -1,4 +1,6 @@
|
|||
use std::cmp;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::fs::read_to_string;
|
||||
|
||||
use chrono::prelude::*;
|
||||
|
@ -21,6 +23,8 @@ use iced_layershell::to_layer_message;
|
|||
use iced_runtime::futures::event;
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use sysinfo::{Disks, System};
|
||||
use system_tray::item::StatusNotifierItem;
|
||||
use system_tray::menu::TrayMenu;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing::{debug, error};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
@ -78,6 +82,7 @@ struct Panel {
|
|||
workspaces: Vec<Workspace>,
|
||||
active_workspace: i32,
|
||||
active_window: String,
|
||||
system_tray: Option<SystemTray>,
|
||||
apps: Vec<String>,
|
||||
}
|
||||
|
||||
|
@ -119,6 +124,7 @@ impl Panel {
|
|||
apps: vec![String::new()],
|
||||
active_window,
|
||||
battery,
|
||||
system_tray: None,
|
||||
},
|
||||
Task::none(),
|
||||
)
|
||||
|
@ -137,6 +143,7 @@ impl Panel {
|
|||
// let used_space = disk.available_space() - disk.total_space();
|
||||
let disk = self.disks.first_mut();
|
||||
if let Some(disk) = disk {
|
||||
disk.refresh();
|
||||
self.disk = format!(
|
||||
" {}",
|
||||
convert((disk.total_space() - disk.available_space()) as f64)
|
||||
|
@ -426,3 +433,35 @@ enum BatteryStatus {
|
|||
Charged,
|
||||
Draining,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SystemTray {
|
||||
client: system_tray::client::Client,
|
||||
items: HashMap<String, (StatusNotifierItem, Option<TrayMenu>)>,
|
||||
}
|
||||
|
||||
impl SystemTray {
|
||||
async fn new() -> Result<Self> {
|
||||
let client = system_tray::client::Client::new().await.into_diagnostic()?;
|
||||
let items = client.items();
|
||||
let items = items
|
||||
.lock()
|
||||
.map_err(|_| SystemTrayError::SomeError)
|
||||
.into_diagnostic()?
|
||||
.clone();
|
||||
Ok(Self { client, items })
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum SystemTrayError {
|
||||
SomeError,
|
||||
}
|
||||
|
||||
impl std::error::Error for SystemTrayError {}
|
||||
|
||||
impl Display for SystemTrayError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "SystemTrayError::SomeError")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue