feat(core): move form icon injection logic

This commit is contained in:
Federico Terzi 2021-05-22 16:49:08 +02:00
parent 985706c6fe
commit 76b4a4a302
5 changed files with 9 additions and 20 deletions

View File

@ -38,13 +38,14 @@ pub fn form_main(matches: &ArgMatches, _icon_paths: &IconPaths) -> i32 {
std::fs::read_to_string(input_file).expect("unable to read input file")
};
let config: config::FormConfig = if !as_json {
let mut config: config::FormConfig = if !as_json {
serde_yaml::from_str(&data).expect("unable to parse form configuration")
} else {
serde_json::from_str(&data).expect("unable to parse form configuration")
};
// TODO: inject the icon on Windows
// Overwrite the icon
config.icon = _icon_paths.form_icon.as_deref().map(|path| path.to_string_lossy().to_string());
let form = generator::generate(config);
let values = show(form);

View File

@ -29,8 +29,6 @@ use ui::selector::MatchSelectorAdapter;
use crate::{cli::worker::engine::{matcher::regex::RegexMatcherAdapterOptions, path::PathProviderAdapter}, engine::event::ExitMode};
use crate::icon::IconPaths;
pub mod executor;
pub mod match_cache;
pub mod matcher;
@ -44,7 +42,6 @@ pub fn initialize_and_spawn(
paths: Paths,
config_store: Box<dyn ConfigStore>,
match_store: Box<dyn MatchStore>,
icon_paths: IconPaths,
ui_remote: Box<dyn UIRemote>,
exit_signal: Receiver<()>,
ui_event_receiver: Receiver<UIEvent>,
@ -63,8 +60,8 @@ pub fn initialize_and_spawn(
let match_cache = super::engine::match_cache::MatchCache::load(&*config_store, &*match_store);
let modulo_manager = crate::gui::modulo::manager::ModuloManager::new();
let modulo_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager, &icon_paths.form_icon);
let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager, &icon_paths.search_icon);
let modulo_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager);
let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager);
let (detect_source, modifier_state_store, sequencer) =
super::engine::source::init_and_spawn().expect("failed to initialize detector module");

View File

@ -94,7 +94,6 @@ fn worker_main(args: CliModuleArgs) -> i32 {
paths.clone(),
config_store,
match_store,
icon_paths,
remote,
engine_exit_receiver,
engine_ui_event_receiver,

View File

@ -19,7 +19,7 @@
use serde::Serialize;
use serde_json::{json, Map, Value};
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap};
use crate::gui::{FormField, FormUI};
@ -27,14 +27,12 @@ use super::manager::ModuloManager;
pub struct ModuloFormUI<'a> {
manager: &'a ModuloManager,
icon_path: Option<String>,
}
impl<'a> ModuloFormUI<'a> {
pub fn new(manager: &'a ModuloManager, icon_path: &Option<PathBuf>) -> Self {
pub fn new(manager: &'a ModuloManager) -> Self {
Self {
manager,
icon_path: icon_path.as_ref().map(|path| path.to_string_lossy().to_string()),
}
}
}
@ -46,7 +44,6 @@ impl<'a> FormUI for ModuloFormUI<'a> {
fields: &HashMap<String, FormField>,
) -> anyhow::Result<Option<HashMap<String, String>>> {
let modulo_form_config = ModuloFormConfig {
icon: self.icon_path.as_deref(),
title: "espanso",
layout,
fields: convert_fields_into_object(fields),
@ -74,7 +71,6 @@ impl<'a> FormUI for ModuloFormUI<'a> {
#[derive(Debug, Serialize)]
struct ModuloFormConfig<'a> {
icon: Option<&'a str>,
title: &'a str,
layout: &'a str,
fields: Map<String, Value>,

View File

@ -19,7 +19,7 @@
use serde::Serialize;
use serde_json::Value;
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap};
use crate::gui::{SearchItem, SearchUI};
@ -27,14 +27,12 @@ use super::manager::ModuloManager;
pub struct ModuloSearchUI<'a> {
manager: &'a ModuloManager,
icon_path: Option<String>,
}
impl<'a> ModuloSearchUI<'a> {
pub fn new(manager: &'a ModuloManager, icon_path: &Option<PathBuf>) -> Self {
pub fn new(manager: &'a ModuloManager) -> Self {
Self {
manager,
icon_path: icon_path.as_ref().map(|path| path.to_string_lossy().to_string()),
}
}
}
@ -42,7 +40,6 @@ impl<'a> ModuloSearchUI<'a> {
impl<'a> SearchUI for ModuloSearchUI<'a> {
fn show(&self, items: &[SearchItem]) -> anyhow::Result<Option<String>> {
let modulo_config = ModuloSearchConfig {
icon: self.icon_path.as_deref(),
title: "espanso",
items: convert_items(&items),
};
@ -69,7 +66,6 @@ impl<'a> SearchUI for ModuloSearchUI<'a> {
#[derive(Debug, Serialize)]
struct ModuloSearchConfig<'a> {
icon: Option<&'a str>,
title: &'a str,
items: Vec<ModuloSearchItemConfig<'a>>,
}