Skip to content

Commit

Permalink
feat(bar): use unique subscriber names
Browse files Browse the repository at this point in the history
This commit ensures that multiple processes of komorebi-bar.exe use
unique, randomly-suffixed subscriber names when registering with
komorebi.
  • Loading branch information
LGUG2Z committed Oct 4, 2024
1 parent 216154b commit 2d1613b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions komorebi-bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ netdev = "0.31"
num = "0.4.3"
num-derive = "0.4.2"
num-traits = "0.2.19"
random_word = { version = "0.4.3", features = ["en"] }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
15 changes: 9 additions & 6 deletions komorebi-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ fn main() -> color_eyre::Result<()> {
.with_decorations(false)
// .with_transparent(config.transparent)
.with_taskbar(false)
.with_position(Position { x: 0.0, y: 0.0 })
.with_position(Position {
x: state.monitors.elements()[config.monitor.index].size().left as f32,
y: state.monitors.elements()[config.monitor.index].size().top as f32,
})
.with_inner_size({
Position {
x: state.monitors.elements()[config.monitor.index].size().right as f32,
Expand Down Expand Up @@ -239,10 +242,12 @@ fn main() -> color_eyre::Result<()> {

let ctx_komorebi = cc.egui_ctx.clone();
std::thread::spawn(move || {
let listener = komorebi_client::subscribe("komorebi-bar")
let subscriber_name = format!("komorebi-bar-{}", random_word::gen(random_word::Lang::En));

let listener = komorebi_client::subscribe(&subscriber_name)
.expect("could not subscribe to komorebi notifications");

tracing::info!("subscribed to komorebi notifications: \"komorebi-bar\"");
tracing::info!("subscribed to komorebi notifications: \"{}\"", subscriber_name);

for client in listener.incoming() {
match client {
Expand All @@ -256,9 +261,7 @@ fn main() -> color_eyre::Result<()> {

// keep trying to reconnect to komorebi
while komorebi_client::send_message(
&SocketMessage::AddSubscriberSocket(String::from(
"komorebi-bar",
)),
&SocketMessage::AddSubscriberSocket(subscriber_name.clone()),
)
.is_err()
{
Expand Down

0 comments on commit 2d1613b

Please sign in to comment.