fix(cosmic-toplevel): deactivate plugin if not in a COSMIC session

This commit is contained in:
Michael Aaron Murphy 2023-02-06 19:25:06 +01:00 committed by Michael Murphy
parent 0b8e385f36
commit 35e313fa18

View file

@ -24,7 +24,14 @@ use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
pub async fn main() {
tracing::info!("starting cosmic-toplevel");
let (mut app, mut toplevel_rx) = App::new(async_stdout());
let mut tx = async_stdout();
if session_is_cosmic() {
send(&mut tx, PluginResponse::Deactivate).await;
return;
}
let (mut app, mut toplevel_rx) = App::new(tx);
let mut requests = json_input_stream(async_stdin());
let mut next_request = requests.next();
@ -94,7 +101,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
fn new(tx: W) -> (Self, mpsc::UnboundedReceiver<ToplevelEvent>) {
let (toplevels_tx, toplevel_rx) = mpsc::unbounded();
let (calloop_tx, calloop_rx) = calloop::channel::channel();
let _ = std::thread::spawn(move || toplevel_handler(toplevels_tx, calloop_rx));
let _handle = std::thread::spawn(move || toplevel_handler(toplevels_tx, calloop_rx));
(
Self {
@ -123,7 +130,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
}
}) {
tracing::info!("activating: {id}");
let _ = self.calloop_tx.send(ToplevelAction::Activate(handle));
let _res = self.calloop_tx.send(ToplevelAction::Activate(handle));
}
}
@ -138,7 +145,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
None
}
}) {
let _ = self.calloop_tx.send(ToplevelAction::Close(handle));
let _res = self.calloop_tx.send(ToplevelAction::Close(handle));
}
}
@ -197,3 +204,12 @@ impl<W: AsyncWrite + Unpin> App<W> {
let _ = self.tx.flush();
}
}
#[must_use]
fn session_is_cosmic() -> bool {
if let Ok(var) = std::env::var("XDG_CURRENT_DESKTOP") {
return var.contains("COSMIC");
}
false
}