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,
|
pub cursor_hint_back_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct TextInjectRequest {
|
pub struct TextInjectRequest {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub force_mode: Option<TextInjectMode>,
|
pub force_mode: Option<TextInjectMode>,
|
||||||
|
|
|
@ -49,7 +49,6 @@ impl Event {
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
pub enum EventType {
|
pub enum EventType {
|
||||||
NOOP,
|
NOOP,
|
||||||
ProcessingError(String),
|
|
||||||
ExitRequested(ExitMode),
|
ExitRequested(ExitMode),
|
||||||
Exit(ExitMode),
|
Exit(ExitMode),
|
||||||
Heartbeat,
|
Heartbeat,
|
||||||
|
@ -77,6 +76,7 @@ pub enum EventType {
|
||||||
DiscardPrevious(internal::DiscardPreviousEvent),
|
DiscardPrevious(internal::DiscardPreviousEvent),
|
||||||
DiscardBetween(internal::DiscardBetweenEvent),
|
DiscardBetween(internal::DiscardBetweenEvent),
|
||||||
Undo(internal::UndoEvent),
|
Undo(internal::UndoEvent),
|
||||||
|
RenderingError,
|
||||||
|
|
||||||
Disabled,
|
Disabled,
|
||||||
Enabled,
|
Enabled,
|
||||||
|
|
|
@ -22,6 +22,7 @@ use crate::event::{Event, EventType};
|
||||||
|
|
||||||
pub trait NotificationManager {
|
pub trait NotificationManager {
|
||||||
fn notify_status_change(&self, enabled: bool);
|
fn notify_status_change(&self, enabled: bool);
|
||||||
|
fn notify_rendering_error(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NotificationMiddleware<'a> {
|
pub struct NotificationMiddleware<'a> {
|
||||||
|
@ -45,6 +46,7 @@ impl<'a> Middleware for NotificationMiddleware<'a> {
|
||||||
match &event.etype {
|
match &event.etype {
|
||||||
EventType::Enabled => self.notification_manager.notify_status_change(true),
|
EventType::Enabled => self.notification_manager.notify_status_change(true),
|
||||||
EventType::Disabled => self.notification_manager.notify_status_change(false),
|
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 log::error;
|
||||||
|
|
||||||
use super::super::Middleware;
|
use super::super::Middleware;
|
||||||
use crate::event::{internal::RenderedEvent, Event, EventType};
|
use crate::event::{effect::TextInjectRequest, internal::RenderedEvent, Event, EventType};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ impl<'a> Middleware for RenderMiddleware<'a> {
|
||||||
"render"
|
"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 {
|
if let EventType::RenderingRequested(m_event) = event.etype {
|
||||||
match self.renderer.render(
|
match self.renderer.render(
|
||||||
m_event.match_id,
|
m_event.match_id,
|
||||||
|
@ -91,7 +91,16 @@ impl<'a> Middleware for RenderMiddleware<'a> {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("error during rendering: {:?}", err);
|
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