Browse Source

window: Show button to open About dialog on error page

merge-requests/2003/head
Kévin Commaille 12 months ago committed by Kévin Commaille
parent
commit
828fa2e91d
  1. 97
      src/error_page.rs
  2. 28
      src/error_page.ui
  3. 18
      src/window.ui

97
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<gtk::Stack>,
stack: TemplateChild<gtk::Stack>,
#[template_child]
pub secret_error_page: TemplateChild<adw::StatusPage>,
secret_error_page: TemplateChild<adw::StatusPage>,
#[template_child]
pub linux_secret_instructions: TemplateChild<adw::Clamp>,
linux_secret_instructions: TemplateChild<adw::Clamp>,
#[template_child]
pub secret_service_override_command: TemplateChild<gtk::Label>,
secret_service_override_command: TemplateChild<gtk::Label>,
#[template_child]
pub session_error_page: TemplateChild<adw::StatusPage>,
session_error_page: TemplateChild<adw::StatusPage>,
}
#[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!(
"<tt>flatpak --user override --talk-name=org.freedesktop.secrets {APP_ID}</tt>",
));
}
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("<tt>").trim_end_matches("</tt>"));
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!(
"<tt>flatpak --user override --talk-name=org.freedesktop.secrets {}</tt>",
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("<tt>").trim_end_matches("</tt>"));
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);
}
}

28
src/error_page.ui

@ -11,7 +11,29 @@
</object>
</property>
<child type="start">
<object class="AccountSwitcherButton"/>
<object class="AccountSwitcherButton" id="account_switcher"/>
</child>
<child type="start">
<object class="GtkButton">
<property name="visible" bind-source="account_switcher" bind-property="visible" bind-flags="sync-create | invert-boolean"/>
<property name="action-name">app.about</property>
<property name="tooltip-text" translatable="yes">About Fractal</property>
<property name="icon-name">about-symbolic</property>
<accessibility>
<property name="label" translatable="yes">About Fractal</property>
</accessibility>
</object>
</child>
<child type="end">
<object class="GtkButton">
<property name="visible" bind-source="account_switcher" bind-property="visible" bind-flags="sync-create"/>
<property name="action-name">app.about</property>
<property name="tooltip-text" translatable="yes">About Fractal</property>
<property name="icon-name">about-symbolic</property>
<accessibility>
<property name="label" translatable="yes">About Fractal</property>
</accessibility>
</object>
</child>
</object>
</child>
@ -35,7 +57,7 @@
<object class="GtkLabel">
<property name="wrap">true</property>
<property name="wrap-mode">word-char</property>
<property name="xalign">0.0</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Fractal relies on a Secret Portal to manage your sensitive session information and an error occurred while we were trying to restore your sessions.</property>
</object>
</child>
@ -156,7 +178,7 @@
<object class="GtkLabel">
<property name="wrap">true</property>
<property name="wrap-mode">word-char</property>
<property name="xalign">0.0</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Check the application logs and your distribution’s documentation for more details.</property>
</object>
</child>

18
src/window.ui

@ -26,15 +26,15 @@
</child>
<child type="end">
<object class="GtkButton">
<property name="action-name">app.about</property>
<property name="tooltip-text" translatable="yes">About Fractal</property>
<property name="icon-name">about-symbolic</property>
<accessibility>
<property name="label" translatable="yes">About Fractal</property>
</accessibility>
</object>
</child>
</object>
<property name="action-name">app.about</property>
<property name="tooltip-text" translatable="yes">About Fractal</property>
<property name="icon-name">about-symbolic</property>
<accessibility>
<property name="label" translatable="yes">About Fractal</property>
</accessibility>
</object>
</child>
</object>
</child>
<property name="content">
<object class="GtkBox">

Loading…
Cancel
Save