Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit 1a0d693

Browse files
committed
fixed stray not working having dbus connection error by using stray of github in project
1 parent cc287ac commit 1a0d693

24 files changed

+1786
-46
lines changed

Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ categories = ["accessibility", "command-line" ]
1515

1616
[dependencies]
1717
gtk = { version = "0.17.0", package = "gtk" }
18-
tokio = { version = "1", features = ["full"] }
18+
tokio = { version = "1.26.0", features = ["full"] }
1919
gtk-layer-shell = "0.6.1"
2020
json = "0.12.4"
2121
glib = "0.18.1"
2222
regex = "1.9.3"
2323
tokio-uds = "0.2"
24-
upower_dbus = "0.3.2"
25-
futures = "0.3.28"
26-
zbus = "3.14.1"
2724
inotify = "0.10.2"
25+
stray = {path = "stray"}
26+
once_cell = "1.18.0"

examples/helium.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@
33
"align":"top",
44
"background":"#000000",
55
"widgets":{
6-
"time":{
6+
"battery":{
77
"format":" {percentage} %",
88
"type":"battery",
99
"is_json":false,
1010
"align":"left",
1111
"refresh-rate":1
1212
},
13-
"cpu":{
13+
"brightness":{
1414
"format":"󰃜 {} %",
15-
"align":"center",
15+
"align":"left",
1616
"type":"brightness",
1717
"refresh-rate":1
1818
},
19-
"ram":{
19+
20+
"tray":{
21+
"type":"tray",
22+
"align":"right"
23+
},
24+
"hyprland":{
2025
"format":"󱂬 {workspace}:{activewindow}",
2126
"type":"hyprland",
22-
"align":"right"
27+
"align":"center"
2328

2429
}
25-
2630

2731
}
2832

examples/style.css

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
.root{
2-
font-size:13px;
3-
margin-top:10px;
4-
padding: 1px;
2+
font-size:15px;
3+
/* margin-top:10px; */
4+
padding:5px 5px;
55
}
66

7-
.time,.cpu,.ram{
7+
.battery,.brightness,.tray,.hyprland{
88
background-color:#5c5f77;
99
padding:8px 20px;
1010
border-radius:7px;
1111
color:white;
1212
}
1313

14-
.toggle{
15-
background-color:#a832a4;
16-
font-size:20px;
17-
color:red;
18-
padding:5px 30px;
14+
.battery{
15+
border-radius:7px 0 0 7px;
16+
padding-right:5px;
1917
}
20-
21-
22-
.root{
23-
padding:5px 5px;
18+
.brightness{
19+
border-radius:0px 7px 7px 0;
20+
padding-left:5px;
2421
}
2522

23+

src/builder/widgets_builder.rs

+3
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,15 @@ fn handle_builtin_widgets(
166166
config: WidgetConfig,
167167
type_of_widget: &String,
168168
) {
169+
// println!("{}", type_of_widget);
169170
if type_of_widget == "hyprland" {
170171
modules::hyprland::build_label(&left, &centered, &right, config);
171172
} else if type_of_widget == "battery" {
172173
modules::battery::build_label(left, &centered, &right, config);
173174
} else if type_of_widget == "brightness" {
174175
modules::brightness::build_label(left, &centered, &right, config);
176+
} else if type_of_widget == "tray" {
177+
modules::tray::build_label(left, centered, right, config);
175178
}
176179
}
177180

src/main.rs

+44-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,61 @@ mod utils;
66
mod widgets;
77

88
use gtk::prelude::{ApplicationExt, ApplicationExtManual};
9+
use utils::command::run;
910

1011
use crate::builder::layer_builder::build_ui;
11-
use std::{path::Path, sync::mpsc::channel, time::Duration};
12-
12+
use stray::{
13+
message::{
14+
menu::{MenuType, TrayMenu},
15+
tray::{IconPixmap, StatusNotifierItem},
16+
NotifierItemCommand,
17+
},
18+
NotifierItemMessage, StatusNotifierWatcher,
19+
};
1320
fn main() -> gtk::glib::ExitCode {
1421
const APP_ID: &str = "com.heliumbar";
1522

1623
let app = gtk::Application::builder().application_id(APP_ID).build();
1724
// println!("{:?}", std::thread::current().id().to_owned());
1825
app.connect_activate(build_ui);
19-
26+
// tray();
2027
app.run()
2128
} //main
2229

30+
fn tray() {
31+
let (_sender, receiver) = tokio::sync::mpsc::channel(50);
32+
33+
std::thread::spawn(move || {
34+
let tokio_runtime = tokio::runtime::Runtime::new().unwrap();
35+
36+
tokio_runtime.block_on(async {
37+
let watcher = StatusNotifierWatcher::new(receiver).await.unwrap();
38+
39+
let mut notifier_host = watcher.create_notifier_host("Hybrid").await;
40+
if let Err(err) = notifier_host {
41+
println!("Error::{}", err);
42+
return;
43+
}
44+
let mut notifier_host = notifier_host.unwrap();
45+
while let Ok(msg) = notifier_host.recv().await {
46+
match msg {
47+
NotifierItemMessage::Update {
48+
address,
49+
item,
50+
menu,
51+
} => {
52+
println!("update:{}{:?}", address, (*item).icon_name);
53+
} //on update,
54+
NotifierItemMessage::Remove { address } => {
55+
println!("Removed:{}", address);
56+
} //remove
57+
} //match msg
58+
} //while
59+
}) //runtime async fun
60+
});
61+
}
62+
63+
////////////////////////
2364
fn watcher_file() {
2465
let path = "/sys/class/backlight/amdgpu_bl1/brightness";
2566
let mut inotify = inotify::Inotify::init().unwrap();

src/modules/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
pub mod hyprland;
2-
pub mod power;
3-
pub use power::*;
41
pub mod battery;
52
pub mod brightness;
3+
pub mod hyprland;
4+
pub mod tray;

src/modules/power.rs

-17
This file was deleted.

0 commit comments

Comments
 (0)