feat(core): implement builtin to dump app info
This commit is contained in:
parent
7f3c70c8df
commit
d23de2e3c9
|
@ -17,7 +17,10 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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;
|
use super::BuiltInMatch;
|
||||||
|
|
||||||
|
@ -38,3 +41,26 @@ pub fn create_match_paste_active_config_info() -> BuiltInMatch {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ pub struct BuiltInMatch {
|
||||||
pub fn get_builtin_matches() -> Vec<BuiltInMatch> {
|
pub fn get_builtin_matches() -> Vec<BuiltInMatch> {
|
||||||
vec![
|
vec![
|
||||||
debug::create_match_paste_active_config_info(),
|
debug::create_match_paste_active_config_info(),
|
||||||
|
debug::create_match_paste_active_app_info(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,16 +17,25 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use espanso_info::AppInfoProvider;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::cli::worker::config::ConfigManager;
|
use crate::cli::worker::config::ConfigManager;
|
||||||
|
|
||||||
pub struct DefaultContext<'a> {
|
pub struct DefaultContext<'a> {
|
||||||
config_manager: &'a ConfigManager<'a>,
|
config_manager: &'a ConfigManager<'a>,
|
||||||
|
app_info_provider: &'a dyn AppInfoProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DefaultContext<'a> {
|
impl<'a> DefaultContext<'a> {
|
||||||
pub fn new(config_manager: &'a ConfigManager<'a>) -> Self {
|
pub fn new(
|
||||||
Self { config_manager }
|
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()
|
self.config_manager.active()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> AppInfoContext for DefaultContext<'a> {
|
||||||
|
fn get_active_app_info(&self) -> AppInfo {
|
||||||
|
self.app_info_provider.get_info()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,10 +23,15 @@ use espanso_config::config::Config;
|
||||||
|
|
||||||
mod default;
|
mod default;
|
||||||
pub use default::DefaultContext;
|
pub use default::DefaultContext;
|
||||||
|
use espanso_info::{AppInfo};
|
||||||
|
|
||||||
pub trait Context: ConfigContext {}
|
pub trait Context: ConfigContext + AppInfoContext {}
|
||||||
|
|
||||||
pub trait ConfigContext {
|
pub trait ConfigContext {
|
||||||
fn get_default_config(&self) -> Arc<dyn Config>;
|
fn get_default_config(&self) -> Arc<dyn Config>;
|
||||||
fn get_active_config(&self) -> Arc<dyn Config>;
|
fn get_active_config(&self) -> Arc<dyn Config>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait AppInfoContext {
|
||||||
|
fn get_active_app_info(&self) -> AppInfo;
|
||||||
|
}
|
|
@ -85,7 +85,7 @@ pub fn initialize_and_spawn(
|
||||||
let modulo_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager);
|
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 modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager);
|
||||||
|
|
||||||
let context: Box<dyn Context> = Box::new(super::context::DefaultContext::new(&config_manager));
|
let context: Box<dyn Context> = Box::new(super::context::DefaultContext::new(&config_manager, &*app_info_provider));
|
||||||
let builtin_matches = super::builtin::get_builtin_matches();
|
let builtin_matches = super::builtin::get_builtin_matches();
|
||||||
let combined_match_cache = CombinedMatchCache::load(&match_cache, &builtin_matches);
|
let combined_match_cache = CombinedMatchCache::load(&match_cache, &builtin_matches);
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub struct MultiplexAdapter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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 }
|
Self { provider, context }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,7 @@ impl<'a> Multiplexer for MultiplexAdapter<'a> {
|
||||||
})),
|
})),
|
||||||
MatchEffect::None => None,
|
MatchEffect::None => None,
|
||||||
},
|
},
|
||||||
MatchResult::Builtin(m) => {
|
MatchResult::Builtin(m) => Some((m.action)(self.context)),
|
||||||
Some((m.action)(self.context))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user