/*
* This file is part of espanso.
*
* Copyright (C) 2019 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 .
*/
use crate::matcher::{Match, MatchReceiver, MatchContentType};
use crate::keyboard::KeyboardManager;
use crate::config::ConfigManager;
use crate::config::BackendType;
use crate::clipboard::ClipboardManager;
use log::{info, warn, debug, error};
use crate::ui::{UIManager, MenuItem, MenuItemType};
use crate::event::{ActionEventReceiver, ActionType};
use crate::extension::Extension;
use crate::render::{Renderer, RenderResult};
use std::cell::RefCell;
use std::process::exit;
use std::collections::HashMap;
use std::path::PathBuf;
use regex::{Regex, Captures};
use std::time::SystemTime;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::{Relaxed, Release, Acquire, AcqRel, SeqCst};
pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>,
U: UIManager, R: Renderer> {
keyboard_manager: &'a S,
clipboard_manager: &'a C,
config_manager: &'a M,
ui_manager: &'a U,
renderer: &'a R,
is_injecting: Arc,
enabled: RefCell,
last_action_time: RefCell, // Used to block espanso from re-interpreting it's own inputs
}
impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIManager, R: Renderer>
Engine<'a, S, C, M, U, R> {
pub fn new(keyboard_manager: &'a S, clipboard_manager: &'a C,
config_manager: &'a M, ui_manager: &'a U,
renderer: &'a R, is_injecting: Arc) -> Engine<'a, S, C, M, U, R> {
let enabled = RefCell::new(true);
let last_action_time = RefCell::new(SystemTime::now());
Engine{keyboard_manager,
clipboard_manager,
config_manager,
ui_manager,
renderer,
is_injecting,
enabled,
last_action_time,
}
}
fn build_menu(&self) -> Vec