diff --git a/espanso/src/cli/worker/builtin/debug.rs b/espanso/src/cli/worker/builtin/debug.rs index c548090..3120dd0 100644 --- a/espanso/src/cli/worker/builtin/debug.rs +++ b/espanso/src/cli/worker/builtin/debug.rs @@ -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() + } +} diff --git a/espanso/src/cli/worker/builtin/mod.rs b/espanso/src/cli/worker/builtin/mod.rs index b8e84d2..ee8f7f8 100644 --- a/espanso/src/cli/worker/builtin/mod.rs +++ b/espanso/src/cli/worker/builtin/mod.rs @@ -57,6 +57,7 @@ pub fn get_builtin_matches(config: &dyn Config) -> Vec { 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(), ]; diff --git a/espanso/src/cli/worker/engine/dispatch/executor/text_ui.rs b/espanso/src/cli/worker/engine/dispatch/executor/text_ui.rs index 5d73932..488d964 100644 --- a/espanso/src/cli/worker/engine/dispatch/executor/text_ui.rs +++ b/espanso/src/cli/worker/engine/dispatch/executor/text_ui.rs @@ -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(()) + } } diff --git a/espanso/src/cli/worker/engine/mod.rs b/espanso/src/cli/worker/engine/mod.rs index 0cd74b2..7449bda 100644 --- a/espanso/src/cli/worker/engine/mod.rs +++ b/espanso/src/cli/worker/engine/mod.rs @@ -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,