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

1
Cargo.lock generated
View File

@@ -2722,6 +2722,7 @@ dependencies = [
"num",
"num-derive",
"num-traits",
"random_word",
"schemars",
"serde",
"serde_json_lenient",

View File

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

View File

@@ -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,
@@ -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 {
@@ -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()
{