feat(core): move form icon injection logic
This commit is contained in:
parent
985706c6fe
commit
76b4a4a302
|
@ -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")
|
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")
|
serde_yaml::from_str(&data).expect("unable to parse form configuration")
|
||||||
} else {
|
} else {
|
||||||
serde_json::from_str(&data).expect("unable to parse form configuration")
|
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 form = generator::generate(config);
|
||||||
let values = show(form);
|
let values = show(form);
|
||||||
|
|
|
@ -29,8 +29,6 @@ use ui::selector::MatchSelectorAdapter;
|
||||||
|
|
||||||
use crate::{cli::worker::engine::{matcher::regex::RegexMatcherAdapterOptions, path::PathProviderAdapter}, engine::event::ExitMode};
|
use crate::{cli::worker::engine::{matcher::regex::RegexMatcherAdapterOptions, path::PathProviderAdapter}, engine::event::ExitMode};
|
||||||
|
|
||||||
use crate::icon::IconPaths;
|
|
||||||
|
|
||||||
pub mod executor;
|
pub mod executor;
|
||||||
pub mod match_cache;
|
pub mod match_cache;
|
||||||
pub mod matcher;
|
pub mod matcher;
|
||||||
|
@ -44,7 +42,6 @@ pub fn initialize_and_spawn(
|
||||||
paths: Paths,
|
paths: Paths,
|
||||||
config_store: Box<dyn ConfigStore>,
|
config_store: Box<dyn ConfigStore>,
|
||||||
match_store: Box<dyn MatchStore>,
|
match_store: Box<dyn MatchStore>,
|
||||||
icon_paths: IconPaths,
|
|
||||||
ui_remote: Box<dyn UIRemote>,
|
ui_remote: Box<dyn UIRemote>,
|
||||||
exit_signal: Receiver<()>,
|
exit_signal: Receiver<()>,
|
||||||
ui_event_receiver: Receiver<UIEvent>,
|
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 match_cache = super::engine::match_cache::MatchCache::load(&*config_store, &*match_store);
|
||||||
|
|
||||||
let modulo_manager = crate::gui::modulo::manager::ModuloManager::new();
|
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_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager);
|
||||||
let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager, &icon_paths.search_icon);
|
let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager);
|
||||||
|
|
||||||
let (detect_source, modifier_state_store, sequencer) =
|
let (detect_source, modifier_state_store, sequencer) =
|
||||||
super::engine::source::init_and_spawn().expect("failed to initialize detector module");
|
super::engine::source::init_and_spawn().expect("failed to initialize detector module");
|
||||||
|
|
|
@ -94,7 +94,6 @@ fn worker_main(args: CliModuleArgs) -> i32 {
|
||||||
paths.clone(),
|
paths.clone(),
|
||||||
config_store,
|
config_store,
|
||||||
match_store,
|
match_store,
|
||||||
icon_paths,
|
|
||||||
remote,
|
remote,
|
||||||
engine_exit_receiver,
|
engine_exit_receiver,
|
||||||
engine_ui_event_receiver,
|
engine_ui_event_receiver,
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{json, Map, Value};
|
use serde_json::{json, Map, Value};
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap};
|
||||||
|
|
||||||
use crate::gui::{FormField, FormUI};
|
use crate::gui::{FormField, FormUI};
|
||||||
|
|
||||||
|
@ -27,14 +27,12 @@ use super::manager::ModuloManager;
|
||||||
|
|
||||||
pub struct ModuloFormUI<'a> {
|
pub struct ModuloFormUI<'a> {
|
||||||
manager: &'a ModuloManager,
|
manager: &'a ModuloManager,
|
||||||
icon_path: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ModuloFormUI<'a> {
|
impl<'a> ModuloFormUI<'a> {
|
||||||
pub fn new(manager: &'a ModuloManager, icon_path: &Option<PathBuf>) -> Self {
|
pub fn new(manager: &'a ModuloManager) -> Self {
|
||||||
Self {
|
Self {
|
||||||
manager,
|
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>,
|
fields: &HashMap<String, FormField>,
|
||||||
) -> anyhow::Result<Option<HashMap<String, String>>> {
|
) -> anyhow::Result<Option<HashMap<String, String>>> {
|
||||||
let modulo_form_config = ModuloFormConfig {
|
let modulo_form_config = ModuloFormConfig {
|
||||||
icon: self.icon_path.as_deref(),
|
|
||||||
title: "espanso",
|
title: "espanso",
|
||||||
layout,
|
layout,
|
||||||
fields: convert_fields_into_object(fields),
|
fields: convert_fields_into_object(fields),
|
||||||
|
@ -74,7 +71,6 @@ impl<'a> FormUI for ModuloFormUI<'a> {
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct ModuloFormConfig<'a> {
|
struct ModuloFormConfig<'a> {
|
||||||
icon: Option<&'a str>,
|
|
||||||
title: &'a str,
|
title: &'a str,
|
||||||
layout: &'a str,
|
layout: &'a str,
|
||||||
fields: Map<String, Value>,
|
fields: Map<String, Value>,
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap};
|
||||||
|
|
||||||
use crate::gui::{SearchItem, SearchUI};
|
use crate::gui::{SearchItem, SearchUI};
|
||||||
|
|
||||||
|
@ -27,14 +27,12 @@ use super::manager::ModuloManager;
|
||||||
|
|
||||||
pub struct ModuloSearchUI<'a> {
|
pub struct ModuloSearchUI<'a> {
|
||||||
manager: &'a ModuloManager,
|
manager: &'a ModuloManager,
|
||||||
icon_path: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ModuloSearchUI<'a> {
|
impl<'a> ModuloSearchUI<'a> {
|
||||||
pub fn new(manager: &'a ModuloManager, icon_path: &Option<PathBuf>) -> Self {
|
pub fn new(manager: &'a ModuloManager) -> Self {
|
||||||
Self {
|
Self {
|
||||||
manager,
|
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> {
|
impl<'a> SearchUI for ModuloSearchUI<'a> {
|
||||||
fn show(&self, items: &[SearchItem]) -> anyhow::Result<Option<String>> {
|
fn show(&self, items: &[SearchItem]) -> anyhow::Result<Option<String>> {
|
||||||
let modulo_config = ModuloSearchConfig {
|
let modulo_config = ModuloSearchConfig {
|
||||||
icon: self.icon_path.as_deref(),
|
|
||||||
title: "espanso",
|
title: "espanso",
|
||||||
items: convert_items(&items),
|
items: convert_items(&items),
|
||||||
};
|
};
|
||||||
|
@ -69,7 +66,6 @@ impl<'a> SearchUI for ModuloSearchUI<'a> {
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct ModuloSearchConfig<'a> {
|
struct ModuloSearchConfig<'a> {
|
||||||
icon: Option<&'a str>,
|
|
||||||
title: &'a str,
|
title: &'a str,
|
||||||
items: Vec<ModuloSearchItemConfig<'a>>,
|
items: Vec<ModuloSearchItemConfig<'a>>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user