feat(engine): display and notify an error if rendering fails. Fix #774
This commit is contained in:
parent
93cb9680e6
commit
24087e8441
|
@ -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>,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user