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 => {
return Some(UIEvent::ContextMenuClick(raw.context_menu_id));
}
UI_EVENT_TYPE_HEARTBEAT => {
UI_EVENT_TYPE_HEARTBEAT => {
return Some(UIEvent::Heartbeat);
}
_ => {}

View File

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

View File

@ -17,14 +17,20 @@
* 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 log::{error, warn};
use std::os::windows::process::CommandExt;
use std::process::Command;
use winrt_notification::{IconCrop, Toast};
use std::os::windows::process::CommandExt;
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<()> {
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);
}
@ -68,12 +76,14 @@ pub fn initialize_notification_thread(notification_icon_path: PathBuf) -> 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 {
Some(sender) => {
sender.send(msg.to_string())?;
Ok(())
},
}
None => bail!("notification sender not available"),
}
}
@ -99,4 +109,4 @@ fn is_espanso_app_user_model_id_set() -> bool {
false
}
}
}
}