feat(core): implement builtin to show logs

This commit is contained in:
Federico Terzi 2021-11-15 22:31:57 +01:00
parent c69544c1e2
commit e2b6dcba38
4 changed files with 23 additions and 3 deletions

View File

@ -106,3 +106,13 @@ pub fn create_match_show_active_app_info() -> BuiltInMatch {
..Default::default()
}
}
pub fn create_match_show_logs() -> BuiltInMatch {
BuiltInMatch {
id: generate_next_builtin_id(),
label: "Show Espanso's logs",
triggers: vec!["#log#".to_string()],
action: |_| EventType::ShowLogs,
..Default::default()
}
}

View File

@ -57,6 +57,7 @@ pub fn get_builtin_matches(config: &dyn Config) -> Vec<BuiltInMatch> {
debug::create_match_paste_active_app_info(),
debug::create_match_show_active_config_info(),
debug::create_match_show_active_app_info(),
debug::create_match_show_logs(),
process::create_match_exit(),
process::create_match_restart(),
];

View File

@ -18,16 +18,18 @@
*/
use espanso_engine::dispatch::TextUIHandler;
use espanso_path::Paths;
use crate::gui::TextUI;
pub struct TextUIHandlerAdapter<'a> {
text_ui: &'a dyn TextUI,
paths: &'a Paths,
}
impl<'a> TextUIHandlerAdapter<'a> {
pub fn new(text_ui: &'a dyn TextUI) -> Self {
Self { text_ui }
pub fn new(text_ui: &'a dyn TextUI, paths: &'a Paths) -> Self {
Self { text_ui, paths }
}
}
@ -36,4 +38,11 @@ impl<'a> TextUIHandler for TextUIHandlerAdapter<'a> {
self.text_ui.show_text(title, text)?;
Ok(())
}
fn show_logs(&self) -> anyhow::Result<()> {
self
.text_ui
.show_file("Espanso Logs", &self.paths.runtime.join("espanso.log"))?;
Ok(())
}
}

View File

@ -243,7 +243,7 @@ pub fn initialize_and_spawn(
let context_menu_adapter = ContextMenuHandlerAdapter::new(&*ui_remote);
let icon_adapter = IconHandlerAdapter::new(&*ui_remote);
let secure_input_adapter = SecureInputManagerAdapter::new();
let text_ui_adapter = TextUIHandlerAdapter::new(&modulo_text_ui);
let text_ui_adapter = TextUIHandlerAdapter::new(&modulo_text_ui, &paths);
let dispatcher = espanso_engine::dispatch::default(
&event_injector,
&clipboard_injector,