Skip to content

Commit

Permalink
Merge pull request #281 from autonomys/error-notifications
Browse files Browse the repository at this point in the history
Error notifications
  • Loading branch information
nazar-pc authored Aug 9, 2024
2 parents 5098b66 + 3b162db commit c8a163c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 20 deletions.
4 changes: 4 additions & 0 deletions res/translations/en/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 😞
Expand Down
6 changes: 6 additions & 0 deletions res/translations/rs/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions res/translations/zh-CN/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 22 additions & 16 deletions src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<gtk::gdk_pixbuf::Pixbuf> = LazyCell::new(|| {
gtk::gdk_pixbuf::Pixbuf::from_read(ICON).expect("Statically correct image; qed")
});

#[thread_local]
static PIXBUF_ABOUT_IMG: LazyCell<gtk::gdk_pixbuf::Pixbuf> = LazyCell::new(|| {
gtk::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE).expect("Statically correct image; qed")
});

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum TrayMenuSignal {
Open,
Expand Down Expand Up @@ -252,10 +262,7 @@ impl AsyncComponent for App {

gtk::Image {
set_height_request: 256,
set_from_pixbuf: Some(
&gtk::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE)
.expect("Statically correct image; qed")
),
set_from_pixbuf: Some(&*PIXBUF_ABOUT_IMG),
},

gtk::Label {
Expand Down Expand Up @@ -285,10 +292,7 @@ impl AsyncComponent for App {

gtk::Image {
set_height_request: 256,
set_from_pixbuf: Some(
&gtk::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE)
.expect("Statically correct image; qed")
),
set_from_pixbuf: Some(&*PIXBUF_ABOUT_IMG),
},

gtk::Label {
Expand Down Expand Up @@ -495,10 +499,7 @@ impl AsyncComponent for App {
.website(env!("CARGO_PKG_REPOSITORY"))
.website_label("GitHub")
.comments(env!("CARGO_PKG_DESCRIPTION"))
.logo(&gtk::gdk::Texture::for_pixbuf(
&gtk::gdk_pixbuf::Pixbuf::from_read(ABOUT_IMAGE)
.expect("Statically correct image; qed"),
))
.logo(&gtk::gdk::Texture::for_pixbuf(&PIXBUF_ABOUT_IMG))
.system_information({
let config_directory = dirs::config_local_dir()
.map(|config_local_dir| {
Expand Down Expand Up @@ -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, &notification);
}
Expand Down Expand Up @@ -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, &notification);

self.set_current_view(View::Stopped(error));
}
BackendNotification::IrrecoverableError { error } => {
Expand Down
6 changes: 2 additions & 4 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, &notification);
}
self.farms.send(
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/running/farm.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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, &notification);

self.get_mut_error().replace(error);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const_option,
let_chains,
result_flattening,
thread_local,
trait_alias,
try_blocks,
variant_count
Expand Down

0 comments on commit c8a163c

Please sign in to comment.