feat(engine): implement notification for enabled/disabled on linux. Fix #798
This commit is contained in:
parent
1bad4b2bfb
commit
a806e180e1
|
@ -34,7 +34,8 @@ use super::{
|
||||||
},
|
},
|
||||||
DisableOptions, EnabledStatusProvider, MatchFilter, MatchInfoProvider, MatchProvider,
|
DisableOptions, EnabledStatusProvider, MatchFilter, MatchInfoProvider, MatchProvider,
|
||||||
MatchResolver, MatchSelector, Matcher, MatcherMiddlewareConfigProvider, Middleware,
|
MatchResolver, MatchSelector, Matcher, MatcherMiddlewareConfigProvider, Middleware,
|
||||||
ModifierStateProvider, Multiplexer, PathProvider, Processor, Renderer, UndoEnabledProvider,
|
ModifierStateProvider, Multiplexer, NotificationManager, PathProvider, Processor, Renderer,
|
||||||
|
UndoEnabledProvider,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
event::{Event, EventType},
|
event::{Event, EventType},
|
||||||
|
@ -42,7 +43,8 @@ use crate::{
|
||||||
context_menu::ContextMenuMiddleware, disable::DisableMiddleware, exit::ExitMiddleware,
|
context_menu::ContextMenuMiddleware, disable::DisableMiddleware, exit::ExitMiddleware,
|
||||||
hotkey::HotKeyMiddleware, icon_status::IconStatusMiddleware,
|
hotkey::HotKeyMiddleware, icon_status::IconStatusMiddleware,
|
||||||
image_resolve::ImageResolverMiddleware, match_exec::MatchExecRequestMiddleware,
|
image_resolve::ImageResolverMiddleware, match_exec::MatchExecRequestMiddleware,
|
||||||
search::SearchMiddleware, suppress::SuppressMiddleware, undo::UndoMiddleware,
|
notification::NotificationMiddleware, search::SearchMiddleware, suppress::SuppressMiddleware,
|
||||||
|
undo::UndoMiddleware,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
@ -71,6 +73,7 @@ impl<'a> DefaultProcessor<'a> {
|
||||||
enabled_status_provider: &'a dyn EnabledStatusProvider,
|
enabled_status_provider: &'a dyn EnabledStatusProvider,
|
||||||
modifier_state_provider: &'a dyn ModifierStateProvider,
|
modifier_state_provider: &'a dyn ModifierStateProvider,
|
||||||
match_resolver: &'a dyn MatchResolver,
|
match_resolver: &'a dyn MatchResolver,
|
||||||
|
notification_manager: &'a dyn NotificationManager,
|
||||||
) -> DefaultProcessor<'a> {
|
) -> DefaultProcessor<'a> {
|
||||||
Self {
|
Self {
|
||||||
event_queue: VecDeque::new(),
|
event_queue: VecDeque::new(),
|
||||||
|
@ -105,6 +108,7 @@ impl<'a> DefaultProcessor<'a> {
|
||||||
)),
|
)),
|
||||||
Box::new(SearchMiddleware::new(match_provider)),
|
Box::new(SearchMiddleware::new(match_provider)),
|
||||||
Box::new(MarkdownMiddleware::new()),
|
Box::new(MarkdownMiddleware::new()),
|
||||||
|
Box::new(NotificationMiddleware::new(notification_manager)),
|
||||||
Box::new(DelayForModifierReleaseMiddleware::new(
|
Box::new(DelayForModifierReleaseMiddleware::new(
|
||||||
modifier_status_provider,
|
modifier_status_provider,
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub mod match_exec;
|
||||||
pub mod match_select;
|
pub mod match_select;
|
||||||
pub mod matcher;
|
pub mod matcher;
|
||||||
pub mod multiplex;
|
pub mod multiplex;
|
||||||
|
pub mod notification;
|
||||||
pub mod render;
|
pub mod render;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod suppress;
|
pub mod suppress;
|
||||||
|
|
55
espanso-engine/src/process/middleware/notification.rs
Normal file
55
espanso-engine/src/process/middleware/notification.rs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* 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 super::super::Middleware;
|
||||||
|
use crate::event::{Event, EventType};
|
||||||
|
|
||||||
|
pub trait NotificationManager {
|
||||||
|
fn notify_status_change(&self, enabled: bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NotificationMiddleware<'a> {
|
||||||
|
notification_manager: &'a dyn NotificationManager,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NotificationMiddleware<'a> {
|
||||||
|
pub fn new(notification_manager: &'a dyn NotificationManager) -> Self {
|
||||||
|
Self {
|
||||||
|
notification_manager,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Middleware for NotificationMiddleware<'a> {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"notification"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next(&self, event: Event, _: &mut dyn FnMut(Event)) -> Event {
|
||||||
|
match &event.etype {
|
||||||
|
EventType::Enabled => self.notification_manager.notify_status_change(true),
|
||||||
|
EventType::Disabled => self.notification_manager.notify_status_change(false),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: test
|
|
@ -44,6 +44,7 @@ pub use middleware::matcher::{
|
||||||
ModifierStateProvider,
|
ModifierStateProvider,
|
||||||
};
|
};
|
||||||
pub use middleware::multiplex::Multiplexer;
|
pub use middleware::multiplex::Multiplexer;
|
||||||
|
pub use middleware::notification::NotificationManager;
|
||||||
pub use middleware::render::{Renderer, RendererError};
|
pub use middleware::render::{Renderer, RendererError};
|
||||||
pub use middleware::search::MatchProvider;
|
pub use middleware::search::MatchProvider;
|
||||||
pub use middleware::suppress::EnabledStatusProvider;
|
pub use middleware::suppress::EnabledStatusProvider;
|
||||||
|
@ -67,6 +68,7 @@ pub fn default<'a, MatcherState>(
|
||||||
enabled_status_provider: &'a dyn EnabledStatusProvider,
|
enabled_status_provider: &'a dyn EnabledStatusProvider,
|
||||||
modifier_state_provider: &'a dyn ModifierStateProvider,
|
modifier_state_provider: &'a dyn ModifierStateProvider,
|
||||||
match_resolver: &'a dyn MatchResolver,
|
match_resolver: &'a dyn MatchResolver,
|
||||||
|
notification_manager: &'a dyn NotificationManager,
|
||||||
) -> impl Processor + 'a {
|
) -> impl Processor + 'a {
|
||||||
default::DefaultProcessor::new(
|
default::DefaultProcessor::new(
|
||||||
matchers,
|
matchers,
|
||||||
|
@ -85,5 +87,6 @@ pub fn default<'a, MatcherState>(
|
||||||
enabled_status_provider,
|
enabled_status_provider,
|
||||||
modifier_state_provider,
|
modifier_state_provider,
|
||||||
match_resolver,
|
match_resolver,
|
||||||
|
notification_manager,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user