feat(bar): use unique subscriber names

This commit ensures that multiple processes of komorebi-bar.exe use
unique, randomly-suffixed subscriber names when registering with
komorebi.
This commit is contained in:
LGUG2Z
2024-10-04 15:22:38 -07:00
parent 216154b975
commit 2d1613b4d9
3 changed files with 11 additions and 6 deletions
Generated
+1
View File
@@ -2722,6 +2722,7 @@ dependencies = [
"num", "num",
"num-derive", "num-derive",
"num-traits", "num-traits",
"random_word",
"schemars", "schemars",
"serde", "serde",
"serde_json_lenient", "serde_json_lenient",
+1
View File
@@ -24,6 +24,7 @@ netdev = "0.31"
num = "0.4.3" num = "0.4.3"
num-derive = "0.4.2" num-derive = "0.4.2"
num-traits = "0.2.19" num-traits = "0.2.19"
random_word = { version = "0.4.3", features = ["en"] }
schemars = { workspace = true } schemars = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
+9 -6
View File
@@ -161,7 +161,10 @@ fn main() -> color_eyre::Result<()> {
.with_decorations(false) .with_decorations(false)
// .with_transparent(config.transparent) // .with_transparent(config.transparent)
.with_taskbar(false) .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({ .with_inner_size({
Position { Position {
x: state.monitors.elements()[config.monitor.index].size().right as f32, x: state.monitors.elements()[config.monitor.index].size().right as f32,
@@ -239,10 +242,12 @@ fn main() -> color_eyre::Result<()> {
let ctx_komorebi = cc.egui_ctx.clone(); let ctx_komorebi = cc.egui_ctx.clone();
std::thread::spawn(move || { 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"); .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() { for client in listener.incoming() {
match client { match client {
@@ -256,9 +261,7 @@ fn main() -> color_eyre::Result<()> {
// keep trying to reconnect to komorebi // keep trying to reconnect to komorebi
while komorebi_client::send_message( while komorebi_client::send_message(
&SocketMessage::AddSubscriberSocket(String::from( &SocketMessage::AddSubscriberSocket(subscriber_name.clone()),
"komorebi-bar",
)),
) )
.is_err() .is_err()
{ {