Add icon and title to modulo forms
This commit is contained in:
parent
510a886b08
commit
695c44c691
|
@ -53,6 +53,11 @@ pub fn update_icon(enabled: bool) {
|
||||||
// TODO: add update icon on macOS
|
// TODO: add update icon on macOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn get_icon_path() -> Option<PathBuf> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
// LINUX IMPLEMENTATION
|
// LINUX IMPLEMENTATION
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
@ -68,6 +73,11 @@ pub fn update_icon(enabled: bool) {
|
||||||
// No icon on Linux
|
// No icon on Linux
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn get_icon_path() -> Option<PathBuf> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
// WINDOWS IMPLEMENTATION
|
// WINDOWS IMPLEMENTATION
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
@ -83,6 +93,11 @@ pub fn update_icon(enabled: bool) {
|
||||||
windows::update_icon(enabled);
|
windows::update_icon(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
pub fn get_icon_path() -> Option<PathBuf> {
|
||||||
|
Some(windows::get_icon_path(&get_data_dir()))
|
||||||
|
}
|
||||||
|
|
||||||
// espanso directories
|
// espanso directories
|
||||||
|
|
||||||
static WARING_INIT: Once = Once::new();
|
static WARING_INIT: Once = Once::new();
|
||||||
|
|
|
@ -28,6 +28,7 @@ use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::atomic::Ordering::Acquire;
|
use std::sync::atomic::Ordering::Acquire;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
use widestring::{U16CStr, U16CString};
|
use widestring::{U16CStr, U16CString};
|
||||||
|
|
||||||
const BMP_BINARY: &[u8] = include_bytes!("../res/win/espanso.bmp");
|
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() {
|
if espanso_ico_image.exists() {
|
||||||
info!("ICO already initialized, skipping.");
|
info!("ICO already initialized, skipping.");
|
||||||
} else {
|
} 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
|
// Native bridge code
|
||||||
|
|
||||||
pub fn update_icon(enabled: bool) {
|
pub fn update_icon(enabled: bool) {
|
||||||
|
|
|
@ -53,12 +53,17 @@ impl super::Extension for FormExtension {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut form_config = Mapping::new();
|
let mut form_config = Mapping::new();
|
||||||
|
form_config.insert(Value::from("title"), Value::from("espanso"));
|
||||||
form_config.insert(Value::from("layout"), Value::from(layout));
|
form_config.insert(Value::from("layout"), Value::from(layout));
|
||||||
|
|
||||||
if let Some(fields) = params.get(&Value::from("fields")) {
|
if let Some(fields) = params.get(&Value::from("fields")) {
|
||||||
form_config.insert(Value::from("fields"), fields.clone());
|
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 =
|
let serialized_config: String =
|
||||||
serde_yaml::to_string(&form_config).expect("unable to serialize form config");
|
serde_yaml::to_string(&form_config).expect("unable to serialize form config");
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl ModuloManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
error!("error while sending body to modulo");
|
error!("error while sending body to modulo: {}", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user