style(ui): fix formatting

This commit is contained in:
Federico Terzi 2021-10-06 18:42:06 +02:00
parent a8a5ef16a2
commit 638863170c
3 changed files with 41 additions and 29 deletions

View File

@ -235,7 +235,7 @@ impl From<RawUIEvent> for Option<UIEvent> {
UI_EVENT_TYPE_CONTEXT_MENU_CLICK => { UI_EVENT_TYPE_CONTEXT_MENU_CLICK => {
return Some(UIEvent::ContextMenuClick(raw.context_menu_id)); return Some(UIEvent::ContextMenuClick(raw.context_menu_id));
} }
UI_EVENT_TYPE_HEARTBEAT => { UI_EVENT_TYPE_HEARTBEAT => {
return Some(UIEvent::Heartbeat); return Some(UIEvent::Heartbeat);
} }
_ => {} _ => {}

View File

@ -58,26 +58,28 @@ mod tests {
#[test] #[test]
fn test_context_menu_serializes_correctly() { fn test_context_menu_serializes_correctly() {
let menu = Menu { items: vec![ let menu = Menu {
MenuItem::Simple(SimpleMenuItem { items: vec![
id: 0, MenuItem::Simple(SimpleMenuItem {
label: "Open".to_string() id: 0,
}), label: "Open".to_string(),
MenuItem::Separator, }),
MenuItem::Sub(SubMenuItem { MenuItem::Separator,
label: "Sub".to_string(), MenuItem::Sub(SubMenuItem {
items: vec![ label: "Sub".to_string(),
MenuItem::Simple(SimpleMenuItem { items: vec![
label: "Sub 1".to_string(), MenuItem::Simple(SimpleMenuItem {
id: 1, label: "Sub 1".to_string(),
}), id: 1,
MenuItem::Simple(SimpleMenuItem { }),
label: "Sub 2".to_string(), MenuItem::Simple(SimpleMenuItem {
id: 2, label: "Sub 2".to_string(),
}), id: 2,
], }),
}), ],
]}; }),
],
};
assert_eq!( assert_eq!(
menu.to_json().unwrap(), menu.to_json().unwrap(),

View File

@ -17,14 +17,20 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::{path::{PathBuf}, sync::{Arc, Mutex, mpsc::{Sender, channel}}}; use std::{
path::PathBuf,
sync::{
mpsc::{channel, Sender},
Arc, Mutex,
},
};
use anyhow::{Result, anyhow, bail}; use anyhow::{anyhow, bail, Result};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{error, warn}; use log::{error, warn};
use std::os::windows::process::CommandExt;
use std::process::Command; use std::process::Command;
use winrt_notification::{IconCrop, Toast}; use winrt_notification::{IconCrop, Toast};
use std::os::windows::process::CommandExt;
const ESPANSO_APP_USER_MODEL_ID: &str = "{5E3B6C0F-1A4D-45C4-8872-D8174702101A}"; const ESPANSO_APP_USER_MODEL_ID: &str = "{5E3B6C0F-1A4D-45C4-8872-D8174702101A}";
@ -34,9 +40,11 @@ lazy_static! {
pub fn initialize_notification_thread(notification_icon_path: PathBuf) -> Result<()> { pub fn initialize_notification_thread(notification_icon_path: PathBuf) -> Result<()> {
let (sender, receiver) = channel::<String>(); let (sender, receiver) = channel::<String>();
{ {
let mut lock = SEND_CHANNEL.lock().map_err(|e| anyhow!("failed to define shared notification sender: {}", e))?; let mut lock = SEND_CHANNEL
.lock()
.map_err(|e| anyhow!("failed to define shared notification sender: {}", e))?;
*lock = Some(sender); *lock = Some(sender);
} }
@ -68,12 +76,14 @@ pub fn initialize_notification_thread(notification_icon_path: PathBuf) -> Result
} }
pub fn show_notification(msg: &str) -> Result<()> { pub fn show_notification(msg: &str) -> Result<()> {
let mut lock = SEND_CHANNEL.lock().map_err(|e| anyhow!("unable to acquire notification send channel: {}", e))?; let mut lock = SEND_CHANNEL
.lock()
.map_err(|e| anyhow!("unable to acquire notification send channel: {}", e))?;
match &mut *lock { match &mut *lock {
Some(sender) => { Some(sender) => {
sender.send(msg.to_string())?; sender.send(msg.to_string())?;
Ok(()) Ok(())
}, }
None => bail!("notification sender not available"), None => bail!("notification sender not available"),
} }
} }
@ -99,4 +109,4 @@ fn is_espanso_app_user_model_id_set() -> bool {
false false
} }
} }
} }