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 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 serde_json::Result;
|
||||||
|
|
||||||
use calloop::{
|
use calloop::{
|
||||||
|
|
@ -10,7 +10,10 @@ use calloop_wayland_source::WaylandSource;
|
||||||
|
|
||||||
use wayland_client::Connection;
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct Workspace {
|
pub struct Workspace {
|
||||||
|
|
@ -21,15 +24,15 @@ pub struct Workspace {
|
||||||
|
|
||||||
impl Workspace {
|
impl Workspace {
|
||||||
pub fn activate(&self) {
|
pub fn activate(&self) {
|
||||||
if let Some(tx) = CONTROLLER.get() {
|
if let Some(tx) = controller().lock().unwrap().as_ref() {
|
||||||
tx.send(self.id).expect("Sending activate command failed");
|
let _ = tx.send(self.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listen_workspaces(sink: StreamSink<Vec<Vec<Workspace>>>) -> Result<()> {
|
pub fn listen_workspaces(sink: StreamSink<Vec<Vec<Workspace>>>) -> Result<()> {
|
||||||
let (tx, rx): (Sender<u32>, Channel<u32>) = channel();
|
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 connection = Connection::connect_to_env().unwrap();
|
||||||
let event_queue = connection.new_event_queue();
|
let event_queue = connection.new_event_queue();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue