From a19aa8206baba13b42018a7b18641fe37c2182dc Mon Sep 17 00:00:00 2001 From: uku Date: Wed, 21 May 2025 22:28:30 +0200 Subject: [PATCH] feat: add alert dialog for opening failures --- src/main.rs | 11 +++++------ src/relm.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2e7d6f5..7b31212 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::{borrow::Cow, path::PathBuf, time::Duration}; use color_eyre::eyre::{OptionExt, Result, bail}; use gobject::GtkZiplineFolder; -use relm::{Dialog, DialogInput, Toast, ToastInput}; +use relm::{Dialog, DialogInput, StandaloneDialog, Toast, ToastInput}; use relm4::{ Component, ComponentController, Controller, RelmApp, Sender, adw::{self, prelude::*}, @@ -400,11 +400,10 @@ fn main() -> Result<()> { color_eyre::install()?; - // TODO: show dialog in case these error - let config = get_config()?; - - let app = RelmApp::new("net.uku3lig.Tyrolienne"); - app.run_async::(config); + match get_config() { + Ok(config) => RelmApp::new("net.uku3lig.Tyrolienne").run_async::(config), + Err(e) => RelmApp::new("net.uku3lig.Tyrolienne").run::(e.to_string()), + } Ok(()) } diff --git a/src/relm.rs b/src/relm.rs index 0b0c578..1cefedf 100644 --- a/src/relm.rs +++ b/src/relm.rs @@ -148,3 +148,53 @@ impl SimpleComponent for Toast { } } } + +pub struct StandaloneDialog; + +impl SimpleComponent for StandaloneDialog { + type Init = String; + type Input = (); + type Output = (); + type Root = adw::ApplicationWindow; + type Widgets = (); + + fn init_root() -> Self::Root { + adw::ApplicationWindow::builder() + .title("Tyrolienne") + .default_width(400) + .default_height(300) + .build() + } + + fn init( + init: Self::Init, + root: Self::Root, + _sender: relm4::ComponentSender, + ) -> relm4::ComponentParts { + let dialog = adw::AlertDialog::builder() + .heading("Could not open Tyrolienne") + .body(init) + .close_response("close") + .build(); + dialog.add_response("close", "Close"); + + dialog.connect_closed(clone!( + #[strong] + root, + move |_| root.close() + )); + + root.connect_show(clone!( + #[strong] + dialog, + #[strong] + root, + move |_| dialog.present(Some(&root)) + )); + + relm4::ComponentParts { + model: StandaloneDialog, + widgets: (), + } + } +}