feat(engine): display and notify an error if rendering fails. Fix #774

This commit is contained in:
Federico Terzi 2021-10-31 22:21:44 +01:00
parent 93cb9680e6
commit 24087e8441
4 changed files with 16 additions and 5 deletions

View File

@ -30,7 +30,7 @@ pub struct CursorHintCompensationEvent {
pub cursor_hint_back_count: usize,
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct TextInjectRequest {
pub text: String,
pub force_mode: Option<TextInjectMode>,

View File

@ -49,7 +49,6 @@ impl Event {
#[allow(clippy::upper_case_acronyms)]
pub enum EventType {
NOOP,
ProcessingError(String),
ExitRequested(ExitMode),
Exit(ExitMode),
Heartbeat,
@ -77,6 +76,7 @@ pub enum EventType {
DiscardPrevious(internal::DiscardPreviousEvent),
DiscardBetween(internal::DiscardBetweenEvent),
Undo(internal::UndoEvent),
RenderingError,
Disabled,
Enabled,

View File

@ -22,6 +22,7 @@ use crate::event::{Event, EventType};
pub trait NotificationManager {
fn notify_status_change(&self, enabled: bool);
fn notify_rendering_error(&self);
}
pub struct NotificationMiddleware<'a> {
@ -45,6 +46,7 @@ impl<'a> Middleware for NotificationMiddleware<'a> {
match &event.etype {
EventType::Enabled => self.notification_manager.notify_status_change(true),
EventType::Disabled => self.notification_manager.notify_status_change(false),
EventType::RenderingError => self.notification_manager.notify_rendering_error(),
_ => {}
}

View File

@ -22,7 +22,7 @@ use std::collections::HashMap;
use log::error;
use super::super::Middleware;
use crate::event::{internal::RenderedEvent, Event, EventType};
use crate::event::{effect::TextInjectRequest, internal::RenderedEvent, Event, EventType};
use anyhow::Result;
use thiserror::Error;
@ -62,7 +62,7 @@ impl<'a> Middleware for RenderMiddleware<'a> {
"render"
}
fn next(&self, event: Event, _: &mut dyn FnMut(Event)) -> Event {
fn next(&self, event: Event, dispatch: &mut dyn FnMut(Event)) -> Event {
if let EventType::RenderingRequested(m_event) = event.etype {
match self.renderer.render(
m_event.match_id,
@ -91,7 +91,16 @@ impl<'a> Middleware for RenderMiddleware<'a> {
}
_ => {
error!("error during rendering: {:?}", err);
return Event::caused_by(event.source_id, EventType::ProcessingError("An error has occurred during rendering, please examine the logs or contact support.".to_string()));
dispatch(Event::caused_by(
event.source_id,
EventType::TextInject(TextInjectRequest {
text: "[Espanso]: An error occurred during rendering, please examine the logs for more information.".to_string(),
..Default::default()
}),
));
return Event::caused_by(event.source_id, EventType::RenderingError);
}
},
}