From 828fa2e91d3bea17dac4580be2f5399d68c45136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 23 Apr 2025 10:28:20 +0200 Subject: [PATCH] window: Show button to open About dialog on error page --- src/error_page.rs | 97 ++++++++++++++++++++++++++--------------------- src/error_page.ui | 28 ++++++++++++-- src/window.ui | 18 ++++----- 3 files changed, 88 insertions(+), 55 deletions(-) diff --git a/src/error_page.rs b/src/error_page.rs index 25852a93..08d7ba1e 100644 --- a/src/error_page.rs +++ b/src/error_page.rs @@ -1,14 +1,16 @@ use adw::{prelude::*, subclass::prelude::*}; use gettextrs::gettext; -use gtk::{self, glib, CompositeTemplate}; +use gtk::glib; -use crate::toast; +use crate::{toast, APP_ID}; /// The possible error subpages. #[derive(Debug, Clone, Copy, strum::AsRefStr)] #[strum(serialize_all = "kebab-case")] pub enum ErrorSubpage { + /// The page to present when there was an error with the secret API. Secret, + /// The page to present when there was an error when initializing a session. Session, } @@ -17,19 +19,19 @@ mod imp { use super::*; - #[derive(Debug, Default, CompositeTemplate)] + #[derive(Debug, Default, gtk::CompositeTemplate)] #[template(resource = "/org/gnome/Fractal/ui/error_page.ui")] pub struct ErrorPage { #[template_child] - pub stack: TemplateChild, + stack: TemplateChild, #[template_child] - pub secret_error_page: TemplateChild, + secret_error_page: TemplateChild, #[template_child] - pub linux_secret_instructions: TemplateChild, + linux_secret_instructions: TemplateChild, #[template_child] - pub secret_service_override_command: TemplateChild, + secret_service_override_command: TemplateChild, #[template_child] - pub session_error_page: TemplateChild, + session_error_page: TemplateChild, } #[glib::object_subclass] @@ -40,7 +42,7 @@ mod imp { fn class_init(klass: &mut Self::Class) { Self::bind_template(klass); - Self::Type::bind_template_callbacks(klass); + Self::bind_template_callbacks(klass); klass.set_accessible_role(gtk::AccessibleRole::Group); } @@ -53,6 +55,45 @@ mod imp { impl ObjectImpl for ErrorPage {} impl WidgetImpl for ErrorPage {} impl BinImpl for ErrorPage {} + + #[gtk::template_callbacks] + impl ErrorPage { + /// Display the given secret error. + pub(super) fn display_secret_error(&self, message: &str) { + #[cfg(not(target_os = "linux"))] + self.linux_secret_instructions.set_visible(false); + + #[cfg(target_os = "linux")] + { + self.linux_secret_instructions.set_visible(true); + + self.secret_service_override_command.set_markup(&format!( + "flatpak --user override --talk-name=org.freedesktop.secrets {APP_ID}", + )); + } + + self.secret_error_page.set_description(Some(message)); + self.stack + .set_visible_child_name(ErrorSubpage::Secret.as_ref()); + } + + /// Display the given session error. + pub(super) fn display_session_error(&self, message: &str) { + self.session_error_page.set_description(Some(message)); + self.stack + .set_visible_child_name(ErrorSubpage::Session.as_ref()); + } + + /// Copy the secret service override command to the clipboard. + #[template_callback] + fn copy_secret_service_override_command(&self) { + let obj = self.obj(); + let command = self.secret_service_override_command.label(); + obj.clipboard() + .set_text(command.trim_start_matches("").trim_end_matches("")); + toast!(obj, gettext("Command copied to clipboard")); + } + } } glib::wrapper! { @@ -61,48 +102,18 @@ glib::wrapper! { @extends gtk::Widget, adw::Bin, @implements gtk::Accessible; } -#[gtk::template_callbacks] impl ErrorPage { pub fn new() -> Self { glib::Object::new() } /// Display the given secret error. - pub fn display_secret_error(&self, message: &str) { - let imp = self.imp(); - - #[cfg(not(target_os = "linux"))] - imp.linux_secret_instructions.set_visible(false); - - #[cfg(target_os = "linux")] - { - imp.linux_secret_instructions.set_visible(true); - - imp.secret_service_override_command.set_markup(&format!( - "flatpak --user override --talk-name=org.freedesktop.secrets {}", - crate::config::APP_ID - )); - } - - imp.secret_error_page.set_description(Some(message)); - imp.stack - .set_visible_child_name(ErrorSubpage::Secret.as_ref()); - } - - /// Copy the secret service override command to the clipboard. - #[template_callback] - fn copy_secret_service_override_command(&self) { - let command = self.imp().secret_service_override_command.label(); - self.clipboard() - .set_text(command.trim_start_matches("").trim_end_matches("")); - toast!(self, gettext("Command copied to clipboard")); + pub(crate) fn display_secret_error(&self, message: &str) { + self.imp().display_secret_error(message); } /// Display the given session error. - pub fn display_session_error(&self, message: &str) { - let imp = self.imp(); - imp.session_error_page.set_description(Some(message)); - imp.stack - .set_visible_child_name(ErrorSubpage::Session.as_ref()); + pub(crate) fn display_session_error(&self, message: &str) { + self.imp().display_session_error(message); } } diff --git a/src/error_page.ui b/src/error_page.ui index f0c929be..e25acc30 100644 --- a/src/error_page.ui +++ b/src/error_page.ui @@ -11,7 +11,29 @@ - + + + + + + app.about + About Fractal + about-symbolic + + About Fractal + + + + + + + app.about + About Fractal + about-symbolic + + About Fractal + + @@ -35,7 +57,7 @@ true word-char - 0.0 + 0.0 Fractal relies on a Secret Portal to manage your sensitive session information and an error occurred while we were trying to restore your sessions. @@ -156,7 +178,7 @@ true word-char - 0.0 + 0.0 Check the application logs and your distribution’s documentation for more details. diff --git a/src/window.ui b/src/window.ui index 12a24f0a..a85e52ea 100644 --- a/src/window.ui +++ b/src/window.ui @@ -26,15 +26,15 @@ - app.about - About Fractal - about-symbolic - - About Fractal - - - - + app.about + About Fractal + about-symbolic + + About Fractal + + + +