guard controller set to fix hot restarts

This commit is contained in:
Henry Hiles 2026-04-21 11:22:33 -04:00
commit 248c61fe63
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -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<Sender<u32>> = OnceLock::new();
static CONTROLLER: OnceLock<Mutex<Option<Sender<u32>>>> = OnceLock::new();
fn controller() -> &'static Mutex<Option<Sender<u32>>> {
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<Vec<Vec<Workspace>>>) -> Result<()> {
let (tx, rx): (Sender<u32>, Channel<u32>) = channel();
CONTROLLER.set(tx).unwrap();
*controller().lock().unwrap() = Some(tx);
let connection = Connection::connect_to_env().unwrap();
let event_queue = connection.new_event_queue();