feat(engine): implement ShowText event
This commit is contained in:
parent
b2452ecca7
commit
84fd39a952
|
@ -17,7 +17,9 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use super::{ContextMenuHandler, Event, IconHandler, ImageInjector, SecureInputManager};
|
||||
use super::{
|
||||
ContextMenuHandler, Event, IconHandler, ImageInjector, SecureInputManager, TextUIHandler,
|
||||
};
|
||||
use super::{Dispatcher, Executor, HtmlInjector, KeyInjector, ModeProvider, TextInjector};
|
||||
|
||||
pub struct DefaultDispatcher<'a> {
|
||||
|
@ -36,6 +38,7 @@ impl<'a> DefaultDispatcher<'a> {
|
|||
context_menu_handler: &'a dyn ContextMenuHandler,
|
||||
icon_handler: &'a dyn IconHandler,
|
||||
secure_input_manager: &'a dyn SecureInputManager,
|
||||
text_ui_handler: &'a dyn TextUIHandler,
|
||||
) -> Self {
|
||||
Self {
|
||||
executors: vec![
|
||||
|
@ -62,6 +65,9 @@ impl<'a> DefaultDispatcher<'a> {
|
|||
Box::new(super::executor::secure_input::SecureInputExecutor::new(
|
||||
secure_input_manager,
|
||||
)),
|
||||
Box::new(super::executor::text_ui::TextUIExecutor::new(
|
||||
text_ui_handler,
|
||||
)),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,3 +24,4 @@ pub mod image_inject;
|
|||
pub mod key_inject;
|
||||
pub mod secure_input;
|
||||
pub mod text_inject;
|
||||
pub mod text_ui;
|
||||
|
|
56
espanso-engine/src/dispatch/executor/text_ui.rs
Normal file
56
espanso-engine/src/dispatch/executor/text_ui.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This file is part of espanso.
|
||||
*
|
||||
* Copyright (C) 2019-2021 Federico Terzi
|
||||
*
|
||||
* espanso is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* espanso is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use crate::event::EventType;
|
||||
use crate::{dispatch::Executor, event::Event};
|
||||
use anyhow::Result;
|
||||
use log::error;
|
||||
|
||||
pub trait TextUIHandler {
|
||||
fn show_text(&self, title: &str, text: &str) -> Result<()>;
|
||||
}
|
||||
|
||||
pub struct TextUIExecutor<'a> {
|
||||
handler: &'a dyn TextUIHandler,
|
||||
}
|
||||
|
||||
impl<'a> TextUIExecutor<'a> {
|
||||
pub fn new(handler: &'a dyn TextUIHandler) -> Self {
|
||||
Self { handler }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Executor for TextUIExecutor<'a> {
|
||||
fn execute(&self, event: &Event) -> bool {
|
||||
if let EventType::ShowText(show_text_event) = &event.etype {
|
||||
if let Err(error) = self
|
||||
.handler
|
||||
.show_text(&show_text_event.title, &show_text_event.text)
|
||||
{
|
||||
error!("text UI handler reported an error: {:?}", error);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test
|
|
@ -38,6 +38,7 @@ pub use executor::image_inject::ImageInjector;
|
|||
pub use executor::key_inject::KeyInjector;
|
||||
pub use executor::secure_input::SecureInputManager;
|
||||
pub use executor::text_inject::{Mode, ModeProvider, TextInjector};
|
||||
pub use executor::text_ui::{TextUIExecutor, TextUIHandler};
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn default<'a>(
|
||||
|
@ -50,6 +51,7 @@ pub fn default<'a>(
|
|||
context_menu_handler: &'a dyn ContextMenuHandler,
|
||||
icon_handler: &'a dyn IconHandler,
|
||||
secure_input_manager: &'a dyn SecureInputManager,
|
||||
text_ui_handler: &'a dyn TextUIHandler,
|
||||
) -> impl Dispatcher + 'a {
|
||||
default::DefaultDispatcher::new(
|
||||
event_injector,
|
||||
|
@ -61,5 +63,6 @@ pub fn default<'a>(
|
|||
context_menu_handler,
|
||||
icon_handler,
|
||||
secure_input_manager,
|
||||
text_ui_handler,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ pub enum EventType {
|
|||
IconStatusChange(ui::IconStatusChangeEvent),
|
||||
DisplaySecureInputTroubleshoot,
|
||||
ShowSearchBar,
|
||||
ShowText(ui::ShowTextEvent),
|
||||
|
||||
// Other
|
||||
LaunchSecureInputAutoFix,
|
||||
|
|
|
@ -52,3 +52,9 @@ pub enum IconStatus {
|
|||
Disabled,
|
||||
SecureInputDisabled,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ShowTextEvent {
|
||||
pub title: String,
|
||||
pub text: String,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user