From 695c44c6913f4abebfce4e554454858871259350 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 16 Aug 2020 20:22:58 +0200 Subject: [PATCH] Add icon and title to modulo forms --- src/context/mod.rs | 15 +++++++++++++++ src/context/windows.rs | 7 ++++++- src/extension/form.rs | 5 +++++ src/ui/modulo/mod.rs | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/context/mod.rs b/src/context/mod.rs index cd3a5aa..ea656fe 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -53,6 +53,11 @@ pub fn update_icon(enabled: bool) { // TODO: add update icon on macOS } +#[cfg(target_os = "macos")] +pub fn get_icon_path() -> Option { + None +} + // LINUX IMPLEMENTATION #[cfg(target_os = "linux")] pub fn new( @@ -68,6 +73,11 @@ pub fn update_icon(enabled: bool) { // No icon on Linux } +#[cfg(target_os = "linux")] +pub fn get_icon_path() -> Option { + None +} + // WINDOWS IMPLEMENTATION #[cfg(target_os = "windows")] pub fn new( @@ -83,6 +93,11 @@ pub fn update_icon(enabled: bool) { windows::update_icon(enabled); } +#[cfg(target_os = "windows")] +pub fn get_icon_path() -> Option { + Some(windows::get_icon_path(&get_data_dir())) +} + // espanso directories static WARING_INIT: Once = Once::new(); diff --git a/src/context/windows.rs b/src/context/windows.rs index e1cf95a..6928850 100644 --- a/src/context/windows.rs +++ b/src/context/windows.rs @@ -28,6 +28,7 @@ use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::Acquire; use std::sync::mpsc::Sender; use std::sync::Arc; +use std::path::{Path, PathBuf}; use widestring::{U16CStr, U16CString}; const BMP_BINARY: &[u8] = include_bytes!("../res/win/espanso.bmp"); @@ -66,7 +67,7 @@ impl WindowsContext { ); } - let espanso_ico_image = espanso_dir.join("espanso.ico"); + let espanso_ico_image = get_icon_path(&espanso_dir); if espanso_ico_image.exists() { info!("ICO already initialized, skipping."); } else { @@ -141,6 +142,10 @@ impl super::Context for WindowsContext { } } +pub fn get_icon_path(espanso_dir: &Path) -> PathBuf { + espanso_dir.join("espanso.ico") +} + // Native bridge code pub fn update_icon(enabled: bool) { diff --git a/src/extension/form.rs b/src/extension/form.rs index 5b9abcd..79133f6 100644 --- a/src/extension/form.rs +++ b/src/extension/form.rs @@ -53,12 +53,17 @@ impl super::Extension for FormExtension { }; let mut form_config = Mapping::new(); + form_config.insert(Value::from("title"), Value::from("espanso")); form_config.insert(Value::from("layout"), Value::from(layout)); if let Some(fields) = params.get(&Value::from("fields")) { form_config.insert(Value::from("fields"), fields.clone()); } + if let Some(icon_path) = crate::context::get_icon_path() { + form_config.insert(Value::from("icon"), Value::from(icon_path.to_string_lossy().to_string())); + } + let serialized_config: String = serde_yaml::to_string(&form_config).expect("unable to serialize form config"); diff --git a/src/ui/modulo/mod.rs b/src/ui/modulo/mod.rs index 5f306ac..008956d 100644 --- a/src/ui/modulo/mod.rs +++ b/src/ui/modulo/mod.rs @@ -104,7 +104,7 @@ impl ModuloManager { } } Err(error) => { - error!("error while sending body to modulo"); + error!("error while sending body to modulo: {}", error); } } } else {