Move get_icon_path into own impl

This commit is contained in:
Hilmar Gústafsson 2020-02-01 12:02:34 +01:00
parent f577504e39
commit d28d4a9479

View File

@ -30,8 +30,7 @@ use winrt_notification::{Duration, IconCrop, Sound, Toast};
pub struct WindowsUIManager;
impl super::UIManager for WindowsUIManager {
fn notify(&self, message: &str) {
impl WindowsUIManager {
fn get_icon_path() -> io::Result<Box<Path>> {
let path_buf = std::env::current_exe()?.parent().unwrap().to_path_buf();
let installed_ico = path_buf.join("icon.ico");
@ -53,15 +52,18 @@ impl super::UIManager for WindowsUIManager {
))
}
}
}
impl super::UIManager for WindowsUIManager {
fn notify(&self, message: &str) {
// Create and show a window notification
let mut toast: Toast = Toast::new(Toast::POWERSHELL_APP_ID) // TODO: Use an ID assigned during installation.
.title("Espanso")
.text1(message)
.duration(Duration::Short);
if let Ok(p) = get_icon_path() {
toast = toast.icon(&p, IconCrop::Circular, "espanso");
if let Ok(ref p) = Self::get_icon_path() {
toast = toast.icon(p, IconCrop::Circular, "espanso");
}
toast.show().expect("Unable to toast");