From 9a7984f3452be354ebeac191a065342ad1b0c800 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 23 Jan 2025 12:50:53 +0200 Subject: [PATCH] use uri for request --- src/app/browser/window/tab/item/identity.rs | 4 +- .../window/tab/item/identity/default.rs | 44 ++++++------------- .../tab/item/identity/default/widget.rs | 6 +-- .../tab/item/identity/default/widget/form.rs | 14 +++--- .../item/identity/default/widget/form/exit.rs | 12 ++--- .../item/identity/default/widget/form/list.rs | 6 ++- 6 files changed, 37 insertions(+), 49 deletions(-) diff --git a/src/app/browser/window/tab/item/identity.rs b/src/app/browser/window/tab/item/identity.rs index adafd1ea..c210a014 100644 --- a/src/app/browser/window/tab/item/identity.rs +++ b/src/app/browser/window/tab/item/identity.rs @@ -12,9 +12,9 @@ use std::rc::Rc; pub fn default( action: (&Rc, &Rc), profile: &Rc, - auth_uri: &Uri, + request: &Uri, ) -> Default { - Default::build(action, profile, auth_uri) + Default::build(action, profile, request) } /// Create new identity widget for unknown request diff --git a/src/app/browser/window/tab/item/identity/default.rs b/src/app/browser/window/tab/item/identity/default.rs index 666bab4b..9f2bf8d1 100644 --- a/src/app/browser/window/tab/item/identity/default.rs +++ b/src/app/browser/window/tab/item/identity/default.rs @@ -2,10 +2,7 @@ mod widget; use widget::{form::list::item::value::Value, Widget}; use super::{BrowserAction, Profile, WindowAction}; -use gtk::{ - glib::{Regex, RegexCompileFlags, RegexMatchFlags, Uri}, - prelude::IsA, -}; +use gtk::{glib::Uri, prelude::IsA}; use std::rc::Rc; pub struct Default { @@ -20,31 +17,13 @@ impl Default { pub fn build( (browser_action, window_action): (&Rc, &Rc), profile: &Rc, - auth_uri: &Uri, + request: &Uri, ) -> Self { - // Init scope - let auth_url = auth_uri.to_string(); - - let scope = match Regex::split_simple( - r"^\w+://(.*)", - &auth_url, - RegexCompileFlags::DEFAULT, - RegexMatchFlags::DEFAULT, - ) - .get(1) - { - Some(postfix) => postfix.to_string(), - None => auth_url, // @TODO warn? - } - .trim() - .trim_end_matches("/") - .to_lowercase(); - // Init widget let widget = Rc::new(Widget::build( (browser_action, window_action), profile, - &scope, + request, )); // Init events @@ -55,6 +34,7 @@ impl Default { widget.on_apply({ let profile = profile.clone(); + let request = request.clone(); let widget = widget.clone(); let window_action = window_action.clone(); move |response| { @@ -68,13 +48,13 @@ impl Default { .make(None, &widget.form.name.value().unwrap()) { Ok(profile_identity_id) => profile_identity_id, - Err(e) => todo!("{}", e.to_string()), + Err(e) => todo!("{e}"), }, ), Value::ImportPem => Some( match profile.identity.add(&widget.form.file.pem.take().unwrap()) { Ok(profile_identity_id) => profile_identity_id, - Err(e) => todo!("{}", e.to_string()), + Err(e) => todo!("{e}"), }, ), }; @@ -83,14 +63,18 @@ impl Default { match option { // Activate identity for `scope` Some(profile_identity_id) => { - if let Err(e) = profile.identity.auth.apply(profile_identity_id, &scope) { - todo!("{}", e.to_string()) + if let Err(e) = profile + .identity + .auth + .apply(profile_identity_id, &request.to_string()) + { + todo!("{e}") }; } // Remove all identity auths for `scope` None => { - if let Err(e) = profile.identity.auth.remove_scope(&scope) { - todo!("{}", e.to_string()) + if let Err(e) = profile.identity.auth.remove_scope(&request.to_string()) { + todo!("{e}") }; } } diff --git a/src/app/browser/window/tab/item/identity/default/widget.rs b/src/app/browser/window/tab/item/identity/default/widget.rs index 50088eeb..eacd5d6c 100644 --- a/src/app/browser/window/tab/item/identity/default/widget.rs +++ b/src/app/browser/window/tab/item/identity/default/widget.rs @@ -12,7 +12,7 @@ use adw::{ prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, AlertDialog, ResponseAppearance, }; -use gtk::prelude::IsA; +use gtk::{glib::Uri, prelude::IsA}; use std::rc::Rc; // Defaults @@ -39,7 +39,7 @@ impl Widget { pub fn build( (browser_action, window_action): (&Rc, &Rc), profile: &Rc, - scope: &str, + request: &Uri, ) -> Self { // Init actions let widget_action = Rc::new(WidgetAction::new()); @@ -48,7 +48,7 @@ impl Widget { let form = Rc::new(Form::build( (browser_action, window_action, &widget_action), profile, - scope, + request, )); // Init main widget diff --git a/src/app/browser/window/tab/item/identity/default/widget/form.rs b/src/app/browser/window/tab/item/identity/default/widget/form.rs index c8062679..67e8a7f5 100644 --- a/src/app/browser/window/tab/item/identity/default/widget/form.rs +++ b/src/app/browser/window/tab/item/identity/default/widget/form.rs @@ -17,7 +17,7 @@ use crate::{ app::browser::{action::Action as BrowserAction, window::action::Action as WindowAction}, Profile, }; -use gtk::{prelude::BoxExt, Box, Orientation}; +use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation}; use std::rc::Rc; pub struct Form { @@ -29,7 +29,7 @@ pub struct Form { pub name: Rc, pub save: Rc, pub g_box: Box, - scope: String, + request: Uri, profile: Rc, } @@ -44,10 +44,10 @@ impl Form { &Rc, ), profile: &Rc, - scope: &str, + request: &Uri, ) -> Self { // Init components - let list = Rc::new(List::build(widget_action, profile, scope)); + let list = Rc::new(List::build(widget_action, profile, request)); let file = Rc::new(File::build(widget_action)); let name = Rc::new(Name::build(widget_action)); let save = Rc::new(Save::build(profile, &list)); @@ -56,7 +56,7 @@ impl Form { (browser_action, widget_action), profile, &list, - scope, + request, )); // Init main container @@ -79,7 +79,7 @@ impl Form { name, save, g_box, - scope: scope.to_string(), + request: request.clone(), profile: profile.clone(), } } @@ -112,7 +112,7 @@ impl Form { .identity .auth .memory - .match_scope(&self.scope) + .match_scope(&self.request.to_string()) .is_some_and(|auth| auth.profile_identity_id == profile_identity_id), ); self.save.update(true); diff --git a/src/app/browser/window/tab/item/identity/default/widget/form/exit.rs b/src/app/browser/window/tab/item/identity/default/widget/form/exit.rs index 8de9c1b6..ae49a6d7 100644 --- a/src/app/browser/window/tab/item/identity/default/widget/form/exit.rs +++ b/src/app/browser/window/tab/item/identity/default/widget/form/exit.rs @@ -8,6 +8,7 @@ use adw::{ AlertDialog, ResponseAppearance, }; use gtk::{ + glib::Uri, prelude::{ButtonExt, WidgetExt}, Button, }; @@ -36,7 +37,7 @@ impl Exit { (browser_action, widget_action): (&Rc, &Rc), profile: &Rc, list: &Rc, - scope: &str, + request: &Uri, ) -> Self { // Init main widget let button = Button::builder() @@ -48,11 +49,11 @@ impl Exit { // Init events button.connect_clicked({ - let scope = scope.to_string(); let browser_action = browser_action.clone(); let button = button.clone(); let list = list.clone(); let profile = profile.clone(); + let request = request.clone(); let widget_action = widget_action.clone(); move |_| { // Get selected identity from holder @@ -83,16 +84,17 @@ impl Exit { // Connect confirmation event alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), { - let scope = scope.clone(); + let browser_action = browser_action.clone(); let button = button.clone(); let list = list.clone(); let profile = profile.clone(); - let browser_action = browser_action.clone(); + let request = request.clone(); let widget_action = widget_action.clone(); move |_, _| { match profile.identity.auth.remove_ref(profile_identity_id) { Ok(_) => { - match list.selected().update(&profile, &scope.to_string()) { + match list.selected().update(&profile, &request.to_string()) + { Ok(_) => { button.set_css_classes(&["success"]); button diff --git a/src/app/browser/window/tab/item/identity/default/widget/form/list.rs b/src/app/browser/window/tab/item/identity/default/widget/form/list.rs index a93bff2f..3561a188 100644 --- a/src/app/browser/window/tab/item/identity/default/widget/form/list.rs +++ b/src/app/browser/window/tab/item/identity/default/widget/form/list.rs @@ -11,6 +11,7 @@ use gtk::{ prelude::{Cast, CastNone}, ListStore, }, + glib::Uri, prelude::{BoxExt, ListItemExt, ObjectExt, WidgetExt}, Align, Box, DropDown, Image, Label, ListItem, Orientation, SignalListItemFactory, }; @@ -24,7 +25,7 @@ impl List { // Constructors /// Create new `Self` - pub fn build(widget_action: &Rc, profile: &Rc, scope: &str) -> Self { + pub fn build(widget_action: &Rc, profile: &Rc, request: &Uri) -> Self { // Init dropdown items let guest_session = Item::new_guest_session(); let generate_pem = Item::new_generate_pem(); @@ -41,7 +42,8 @@ impl List { Ok(identities) => { let mut is_guest_session = true; for identity in identities { - match Item::new_profile_identity_id(profile, identity.id, scope) { + match Item::new_profile_identity_id(profile, identity.id, &request.to_string()) + { Ok(item) => { if item.is_active() { is_guest_session = false;