From 26e0a35d9449c11b8fff23678b71533647edd824 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 8 Dec 2024 00:37:40 +0200 Subject: [PATCH] implement auth_url for exit action --- .../browser/window/tab/item/identity/gemini.rs | 2 +- .../window/tab/item/identity/gemini/widget.rs | 6 +++--- .../tab/item/identity/gemini/widget/form.rs | 17 +++++++++++++---- .../item/identity/gemini/widget/form/exit.rs | 15 +++++++++++++-- .../item/identity/gemini/widget/form/list.rs | 9 +++++++-- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/app/browser/window/tab/item/identity/gemini.rs b/src/app/browser/window/tab/item/identity/gemini.rs index 8618ad29..a81d12a1 100644 --- a/src/app/browser/window/tab/item/identity/gemini.rs +++ b/src/app/browser/window/tab/item/identity/gemini.rs @@ -28,7 +28,7 @@ impl Gemini { let widget = Rc::new(Widget::new( (action.0.clone(), action.1.clone()), profile.clone(), - &auth_url, + auth_uri.clone(), )); // Init events 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 16842933..9e5c514e 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget.rs @@ -11,7 +11,7 @@ use adw::{ prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, AlertDialog, ResponseAppearance, }; -use gtk::prelude::IsA; +use gtk::{glib::Uri, prelude::IsA}; use std::rc::Rc; // Defaults @@ -38,7 +38,7 @@ impl Widget { pub fn new( action: (Rc, Rc), profile: Rc, - auth_url: &str, + auth_uri: Uri, ) -> Self { // Init actions let widget_action = Rc::new(WidgetAction::new()); @@ -47,7 +47,7 @@ impl Widget { let form = Rc::new(Form::new( (action.0.clone(), action.1.clone(), widget_action.clone()), profile, - auth_url, + auth_uri, )); // Init main widget 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 844c8015..c9a5fbdb 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 @@ -16,7 +16,7 @@ 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 gtk::{glib::Uri, prelude::BoxExt, Box, Orientation}; use std::rc::Rc; pub struct Form { @@ -37,15 +37,24 @@ impl Form { pub fn new( action: (Rc, Rc, Rc), profile: Rc, - auth_url: &str, + auth_uri: Uri, ) -> Self { // Init components - let list = Rc::new(List::new(action.2.clone(), profile.clone(), auth_url)); + let list = Rc::new(List::new( + action.2.clone(), + profile.clone(), + auth_uri.clone(), + )); 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(action.0.clone(), profile.clone(), list.clone())); + let exit = Rc::new(Exit::new( + action.0.clone(), + profile.clone(), + list.clone(), + auth_uri.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 f91c2e72..9c26964b 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 @@ -6,6 +6,7 @@ use adw::{ AlertDialog, ResponseAppearance, }; use gtk::{ + glib::Uri, prelude::{ButtonExt, WidgetExt}, Button, }; @@ -30,7 +31,12 @@ impl Exit { // Constructors /// Create new `Self` - pub fn new(browser_action: Rc, profile: Rc, list: Rc) -> Self { + pub fn new( + browser_action: Rc, + profile: Rc, + list: Rc, + auth_uri: Uri, + ) -> Self { // Init main widget let button = Button::builder() .label(LABEL) @@ -41,6 +47,7 @@ impl Exit { // Init events button.connect_clicked({ + let auth_uri = auth_uri.clone(); let button = button.clone(); move |_| { // Get selected identity from holder @@ -70,6 +77,7 @@ impl Exit { // Connect confirmation event alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), { + let auth_uri = auth_uri.clone(); let browser_action = browser_action.clone(); let button = button.clone(); let list = list.clone(); @@ -81,7 +89,10 @@ impl Exit { .auth .remove_ref(profile_identity_gemini_id) { - Ok(_) => match list.selected().update(&profile, "") { + Ok(_) => match list + .selected() + .update(&profile, &auth_uri.to_string()) + { Ok(_) => { button.set_css_classes(&["success"]); button.set_label("Identity successfully disconnected") 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 d8bc0dcb..d0a357d7 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 @@ -11,6 +11,7 @@ use gtk::{ prelude::{Cast, CastNone}, ListStore, }, + glib::Uri, prelude::{BoxExt, ListItemExt, WidgetExt}, Align, Box, DropDown, Image, Label, ListItem, Orientation, SignalListItemFactory, }; @@ -24,7 +25,7 @@ impl List { // Constructors /// Create new `Self` - pub fn new(widget_action: Rc, profile: Rc, auth_url: &str) -> Self { + pub fn new(widget_action: Rc, profile: Rc, auth_uri: Uri) -> Self { // Init model let list_store = ListStore::new::(); @@ -37,7 +38,11 @@ impl List { match profile.identity.gemini.database.records() { Ok(identities) => { for identity in identities { - match Item::new_profile_identity_gemini_id(&profile, identity.id, auth_url) { + match Item::new_profile_identity_gemini_id( + &profile, + identity.id, + &auth_uri.to_string(), + ) { Ok(item) => list_store.append(&item), Err(_) => todo!(), }