feat(core): wire up extensions

This commit is contained in:
Federico Terzi 2021-04-21 20:49:46 +02:00
parent 4af0cde3ed
commit a5fff067f7
4 changed files with 67 additions and 8 deletions

View File

@ -31,4 +31,5 @@ thiserror = "1.0.23"
clap = "2.33.3"
lazy_static = "1.4.0"
crossbeam = "0.8.0"
enum-as-inner = "0.3.3"
enum-as-inner = "0.3.3"
dirs = "3.0.1"

View File

@ -0,0 +1,39 @@
/*
* 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 espanso_clipboard::Clipboard;
use espanso_render::extension::clipboard::ClipboardProvider;
pub struct ClipboardAdapter<'a> {
clipboard: &'a dyn Clipboard,
}
impl <'a> ClipboardAdapter<'a> {
pub fn new(clipboard: &'a dyn Clipboard) -> Self {
Self {
clipboard
}
}
}
impl<'a> ClipboardProvider for ClipboardAdapter<'a> {
fn get_text(&self) -> Option<String> {
self.clipboard.get_text()
}
}

View File

@ -17,7 +17,9 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{cell::RefCell, collections::HashMap, convert::TryInto};
use std::{cell::RefCell, collections::HashMap};
pub mod clipboard;
use espanso_config::{
config::Config,

View File

@ -46,6 +46,8 @@ fn worker_main(args: CliModuleArgs) {
let match_store = args
.match_store
.expect("missing match store in worker main");
let paths = args.paths.expect("missing paths in worker main");
let app_info_provider =
espanso_info::get_provider().expect("unable to initialize app info provider");
@ -66,8 +68,27 @@ fn worker_main(args: CliModuleArgs) {
let selector = MatchSelectorAdapter::new();
let multiplexer = engine::multiplex::MultiplexAdapter::new(&match_cache);
// TODO: add extensions
let renderer = espanso_render::create(Vec::new());
let injector =
espanso_inject::get_injector(Default::default()).expect("failed to initialize injector module"); // TODO: handle the options
let clipboard = espanso_clipboard::get_clipboard(Default::default())
.expect("failed to initialize clipboard module"); // TODO: handle options
let clipboard_adapter = engine::render::clipboard::ClipboardAdapter::new(&*clipboard);
let clipboard_extension = espanso_render::extension::clipboard::ClipboardExtension::new(&clipboard_adapter);
let date_extension = espanso_render::extension::date::DateExtension::new();
let echo_extension = espanso_render::extension::echo::EchoExtension::new();
let random_extension = espanso_render::extension::random::RandomExtension::new();
let home_path = dirs::home_dir().expect("unable to obtain home dir path");
let script_extension = espanso_render::extension::script::ScriptExtension::new(&paths.config, &home_path, &paths.packages);
let shell_extension = espanso_render::extension::shell::ShellExtension::new(&paths.config);
let renderer = espanso_render::create(vec![
&clipboard_extension,
&date_extension,
&echo_extension,
&random_extension,
&script_extension,
&shell_extension,
]);
let renderer_adapter =
engine::render::RendererAdapter::new(&match_cache, &config_manager, &renderer);
@ -80,10 +101,6 @@ fn worker_main(args: CliModuleArgs) {
&match_cache,
);
let injector =
espanso_inject::get_injector(Default::default()).expect("failed to initialize injector module"); // TODO: handle the options
let clipboard = espanso_clipboard::get_clipboard(Default::default())
.expect("failed to initialize clipboard module"); // TODO: handle options
let event_injector = engine::executor::event_injector::EventInjectorAdapter::new(&*injector);
let clipboard_injector =