diff --git a/espanso/src/cli/worker/builtin/debug.rs b/espanso/src/cli/worker/builtin/debug.rs
index 00284a7..2074528 100644
--- a/espanso/src/cli/worker/builtin/debug.rs
+++ b/espanso/src/cli/worker/builtin/debug.rs
@@ -17,7 +17,10 @@
* along with espanso. If not, see .
*/
-use crate::{cli::worker::builtin::generate_next_builtin_id, engine::event::{EventType, effect::{TextInjectRequest}}};
+use crate::{
+ cli::worker::builtin::generate_next_builtin_id,
+ engine::event::{effect::TextInjectRequest, EventType},
+};
use super::BuiltInMatch;
@@ -37,4 +40,27 @@ pub fn create_match_paste_active_config_info() -> BuiltInMatch {
})
},
}
-}
\ No newline at end of file
+}
+
+pub fn create_match_paste_active_app_info() -> BuiltInMatch {
+ BuiltInMatch {
+ id: generate_next_builtin_id(),
+ label: "Paste active application information (detect)",
+ triggers: vec!["#detect#".to_string()],
+ action: |context| {
+ let info = context.get_active_app_info();
+
+ let dump = format!(
+ "title: '{}'\nexec: '{}'\nclass: '{}'",
+ info.title.unwrap_or_default(),
+ info.exec.unwrap_or_default(),
+ info.class.unwrap_or_default()
+ );
+
+ EventType::TextInject(TextInjectRequest {
+ text: dump,
+ force_mode: None,
+ })
+ },
+ }
+}
diff --git a/espanso/src/cli/worker/builtin/mod.rs b/espanso/src/cli/worker/builtin/mod.rs
index ae0b753..39a6794 100644
--- a/espanso/src/cli/worker/builtin/mod.rs
+++ b/espanso/src/cli/worker/builtin/mod.rs
@@ -37,6 +37,7 @@ pub struct BuiltInMatch {
pub fn get_builtin_matches() -> Vec {
vec![
debug::create_match_paste_active_config_info(),
+ debug::create_match_paste_active_app_info(),
]
}
diff --git a/espanso/src/cli/worker/context/default.rs b/espanso/src/cli/worker/context/default.rs
index 7e09be9..e5f323e 100644
--- a/espanso/src/cli/worker/context/default.rs
+++ b/espanso/src/cli/worker/context/default.rs
@@ -17,16 +17,25 @@
* along with espanso. If not, see .
*/
+use espanso_info::AppInfoProvider;
+
use super::*;
use crate::cli::worker::config::ConfigManager;
pub struct DefaultContext<'a> {
config_manager: &'a ConfigManager<'a>,
+ app_info_provider: &'a dyn AppInfoProvider,
}
impl<'a> DefaultContext<'a> {
- pub fn new(config_manager: &'a ConfigManager<'a>) -> Self {
- Self { config_manager }
+ pub fn new(
+ config_manager: &'a ConfigManager<'a>,
+ app_info_provider: &'a dyn AppInfoProvider,
+ ) -> Self {
+ Self {
+ config_manager,
+ app_info_provider,
+ }
}
}
@@ -41,3 +50,9 @@ impl<'a> ConfigContext for DefaultContext<'a> {
self.config_manager.active()
}
}
+
+impl<'a> AppInfoContext for DefaultContext<'a> {
+ fn get_active_app_info(&self) -> AppInfo {
+ self.app_info_provider.get_info()
+ }
+}
diff --git a/espanso/src/cli/worker/context/mod.rs b/espanso/src/cli/worker/context/mod.rs
index 41eefde..ffa034b 100644
--- a/espanso/src/cli/worker/context/mod.rs
+++ b/espanso/src/cli/worker/context/mod.rs
@@ -23,10 +23,15 @@ use espanso_config::config::Config;
mod default;
pub use default::DefaultContext;
+use espanso_info::{AppInfo};
-pub trait Context: ConfigContext {}
+pub trait Context: ConfigContext + AppInfoContext {}
pub trait ConfigContext {
fn get_default_config(&self) -> Arc;
fn get_active_config(&self) -> Arc;
+}
+
+pub trait AppInfoContext {
+ fn get_active_app_info(&self) -> AppInfo;
}
\ No newline at end of file
diff --git a/espanso/src/cli/worker/engine/mod.rs b/espanso/src/cli/worker/engine/mod.rs
index f4c9a4a..c919457 100644
--- a/espanso/src/cli/worker/engine/mod.rs
+++ b/espanso/src/cli/worker/engine/mod.rs
@@ -85,7 +85,7 @@ pub fn initialize_and_spawn(
let modulo_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager);
let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager);
- let context: Box = Box::new(super::context::DefaultContext::new(&config_manager));
+ let context: Box = Box::new(super::context::DefaultContext::new(&config_manager, &*app_info_provider));
let builtin_matches = super::builtin::get_builtin_matches();
let combined_match_cache = CombinedMatchCache::load(&match_cache, &builtin_matches);
diff --git a/espanso/src/cli/worker/engine/process/middleware/multiplex.rs b/espanso/src/cli/worker/engine/process/middleware/multiplex.rs
index 2c73a8d..360144a 100644
--- a/espanso/src/cli/worker/engine/process/middleware/multiplex.rs
+++ b/espanso/src/cli/worker/engine/process/middleware/multiplex.rs
@@ -46,7 +46,7 @@ pub struct MultiplexAdapter<'a> {
}
impl<'a> MultiplexAdapter<'a> {
- pub fn new(provider: &'a dyn MatchProvider<'a>, context: &'a dyn Context) -> Self {
+ pub fn new(provider: &'a dyn MatchProvider<'a>, context: &'a Context) -> Self {
Self { provider, context }
}
}
@@ -69,9 +69,7 @@ impl<'a> Multiplexer for MultiplexAdapter<'a> {
})),
MatchEffect::None => None,
},
- MatchResult::Builtin(m) => {
- Some((m.action)(self.context))
- }
+ MatchResult::Builtin(m) => Some((m.action)(self.context)),
}
}
}