guard controller set to fix hot restarts
This commit is contained in:
parent
bb9fdfa83d
commit
248c61fe63
1 changed files with 9 additions and 6 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue