diff --git a/espanso/src/cli/modulo/form.rs b/espanso/src/cli/modulo/form.rs index 998d1ee..7c369ab 100644 --- a/espanso/src/cli/modulo/form.rs +++ b/espanso/src/cli/modulo/form.rs @@ -19,8 +19,9 @@ use clap::{ArgMatches}; use espanso_modulo::form::*; +use crate::icon::IconPaths; -pub fn form_main(matches: &ArgMatches) -> i32 { +pub fn form_main(matches: &ArgMatches, _icon_paths: &IconPaths) -> i32 { let as_json: bool = matches.is_present("json"); let input_file = matches @@ -42,6 +43,8 @@ pub fn form_main(matches: &ArgMatches) -> i32 { } else { serde_json::from_str(&data).expect("unable to parse form configuration") }; + + // TODO: inject the icon on Windows let form = generator::generate(config); let values = show(form); diff --git a/espanso/src/cli/modulo/mod.rs b/espanso/src/cli/modulo/mod.rs index c4d0170..4b444c7 100644 --- a/espanso/src/cli/modulo/mod.rs +++ b/espanso/src/cli/modulo/mod.rs @@ -39,13 +39,14 @@ pub fn new() -> CliModule { fn modulo_main(args: CliModuleArgs) -> i32 { let paths = args.paths.expect("missing paths in modulo main"); let cli_args = args.cli_args.expect("missing cli_args in modulo main"); + let icon_paths = crate::icon::load_icon_paths(&paths.runtime).expect("unable to load icon paths"); if let Some(matches) = cli_args.subcommand_matches("form") { - return form::form_main(matches); + return form::form_main(matches, &icon_paths); } if let Some(matches) = cli_args.subcommand_matches("search") { - return search::search_main(matches); + return search::search_main(matches, &icon_paths); } 0 diff --git a/espanso/src/cli/modulo/search.rs b/espanso/src/cli/modulo/search.rs index 5894cb2..9678046 100644 --- a/espanso/src/cli/modulo/search.rs +++ b/espanso/src/cli/modulo/search.rs @@ -20,8 +20,9 @@ use std::collections::HashMap; use clap::{ArgMatches}; use espanso_modulo::search::*; +use crate::icon::IconPaths; -pub fn search_main(matches: &ArgMatches) -> i32 { +pub fn search_main(matches: &ArgMatches, icon_paths: &IconPaths) -> i32 { let as_json: bool = matches.is_present("json"); let input_file = matches @@ -38,12 +39,15 @@ pub fn search_main(matches: &ArgMatches) -> i32 { std::fs::read_to_string(input_file).expect("unable to read input file") }; - let config: config::SearchConfig = if !as_json { + let mut config: config::SearchConfig = if !as_json { serde_yaml::from_str(&data).expect("unable to parse search configuration") } else { serde_json::from_str(&data).expect("unable to parse search configuration") }; + // Overwrite the icon + config.icon = icon_paths.logo.as_deref().map(|path| path.to_string_lossy().to_string()); + let algorithm = algorithm::get_algorithm(&config.algorithm); let search = generator::generate(config); diff --git a/espanso/src/cli/worker/engine/mod.rs b/espanso/src/cli/worker/engine/mod.rs index 4458c32..51a47c6 100644 --- a/espanso/src/cli/worker/engine/mod.rs +++ b/espanso/src/cli/worker/engine/mod.rs @@ -29,7 +29,7 @@ use ui::selector::MatchSelectorAdapter; use crate::{cli::worker::engine::{matcher::regex::RegexMatcherAdapterOptions, path::PathProviderAdapter}, engine::event::ExitMode}; -use super::ui::icon::IconPaths; +use crate::icon::IconPaths; pub mod executor; pub mod match_cache; diff --git a/espanso/src/cli/worker/mod.rs b/espanso/src/cli/worker/mod.rs index a814d0a..e43933a 100644 --- a/espanso/src/cli/worker/mod.rs +++ b/espanso/src/cli/worker/mod.rs @@ -69,7 +69,7 @@ fn worker_main(args: CliModuleArgs) -> i32 { .expect("missing match store in worker main"); let icon_paths = - self::ui::icon::load_icon_paths(&paths.runtime).expect("unable to initialize icons"); + crate::icon::load_icon_paths(&paths.runtime).expect("unable to initialize icons"); let (remote, mut eventloop) = espanso_ui::create_ui(espanso_ui::UIOptions { // TODO: handle show icon diff --git a/espanso/src/cli/worker/ui/mod.rs b/espanso/src/cli/worker/ui/mod.rs index 5de9509..8b9382c 100644 --- a/espanso/src/cli/worker/ui/mod.rs +++ b/espanso/src/cli/worker/ui/mod.rs @@ -17,5 +17,4 @@ * along with espanso. If not, see . */ -pub mod icon; pub mod util; \ No newline at end of file diff --git a/espanso/src/cli/worker/ui/util.rs b/espanso/src/cli/worker/ui/util.rs index a16edaa..1bd4638 100644 --- a/espanso/src/cli/worker/ui/util.rs +++ b/espanso/src/cli/worker/ui/util.rs @@ -19,7 +19,7 @@ use espanso_ui::icons::TrayIcon; -use super::icon::IconPaths; +use crate::icon::IconPaths; // TODO: test pub fn convert_icon_paths_to_tray_vec(icon_paths: &IconPaths) -> Vec<(TrayIcon, String)> { diff --git a/espanso/src/cli/worker/ui/icon.rs b/espanso/src/icon.rs similarity index 85% rename from espanso/src/cli/worker/ui/icon.rs rename to espanso/src/icon.rs index eb12321..53b9d31 100644 --- a/espanso/src/cli/worker/ui/icon.rs +++ b/espanso/src/icon.rs @@ -21,20 +21,20 @@ use anyhow::Result; use log::{debug, info}; use std::path::{Path, PathBuf}; -const ICON_BINARY: &[u8] = include_bytes!("../../../res/icon.png"); +const ICON_BINARY: &[u8] = include_bytes!("res/icon.png"); #[cfg(target_os = "windows")] -const WINDOWS_ICO_BINARY: &[u8] = include_bytes!("../../../res/windows/espanso.ico"); +const WINDOWS_ICO_BINARY: &[u8] = include_bytes!("res/windows/espanso.ico"); #[cfg(target_os = "windows")] -const WINDOWS_RED_ICO_BINARY: &[u8] = include_bytes!("../../../res/windows/espansored.ico"); +const WINDOWS_RED_ICO_BINARY: &[u8] = include_bytes!("res/windows/espansored.ico"); #[cfg(target_os = "macos")] -const MAC_BINARY: &[u8] = include_bytes!("../../../res/macos/icon.png"); +const MAC_BINARY: &[u8] = include_bytes!("res/macos/icon.png"); #[cfg(target_os = "macos")] -const MAC_DISABLED_BINARY: &[u8] = include_bytes!("../../../res/macos/icondisabled.png"); +const MAC_DISABLED_BINARY: &[u8] = include_bytes!("res/macos/icondisabled.png"); #[cfg(target_os = "macos")] -const MAC_SYSTEM_DISABLED_BINARY: &[u8] = include_bytes!("../../../res/macos/iconsystemdisabled.png"); +const MAC_SYSTEM_DISABLED_BINARY: &[u8] = include_bytes!("res/macos/iconsystemdisabled.png"); #[derive(Debug, Default)] pub struct IconPaths { diff --git a/espanso/src/main.rs b/espanso/src/main.rs index 3ae99ca..b03ccb0 100644 --- a/espanso/src/main.rs +++ b/espanso/src/main.rs @@ -39,6 +39,7 @@ mod cli; mod engine; mod exit_code; mod gui; +mod icon; mod ipc; mod lock; mod logging;