diff --git a/res/translations/en/messages.ftl b/res/translations/en/messages.ftl index a6de9ef1..eed0e89e 100644 --- a/res/translations/en/messages.ftl +++ b/res/translations/en/messages.ftl @@ -199,6 +199,10 @@ tray_icon_close = Close notification_app_minimized_to_tray = Space Acres was minimized to tray .body = You can open it again or exit completely using tray icon menu +notification_stopped_with_error = Space Acres stopped with error + .body = An error happened and requires user intervention to resolve +notification_farm_error = One of the farms failed in Space Acres + .body = An error happened and requires user intervention to resolve notification_signed_reward_successfully = Signed new reward successfully 🥳 .body = Thank you for securing the network 🙌 notification_missed_reward = Reward signing failed 😞 diff --git a/res/translations/rs/messages.ftl b/res/translations/rs/messages.ftl index 279979ff..fb9e3583 100644 --- a/res/translations/rs/messages.ftl +++ b/res/translations/rs/messages.ftl @@ -213,6 +213,12 @@ tray_icon_close = Close notification_app_minimized_to_tray = Space Acres was minimized to tray .body = You can open it again or exit completely using tray icon menu # TODO: Translate +notification_stopped_with_error = Space Acres stopped with error + .body = An error happened and requires user intervention to resolve +# TODO: Translate +notification_farm_error = One of the farms failed in Space Acres + .body = An error happened and requires user intervention to resolve +# TODO: Translate notification_signed_reward_successfully = Signed new reward successfully 🥳 .body = Thank you for securing the network 🙌 # TODO: Translate diff --git a/res/translations/zh-CN/messages.ftl b/res/translations/zh-CN/messages.ftl index 6ad86cdc..414f8eea 100644 --- a/res/translations/zh-CN/messages.ftl +++ b/res/translations/zh-CN/messages.ftl @@ -206,6 +206,12 @@ tray_icon_close = Close notification_app_minimized_to_tray = Space Acres was minimized to tray .body = You can open it again or exit completely using tray icon menu # TODO: Translate +notification_stopped_with_error = Space Acres stopped with error + .body = An error happened and requires user intervention to resolve +# TODO: Translate +notification_farm_error = One of the farms failed in Space Acres + .body = An error happened and requires user intervention to resolve +# TODO: Translate notification_signed_reward_successfully = Signed new reward successfully 🥳 .body = Thank you for securing the network 🙌 # TODO: Translate diff --git a/src/frontend.rs b/src/frontend.rs index a0d0e121..9ab3b073 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -23,7 +23,7 @@ use relm4::actions::{RelmAction, RelmActionGroup}; use relm4::prelude::*; use relm4::{Sender, ShutdownReceiver}; use relm4_icons::icon_name; -use std::cell::Cell; +use std::cell::{Cell, LazyCell}; use std::future::Future; use std::path::PathBuf; use std::rc::Rc; @@ -34,6 +34,16 @@ pub const GLOBAL_CSS: &str = include_str!("../res/app.css"); const ICON: &[u8] = include_bytes!("../res/icon.png"); const ABOUT_IMAGE: &[u8] = include_bytes!("../res/about.png"); +#[thread_local] +static PIXBUF_ICON: LazyCell = LazyCell::new(|| { + gtk::gdk_pixbuf::Pixbuf::from_read(ICON).expect("Statically correct image; qed") +}); + +#[thread_local] +static PIXBUF_ABOUT_IMG: LazyCell = LazyCell::new(|| { + gtk::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE).expect("Statically correct image; qed") +}); + #[derive(Debug, Copy, Clone, Eq, PartialEq)] enum TrayMenuSignal { Open, @@ -252,10 +262,7 @@ impl AsyncComponent for App { gtk::Image { set_height_request: 256, - set_from_pixbuf: Some( - >k::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE) - .expect("Statically correct image; qed") - ), + set_from_pixbuf: Some(&*PIXBUF_ABOUT_IMG), }, gtk::Label { @@ -285,10 +292,7 @@ impl AsyncComponent for App { gtk::Image { set_height_request: 256, - set_from_pixbuf: Some( - >k::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE) - .expect("Statically correct image; qed") - ), + set_from_pixbuf: Some(&*PIXBUF_ABOUT_IMG), }, gtk::Label { @@ -495,10 +499,7 @@ impl AsyncComponent for App { .website(env!("CARGO_PKG_REPOSITORY")) .website_label("GitHub") .comments(env!("CARGO_PKG_DESCRIPTION")) - .logo(>k::gdk::Texture::for_pixbuf( - >k::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE) - .expect("Statically correct image; qed"), - )) + .logo(>k::gdk::Texture::for_pixbuf(&PIXBUF_ABOUT_IMG)) .system_information({ let config_directory = dirs::config_local_dir() .map(|config_local_dir| { @@ -659,13 +660,11 @@ impl AsyncComponent for App { move |_window| { if !notification_shown_already.replace(true) { - let icon = gtk::gdk_pixbuf::Pixbuf::from_read(ICON) - .expect("Statically correct image; qed"); let notification = gio::Notification::new(&T.notification_app_minimized_to_tray()); notification.set_body(Some(&T.notification_app_minimized_to_tray_body())); // TODO: This icon is not rendered properly for some reason - notification.set_icon(&icon); + notification.set_icon(&*PIXBUF_ICON); notification.set_priority(gio::NotificationPriority::Low); relm4::main_application().send_notification(None, ¬ification); } @@ -962,6 +961,13 @@ impl App { .emit(RunningInput::FarmerNotification(farmer_notification)); } BackendNotification::Stopped { error } => { + let notification = gio::Notification::new(&T.notification_stopped_with_error()); + notification.set_body(Some(&T.notification_stopped_with_error_body())); + // TODO: This icon is not rendered properly for some reason + notification.set_icon(&*PIXBUF_ICON); + notification.set_priority(gio::NotificationPriority::High); + relm4::main_application().send_notification(None, ¬ification); + self.set_current_view(View::Stopped(error)); } BackendNotification::IrrecoverableError { error } => { diff --git a/src/frontend/running.rs b/src/frontend/running.rs index 073e7844..1e9bc84b 100644 --- a/src/frontend/running.rs +++ b/src/frontend/running.rs @@ -11,7 +11,7 @@ use crate::frontend::translations::{AsDefaultStr, T}; use crate::frontend::widgets::progress_circle::{ ProgressCircle, ProgressCircleInit, ProgressCircleInput, }; -use crate::frontend::ICON; +use crate::frontend::PIXBUF_ICON; use gtk::gio; use gtk::prelude::*; use relm4::factory::FactoryHashMap; @@ -475,10 +475,8 @@ impl RunningView { } }; - let icon = gtk::gdk_pixbuf::Pixbuf::from_read(ICON) - .expect("Statically correct image; qed"); // TODO: This icon is not rendered properly for some reason - notification.set_icon(&icon); + notification.set_icon(&*PIXBUF_ICON); relm4::main_application().send_notification(None, ¬ification); } self.farms.send( diff --git a/src/frontend/running/farm.rs b/src/frontend/running/farm.rs index a4123139..4d8d167c 100644 --- a/src/frontend/running/farm.rs +++ b/src/frontend/running/farm.rs @@ -1,6 +1,8 @@ use crate::backend::farmer::DiskFarm; use crate::frontend::translations::{AsDefaultStr, T}; +use crate::frontend::PIXBUF_ICON; use bytesize::ByteSize; +use gtk::gio; use gtk::prelude::*; use relm4::prelude::*; use relm4_icons::icon_name; @@ -585,6 +587,13 @@ impl FarmWidget { self.set_farm_details(!self.farm_details); } FarmWidgetInput::Error { error } => { + let notification = gio::Notification::new(&T.notification_farm_error()); + notification.set_body(Some(&T.notification_farm_error_body())); + // TODO: This icon is not rendered properly for some reason + notification.set_icon(&*PIXBUF_ICON); + notification.set_priority(gio::NotificationPriority::High); + relm4::main_application().send_notification(None, ¬ification); + self.get_mut_error().replace(error); } } diff --git a/src/main.rs b/src/main.rs index 81b384d9..4ddf32c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ const_option, let_chains, result_flattening, + thread_local, trait_alias, try_blocks, variant_count