feat(core): overwrite modulo icon
This commit is contained in:
		
							parent
							
								
									0e5e308e9f
								
							
						
					
					
						commit
						a7c51fe803
					
				| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,5 +17,4 @@
 | 
			
		|||
 * along with espanso.  If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
pub mod icon;
 | 
			
		||||
pub mod util;
 | 
			
		||||
| 
						 | 
				
			
			@ -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)> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +39,7 @@ mod cli;
 | 
			
		|||
mod engine;
 | 
			
		||||
mod exit_code;
 | 
			
		||||
mod gui;
 | 
			
		||||
mod icon;
 | 
			
		||||
mod ipc;
 | 
			
		||||
mod lock;
 | 
			
		||||
mod logging;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user