From e8638a8f2466371b4c0ec1cbac234b019071caf3 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 7 Dec 2024 23:44:34 +0200 Subject: [PATCH] emit update action on identity logout --- .../window/tab/item/identity/gemini.rs | 6 ++- .../window/tab/item/identity/gemini/widget.rs | 20 +++++++--- .../tab/item/identity/gemini/widget/form.rs | 18 ++++++--- .../item/identity/gemini/widget/form/exit.rs | 37 +++++++++++-------- .../item/identity/gemini/widget/form/file.rs | 10 ++--- .../item/identity/gemini/widget/form/list.rs | 6 +-- .../item/identity/gemini/widget/form/name.rs | 6 +-- 7 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/app/browser/window/tab/item/identity/gemini.rs b/src/app/browser/window/tab/item/identity/gemini.rs index db775740..8618ad29 100644 --- a/src/app/browser/window/tab/item/identity/gemini.rs +++ b/src/app/browser/window/tab/item/identity/gemini.rs @@ -25,7 +25,11 @@ impl Gemini { let auth_url = auth_uri.to_string(); // Init widget - let widget = Rc::new(Widget::new(profile.clone(), &auth_url)); + let widget = Rc::new(Widget::new( + (action.0.clone(), action.1.clone()), + profile.clone(), + &auth_url, + )); // Init events widget.on_cancel({ diff --git a/src/app/browser/window/tab/item/identity/gemini/widget.rs b/src/app/browser/window/tab/item/identity/gemini/widget.rs index a9c12962..16842933 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget.rs @@ -1,10 +1,12 @@ mod action; pub mod form; -use action::Action; use form::{list::item::value::Value, Form}; +use crate::app::browser::action::Action as BrowserAction; +use crate::app::browser::window::action::Action as WindowAction; use crate::profile::Profile; +use action::Action as WidgetAction; use adw::{ prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, AlertDialog, ResponseAppearance, @@ -33,12 +35,20 @@ impl Widget { // Constructors /// Create new `Self` - pub fn new(profile: Rc, auth_url: &str) -> Self { + pub fn new( + action: (Rc, Rc), + profile: Rc, + auth_url: &str, + ) -> Self { // Init actions - let action = Rc::new(Action::new()); + let widget_action = Rc::new(WidgetAction::new()); // Init child container - let form = Rc::new(Form::new(profile, action.clone(), auth_url)); + let form = Rc::new(Form::new( + (action.0.clone(), action.1.clone(), widget_action.clone()), + profile, + auth_url, + )); // Init main widget let alert_dialog = AlertDialog::builder() @@ -64,7 +74,7 @@ impl Widget { alert_dialog.set_response_appearance(RESPONSE_CANCEL.0, ResponseAppearance::Destructive); // Init events - action.update.connect_activate({ + widget_action.update.connect_activate({ let form = form.clone(); let alert_dialog = alert_dialog.clone(); move || { diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs index affb2609..844c8015 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs @@ -12,7 +12,9 @@ use list::{item::value::Value, List}; use name::Name; use save::Save; -use super::Action; +use super::WidgetAction; +use crate::app::browser::action::Action as BrowserAction; +use crate::app::browser::window::action::Action as WindowAction; use crate::profile::Profile; use gtk::{prelude::BoxExt, Box, Orientation}; use std::rc::Rc; @@ -32,14 +34,18 @@ impl Form { // Constructors /// Create new `Self` - pub fn new(profile: Rc, action_widget: Rc, auth_url: &str) -> Self { + pub fn new( + action: (Rc, Rc, Rc), + profile: Rc, + auth_url: &str, + ) -> Self { // Init components - let list = Rc::new(List::new(action_widget.clone(), profile.clone(), auth_url)); - let file = Rc::new(File::new(action_widget.clone())); - let name = Rc::new(Name::new(action_widget.clone())); + let list = Rc::new(List::new(action.2.clone(), profile.clone(), auth_url)); + let file = Rc::new(File::new(action.2.clone())); + let name = Rc::new(Name::new(action.2.clone())); let save = Rc::new(Save::new(profile.clone(), list.clone())); let drop = Rc::new(Drop::new(profile.clone(), list.clone())); - let exit = Rc::new(Exit::new(profile.clone(), list.clone())); + let exit = Rc::new(Exit::new(action.0.clone(), profile.clone(), list.clone())); // Init main container let g_box = Box::builder().orientation(Orientation::Vertical).build(); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs index 6355e510..f91c2e72 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs @@ -1,4 +1,5 @@ use super::list::{item::Value, List}; +use crate::app::browser::action::Action as BrowserAction; use crate::profile::Profile; use adw::{ prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, @@ -29,7 +30,7 @@ impl Exit { // Constructors /// Create new `Self` - pub fn new(profile: Rc, list: Rc) -> Self { + pub fn new(browser_action: Rc, profile: Rc, list: Rc) -> Self { // Init main widget let button = Button::builder() .label(LABEL) @@ -69,29 +70,33 @@ impl Exit { // Connect confirmation event alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), { + let browser_action = browser_action.clone(); let button = button.clone(); let list = list.clone(); let profile = profile.clone(); - move |_, _| match profile - .identity - .gemini - .auth - .remove_ref(profile_identity_gemini_id) - { - Ok(_) => match list.selected().update(&profile, "") { - Ok(_) => { - button.set_css_classes(&["success"]); - button.set_label("Identity successfully disconnected") - } + move |_, _| { + match profile + .identity + .gemini + .auth + .remove_ref(profile_identity_gemini_id) + { + Ok(_) => match list.selected().update(&profile, "") { + Ok(_) => { + button.set_css_classes(&["success"]); + button.set_label("Identity successfully disconnected") + } + Err(e) => { + button.set_css_classes(&["error"]); + button.set_label(&e.to_string()) + } + }, Err(e) => { button.set_css_classes(&["error"]); button.set_label(&e.to_string()) } - }, - Err(e) => { - button.set_css_classes(&["error"]); - button.set_label(&e.to_string()) } + browser_action.update.activate(None) } }); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs index 54617b23..3f208bfb 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs @@ -1,4 +1,4 @@ -use super::Action; +use super::WidgetAction; use gtk::{ gio::{Cancellable, ListStore, TlsCertificate}, glib::{gformat, GString}, @@ -21,7 +21,7 @@ impl File { // Constructors /// Create new `Self` - pub fn new(action_widget: Rc) -> Self { + pub fn new(widget_action: Rc) -> Self { // Init PEM let pem = Rc::new(RefCell::new(None)); @@ -35,7 +35,7 @@ impl File { // Init events button.connect_clicked({ - let action_widget = action_widget.clone(); + let widget_action = widget_action.clone(); let button = button.clone(); let pem = pem.clone(); move |_| { @@ -61,7 +61,7 @@ impl File { .default_filter(&filter_pem) .build() .open(None::<&Window>, None::<&Cancellable>, { - let action_widget = action_widget.clone(); + let widget_action = widget_action.clone(); let button = button.clone(); let pem = pem.clone(); move |result| { @@ -89,7 +89,7 @@ impl File { } } button.set_sensitive(true); // unlock - action_widget.update.activate() + widget_action.update.activate() } }); } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs index c3814bda..2ca1b632 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use item::Item; -use super::Action; +use super::WidgetAction; use crate::profile::Profile; use gtk::{ gdk::Cursor, @@ -24,7 +24,7 @@ impl List { // Constructors /// Create new `Self` - pub fn new(action_widget: Rc, profile: Rc, auth_url: &str) -> Self { + pub fn new(widget_action: Rc, profile: Rc, auth_url: &str) -> Self { // Init model let list_store = ListStore::new::(); @@ -133,7 +133,7 @@ impl List { .build(); // Connect events - dropdown.connect_selected_notify(move |_| action_widget.update.activate()); + dropdown.connect_selected_notify(move |_| widget_action.update.activate()); // Return activated `Self` Self { diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs index 7fc2bb82..88f91e24 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs @@ -1,4 +1,4 @@ -use super::Action; +use super::WidgetAction; use gtk::{ glib::GString, prelude::{EditableExt, EntryExt, WidgetExt}, @@ -19,7 +19,7 @@ impl Name { // Constructors /// Create new `Self` - pub fn new(action_widget: Rc) -> Self { + pub fn new(widget_action: Rc) -> Self { // Init main gobject let entry = Entry::builder() .margin_top(MARGIN) @@ -29,7 +29,7 @@ impl Name { .build(); // Init events - entry.connect_changed(move |_| action_widget.update.activate()); + entry.connect_changed(move |_| widget_action.update.activate()); // Return activated `Self` Self { entry }