adding systemtray beginnings

This commit is contained in:
Chris Cochrun 2025-05-23 10:38:10 -05:00
parent ae1c1b82af
commit 42fdbe5df1
3 changed files with 218 additions and 36 deletions

214
Cargo.lock generated
View file

@ -91,7 +91,7 @@ dependencies = [
"ndk-context",
"ndk-sys 0.6.0+11769913",
"num_enum",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -529,7 +529,7 @@ dependencies = [
"polling",
"rustix",
"slab",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -694,7 +694,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4274ea815e013e0f9f04a2633423e14194e408a0576c943ce3d14ca56c50031c"
dependencies = [
"thiserror",
"thiserror 1.0.69",
"x11rb",
]
@ -968,7 +968,7 @@ dependencies = [
"rust-ini",
"web-sys",
"winreg",
"zbus",
"zbus 4.4.0",
]
[[package]]
@ -1436,9 +1436,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
[[package]]
name = "futures-lite"
version = "2.5.0"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1"
checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532"
dependencies = [
"fastrand",
"futures-core",
@ -1590,7 +1590,7 @@ checksum = "6f56f6318968d03c18e1bcf4857ff88c61157e9da8e47c5f29055d60e1228884"
dependencies = [
"log",
"presser",
"thiserror",
"thiserror 1.0.69",
"winapi",
"windows 0.52.0",
]
@ -1670,7 +1670,7 @@ dependencies = [
"com",
"libc",
"libloading 0.8.6",
"thiserror",
"thiserror 1.0.69",
"widestring",
"winapi",
]
@ -1779,7 +1779,7 @@ dependencies = [
"iced_renderer",
"iced_widget",
"iced_winit",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -1798,7 +1798,7 @@ dependencies = [
"palette",
"rustc-hash 2.1.0",
"smol_str",
"thiserror",
"thiserror 1.0.69",
"web-time",
]
@ -1846,7 +1846,7 @@ dependencies = [
"once_cell",
"raw-window-handle",
"rustc-hash 2.1.0",
"thiserror",
"thiserror 1.0.69",
"unicode-segmentation",
]
@ -1866,7 +1866,7 @@ dependencies = [
"iced_runtime",
"layershellev",
"log",
"thiserror",
"thiserror 1.0.69",
"tracing",
"window_clipboard",
]
@ -1894,7 +1894,7 @@ dependencies = [
"iced_tiny_skia",
"iced_wgpu",
"log",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -1907,7 +1907,7 @@ dependencies = [
"iced_core",
"iced_futures",
"raw-window-handle",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -1942,7 +1942,7 @@ dependencies = [
"log",
"once_cell",
"rustc-hash 2.1.0",
"thiserror",
"thiserror 1.0.69",
"wgpu",
]
@ -1957,7 +1957,7 @@ dependencies = [
"num-traits",
"once_cell",
"rustc-hash 2.1.0",
"thiserror",
"thiserror 1.0.69",
"unicode-segmentation",
]
@ -1972,7 +1972,7 @@ dependencies = [
"iced_runtime",
"log",
"rustc-hash 2.1.0",
"thiserror",
"thiserror 1.0.69",
"tracing",
"wasm-bindgen-futures",
"web-sys",
@ -2035,7 +2035,7 @@ dependencies = [
"combine",
"jni-sys",
"log",
"thiserror",
"thiserror 1.0.69",
"walkdir",
"windows-sys 0.45.0",
]
@ -2104,7 +2104,7 @@ dependencies = [
"log",
"raw-window-handle",
"tempfile",
"thiserror",
"thiserror 1.0.69",
"waycrate_xkbkeycode",
"wayland-backend",
"wayland-client",
@ -2294,7 +2294,7 @@ dependencies = [
"supports-unicode",
"terminal_size",
"textwrap",
"thiserror",
"thiserror 1.0.69",
"unicode-width",
]
@ -2346,7 +2346,7 @@ dependencies = [
"rustc-hash 1.1.0",
"spirv",
"termcolor",
"thiserror",
"thiserror 1.0.69",
"unicode-xid",
]
@ -2362,7 +2362,7 @@ dependencies = [
"ndk-sys 0.6.0+11769913",
"num_enum",
"raw-window-handle",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -3225,7 +3225,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom",
"libredox",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -3502,6 +3502,7 @@ dependencies = [
"ron",
"serde",
"sysinfo",
"system-tray",
"tokio",
"tracing",
"tracing-subscriber",
@ -3582,7 +3583,7 @@ dependencies = [
"log",
"memmap2",
"rustix",
"thiserror",
"thiserror 1.0.69",
"wayland-backend",
"wayland-client",
"wayland-csd-frame",
@ -3765,6 +3766,20 @@ dependencies = [
"windows 0.61.1",
]
[[package]]
name = "system-tray"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3397841ed755bf361606a845779e0f7333d35fb4e39627ef6f656d7cdad4c73"
dependencies = [
"futures-lite",
"serde",
"thiserror 2.0.12",
"tokio",
"tracing",
"zbus 5.6.0",
]
[[package]]
name = "tempfile"
version = "3.14.0"
@ -3813,7 +3828,16 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [
"thiserror-impl 2.0.12",
]
[[package]]
@ -3827,6 +3851,17 @@ dependencies = [
"syn 2.0.92",
]
[[package]]
name = "thiserror-impl"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.92",
]
[[package]]
name = "thread_local"
version = "1.1.8"
@ -3935,8 +3970,10 @@ dependencies = [
"libc",
"mio",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"tracing",
"windows-sys 0.52.0",
]
@ -3965,7 +4002,7 @@ checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
dependencies = [
"indexmap",
"toml_datetime",
"winnow",
"winnow 0.6.20",
]
[[package]]
@ -4446,7 +4483,7 @@ dependencies = [
"raw-window-handle",
"rustc-hash 1.1.0",
"smallvec",
"thiserror",
"thiserror 1.0.69",
"web-sys",
"wgpu-hal",
"wgpu-types",
@ -4490,7 +4527,7 @@ dependencies = [
"renderdoc-sys",
"rustc-hash 1.1.0",
"smallvec",
"thiserror",
"thiserror 1.0.69",
"wasm-bindgen",
"web-sys",
"wgpu-types",
@ -4556,7 +4593,7 @@ dependencies = [
"clipboard_wayland",
"clipboard_x11",
"raw-window-handle",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -4954,6 +4991,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "winnow"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec"
dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.10.1"
@ -5081,9 +5127,37 @@ dependencies = [
"uds_windows",
"windows-sys 0.52.0",
"xdg-home",
"zbus_macros",
"zbus_names",
"zvariant",
"zbus_macros 4.4.0",
"zbus_names 3.0.0",
"zvariant 4.2.0",
]
[[package]]
name = "zbus"
version = "5.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2522b82023923eecb0b366da727ec883ace092e7887b61d3da5139f26b44da58"
dependencies = [
"async-broadcast",
"async-recursion",
"async-trait",
"enumflags2",
"event-listener",
"futures-core",
"futures-lite",
"hex",
"nix 0.29.0",
"ordered-stream",
"serde",
"serde_repr",
"tokio",
"tracing",
"uds_windows",
"windows-sys 0.59.0",
"winnow 0.7.10",
"zbus_macros 5.6.0",
"zbus_names 4.2.0",
"zvariant 5.5.1",
]
[[package]]
@ -5096,7 +5170,22 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.92",
"zvariant_utils",
"zvariant_utils 2.1.0",
]
[[package]]
name = "zbus_macros"
version = "5.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05d2e12843c75108c00c618c2e8ef9675b50b6ec095b36dc965f2e5aed463c15"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 2.0.92",
"zbus_names 4.2.0",
"zvariant 5.5.1",
"zvariant_utils 3.2.0",
]
[[package]]
@ -5107,7 +5196,19 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c"
dependencies = [
"serde",
"static_assertions",
"zvariant",
"zvariant 4.2.0",
]
[[package]]
name = "zbus_names"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7be68e64bf6ce8db94f63e72f0c7eb9a60d733f7e0499e628dfab0f84d6bcb97"
dependencies = [
"serde",
"static_assertions",
"winnow 0.7.10",
"zvariant 5.5.1",
]
[[package]]
@ -5147,7 +5248,21 @@ dependencies = [
"enumflags2",
"serde",
"static_assertions",
"zvariant_derive",
"zvariant_derive 4.2.0",
]
[[package]]
name = "zvariant"
version = "5.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "557e89d54880377a507c94cd5452f20e35d14325faf9d2958ebeadce0966c1b2"
dependencies = [
"endi",
"enumflags2",
"serde",
"winnow 0.7.10",
"zvariant_derive 5.5.1",
"zvariant_utils 3.2.0",
]
[[package]]
@ -5160,7 +5275,20 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.92",
"zvariant_utils",
"zvariant_utils 2.1.0",
]
[[package]]
name = "zvariant_derive"
version = "5.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "757779842a0d242061d24c28be589ce392e45350dfb9186dfd7a042a2e19870c"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 2.0.92",
"zvariant_utils 3.2.0",
]
[[package]]
@ -5173,3 +5301,17 @@ dependencies = [
"quote",
"syn 2.0.92",
]
[[package]]
name = "zvariant_utils"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e16edfee43e5d7b553b77872d99bc36afdda75c223ca7ad5e3fbecd82ca5fc34"
dependencies = [
"proc-macro2",
"quote",
"serde",
"static_assertions",
"syn 2.0.92",
"winnow 0.7.10",
]

View file

@ -23,4 +23,5 @@ iced_layershell = "0.13.0"
chrono = "0.4.39"
sysinfo = "0.35.0"
hyprland = { git = "https://github.com/hyprland-community/hyprland-rs", branch = "master" }
system-tray = "0.7.0"

View file

@ -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")
}
}