From 248c61fe63b1b2ceaa6b1b8ef2bcd89758a7ec2b Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Tue, 21 Apr 2026 11:22:33 -0400 Subject: [PATCH] guard controller set to fix hot restarts --- rust/src/api/workspace_api.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rust/src/api/workspace_api.rs b/rust/src/api/workspace_api.rs index 46bc884..fadd9da 100644 --- a/rust/src/api/workspace_api.rs +++ b/rust/src/api/workspace_api.rs @@ -1,5 +1,5 @@ use crate::{frb_generated::StreamSink, internal::wayland::AppState}; -use std::{collections::HashMap, sync::OnceLock}; +use std::{collections::HashMap, sync::{Mutex, OnceLock}}; use serde_json::Result; use calloop::{ @@ -10,7 +10,10 @@ use calloop_wayland_source::WaylandSource; use wayland_client::Connection; -static CONTROLLER: OnceLock> = OnceLock::new(); +static CONTROLLER: OnceLock>>> = OnceLock::new(); +fn controller() -> &'static Mutex>> { + CONTROLLER.get_or_init(|| Mutex::new(None)) +} #[derive(Clone)] pub struct Workspace { @@ -21,15 +24,15 @@ pub struct Workspace { impl Workspace { pub fn activate(&self) { - if let Some(tx) = CONTROLLER.get() { - tx.send(self.id).expect("Sending activate command failed"); - } + if let Some(tx) = controller().lock().unwrap().as_ref() { + let _ = tx.send(self.id); + } } } pub fn listen_workspaces(sink: StreamSink>>) -> Result<()> { let (tx, rx): (Sender, Channel) = channel(); - CONTROLLER.set(tx).unwrap(); + *controller().lock().unwrap() = Some(tx); let connection = Connection::connect_to_env().unwrap(); let event_queue = connection.new_event_queue();