Skip to content

Commit 35e313f

Browse files
committed
fix(cosmic-toplevel): deactivate plugin if not in a COSMIC session
1 parent 0b8e385 commit 35e313f

File tree

1 file changed

+20
-4
lines changed
  • plugins/src/cosmic_toplevel

1 file changed

+20
-4
lines changed

plugins/src/cosmic_toplevel/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
2424
pub async fn main() {
2525
tracing::info!("starting cosmic-toplevel");
2626

27-
let (mut app, mut toplevel_rx) = App::new(async_stdout());
27+
let mut tx = async_stdout();
28+
29+
if session_is_cosmic() {
30+
send(&mut tx, PluginResponse::Deactivate).await;
31+
return;
32+
}
33+
34+
let (mut app, mut toplevel_rx) = App::new(tx);
2835

2936
let mut requests = json_input_stream(async_stdin());
3037
let mut next_request = requests.next();
@@ -94,7 +101,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
94101
fn new(tx: W) -> (Self, mpsc::UnboundedReceiver<ToplevelEvent>) {
95102
let (toplevels_tx, toplevel_rx) = mpsc::unbounded();
96103
let (calloop_tx, calloop_rx) = calloop::channel::channel();
97-
let _ = std::thread::spawn(move || toplevel_handler(toplevels_tx, calloop_rx));
104+
let _handle = std::thread::spawn(move || toplevel_handler(toplevels_tx, calloop_rx));
98105

99106
(
100107
Self {
@@ -123,7 +130,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
123130
}
124131
}) {
125132
tracing::info!("activating: {id}");
126-
let _ = self.calloop_tx.send(ToplevelAction::Activate(handle));
133+
let _res = self.calloop_tx.send(ToplevelAction::Activate(handle));
127134
}
128135
}
129136

@@ -138,7 +145,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
138145
None
139146
}
140147
}) {
141-
let _ = self.calloop_tx.send(ToplevelAction::Close(handle));
148+
let _res = self.calloop_tx.send(ToplevelAction::Close(handle));
142149
}
143150
}
144151

@@ -197,3 +204,12 @@ impl<W: AsyncWrite + Unpin> App<W> {
197204
let _ = self.tx.flush();
198205
}
199206
}
207+
208+
#[must_use]
209+
fn session_is_cosmic() -> bool {
210+
if let Ok(var) = std::env::var("XDG_CURRENT_DESKTOP") {
211+
return var.contains("COSMIC");
212+
}
213+
214+
false
215+
}

0 commit comments

Comments
 (0)