From 6efad71f0e7ec9aee88bb60a85389ed32e407eb7 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 20 Aug 2021 18:44:22 +0200 Subject: [PATCH] feat: Allow plugins to signal to deactivate themselves Necessary when a plugin is unsupported --- plugins/src/pop_shell/mod.rs | 6 +++++- service/src/lib.rs | 6 ++++++ src/lib.rs | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/src/pop_shell/mod.rs b/plugins/src/pop_shell/mod.rs index 10e3692..39be4b1 100644 --- a/plugins/src/pop_shell/mod.rs +++ b/plugins/src/pop_shell/mod.rs @@ -25,7 +25,11 @@ impl Type for Item { pub async fn main() { let connection = match Connection::new_session() { Ok(conn) => conn, - Err(_) => return, + Err(_) => { + let mut out = async_stdout(); + let _ = crate::send(&mut out, PluginResponse::Deactivate); + return; + } }; let mut app = App::new(connection, async_stdout()); diff --git a/service/src/lib.rs b/service/src/lib.rs index 3e8330b..21c936f 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -139,6 +139,12 @@ impl Service { gpu_preference, }); } + + // Report the plugin as finished and remove it from future polling + PluginResponse::Deactivate => { + self.finished(plugin).await; + let _ = self.plugins.remove(plugin); + } }, // When a plugin has exited, the sender attached to the plugin will be dropped diff --git a/src/lib.rs b/src/lib.rs index d0e829e..dcfb1bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,11 +72,13 @@ pub enum PluginResponse { Clear, /// Close the launcher. Close, - // Additional options for launching a certain item + // Additional options for launching a certain item. Context { id: Indice, options: Vec, }, + /// Instruct the launcher service to deactivate this plugin. + Deactivate, // Notifies that a .desktop entry should be launched by the frontend. DesktopEntry { path: PathBuf,