Skip to content

Commit

Permalink
remove scheme from scope, rename build constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 23, 2025
1 parent 9371f16 commit 089a91d
Show file tree
Hide file tree
Showing 25 changed files with 103 additions and 72 deletions.
4 changes: 2 additions & 2 deletions src/app/browser/window/tab/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Item {
// Route by scheme
let scheme = uri.scheme();
if scheme == "gemini" || scheme == "titan" {
return identity::new_gemini(
return identity::default(
(&browser_action, &window_action),
&profile,
&uri,
Expand All @@ -106,7 +106,7 @@ impl Item {
}
}
// Show dialog with unsupported request message
identity::new_unsupported().present(Some(&parent));
identity::unsupported().present(Some(&parent));
}
});

Expand Down
12 changes: 6 additions & 6 deletions src/app/browser/window/tab/item/identity.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
mod gemini;
mod default;
mod unsupported;

use gemini::Gemini;
use default::Default;
use unsupported::Unsupported;

use super::{BrowserAction, Profile, WindowAction};
use gtk::glib::Uri;
use std::rc::Rc;

/// Create new identity widget for Gemini protocol match given URI
pub fn new_gemini(
pub fn default(
action: (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>,
auth_uri: &Uri,
) -> Gemini {
Gemini::new(action, profile, auth_uri)
) -> Default {
Default::build(action, profile, auth_uri)
}

/// Create new identity widget for unknown request
pub fn new_unsupported() -> Unsupported {
pub fn unsupported() -> Unsupported {
Unsupported::new()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,49 @@ mod widget;
use widget::{form::list::item::value::Value, Widget};

use super::{BrowserAction, Profile, WindowAction};
use gtk::{glib::Uri, prelude::IsA};
use gtk::{
glib::{Regex, RegexCompileFlags, RegexMatchFlags, Uri},
prelude::IsA,
};
use std::rc::Rc;

pub struct Gemini {
pub struct Default {
// profile: Rc<Profile>,
widget: Rc<Widget>,
}

impl Gemini {
impl Default {
// Construct

/// Create new `Self` for given `Profile`
pub fn new(
pub fn build(
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>,
auth_uri: &Uri,
) -> Self {
// Init shared URL string from URI
// 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::new(
let widget = Rc::new(Widget::build(
(browser_action, window_action),
profile,
auth_uri,
&scope,
));

// Init events
Expand Down Expand Up @@ -63,16 +81,15 @@ impl Gemini {

// Apply auth
match option {
// Activate identity for `auth_uri`
// Activate identity for `scope`
Some(profile_identity_id) => {
if let Err(e) = profile.identity.auth.apply(profile_identity_id, &auth_url)
{
if let Err(e) = profile.identity.auth.apply(profile_identity_id, &scope) {
todo!("{}", e.to_string())
};
}
// Remove all identity auths for `auth_uri`
// Remove all identity auths for `scope`
None => {
if let Err(e) = profile.identity.auth.remove_scope(&auth_url) {
if let Err(e) = profile.identity.auth.remove_scope(&scope) {
todo!("{}", e.to_string())
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use adw::{
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
AlertDialog, ResponseAppearance,
};
use gtk::{glib::Uri, prelude::IsA};
use gtk::prelude::IsA;
use std::rc::Rc;

// Defaults
Expand All @@ -36,19 +36,19 @@ impl Widget {
// Constructors

/// Create new `Self`
pub fn new(
pub fn build(
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>,
auth_uri: &Uri,
scope: &str,
) -> Self {
// Init actions
let widget_action = Rc::new(WidgetAction::new());

// Init child container
let form = Rc::new(Form::new(
let form = Rc::new(Form::build(
(browser_action, window_action, &widget_action),
profile,
auth_uri,
scope,
));

// Init main widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
app::browser::{action::Action as BrowserAction, window::action::Action as WindowAction},
Profile,
};
use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation};
use gtk::{prelude::BoxExt, Box, Orientation};
use std::rc::Rc;

pub struct Form {
Expand All @@ -29,34 +29,34 @@ pub struct Form {
pub name: Rc<Name>,
pub save: Rc<Save>,
pub g_box: Box,
auth_uri: Uri,
scope: String,
profile: Rc<Profile>,
}

impl Form {
// Constructors

/// Create new `Self`
pub fn new(
pub fn build(
(browser_action, _window_action, widget_action): (
&Rc<BrowserAction>,
&Rc<WindowAction>,
&Rc<WidgetAction>,
),
profile: &Rc<Profile>,
auth_uri: &Uri,
scope: &str,
) -> Self {
// Init components
let list = Rc::new(List::new(widget_action, profile, auth_uri));
let file = Rc::new(File::new(widget_action));
let name = Rc::new(Name::new(widget_action));
let save = Rc::new(Save::new(profile, &list));
let drop = Rc::new(Drop::new(profile, &list));
let exit = Rc::new(Exit::new(
let list = Rc::new(List::build(widget_action, profile, scope));
let file = Rc::new(File::build(widget_action));
let name = Rc::new(Name::build(widget_action));
let save = Rc::new(Save::build(profile, &list));
let drop = Rc::new(Drop::build(profile, &list));
let exit = Rc::new(Exit::build(
(browser_action, widget_action),
profile,
&list,
auth_uri,
scope,
));

// Init main container
Expand All @@ -79,7 +79,7 @@ impl Form {
name,
save,
g_box,
auth_uri: auth_uri.clone(),
scope: scope.to_string(),
profile: profile.clone(),
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Form {
.identity
.auth
.memory
.match_scope(&self.auth_uri.to_string())
.match_scope(&self.scope)
.is_some_and(|auth| auth.profile_identity_id == profile_identity_id),
);
self.save.update(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Drop {
// Constructors

/// Create new `Self`
pub fn new(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
pub fn build(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
// Init main widget
let button = Button::builder()
.label(LABEL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use adw::{
AlertDialog, ResponseAppearance,
};
use gtk::{
glib::Uri,
prelude::{ButtonExt, WidgetExt},
Button,
};
Expand All @@ -33,11 +32,11 @@ impl Exit {
// Constructors

/// Create new `Self`
pub fn new(
pub fn build(
(browser_action, widget_action): (&Rc<BrowserAction>, &Rc<WidgetAction>),
profile: &Rc<Profile>,
list: &Rc<List>,
auth_uri: &Uri,
scope: &str,
) -> Self {
// Init main widget
let button = Button::builder()
Expand All @@ -49,7 +48,7 @@ impl Exit {

// Init events
button.connect_clicked({
let auth_uri = auth_uri.clone();
let scope = scope.to_string();
let browser_action = browser_action.clone();
let button = button.clone();
let list = list.clone();
Expand Down Expand Up @@ -84,27 +83,27 @@ impl Exit {

// Connect confirmation event
alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), {
let auth_uri = auth_uri.clone();
let scope = scope.clone();
let button = button.clone();
let list = list.clone();
let profile = profile.clone();
let browser_action = browser_action.clone();
let widget_action = widget_action.clone();
move |_, _| {
match profile.identity.auth.remove_ref(profile_identity_id) {
Ok(_) => match list
.selected()
.update(&profile, &auth_uri.to_string())
{
Ok(_) => {
button.set_css_classes(&["success"]);
button.set_label("Identity successfully disconnected")
Ok(_) => {
match list.selected().update(&profile, &scope.to_string()) {
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl File {
// Constructors

/// Create new `Self`
pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
pub fn build(widget_action: &Rc<WidgetAction>) -> Self {
// Init PEM
let pem = Rc::new(RefCell::new(None));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use gtk::{
prelude::{Cast, CastNone},
ListStore,
},
glib::Uri,
prelude::{BoxExt, ListItemExt, ObjectExt, WidgetExt},
Align, Box, DropDown, Image, Label, ListItem, Orientation, SignalListItemFactory,
};
Expand All @@ -25,7 +24,7 @@ impl List {
// Constructors

/// Create new `Self`
pub fn new(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, auth_uri: &Uri) -> Self {
pub fn build(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, scope: &str) -> Self {
// Init dropdown items
let guest_session = Item::new_guest_session();
let generate_pem = Item::new_generate_pem();
Expand All @@ -42,8 +41,7 @@ impl List {
Ok(identities) => {
let mut is_guest_session = true;
for identity in identities {
match Item::new_profile_identity_id(profile, identity.id, &auth_uri.to_string())
{
match Item::new_profile_identity_id(profile, identity.id, scope) {
Ok(item) => {
if item.is_active() {
is_guest_session = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Name {
// Constructors

/// Create new `Self`
pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
pub fn build(widget_action: &Rc<WidgetAction>) -> Self {
// Init main gobject
let entry = Entry::builder()
.margin_top(MARGIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Save {
// Constructors

/// Create new `Self`
pub fn new(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
pub fn build(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
// Init main widget
let button = Button::builder()
.label(LABEL)
Expand Down
10 changes: 2 additions & 8 deletions src/app/browser/window/tab/item/page/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,8 @@ impl Navigation {
.update(self.profile.bookmark.get(&request).is_ok());
self.history.update();
self.reload.update(!request.is_empty());
self.request.update(
self.profile
.identity
.auth
.memory
.match_scope(&request)
.is_some(),
);
self.request
.update(self.profile.identity.match_scope(&request).is_some());
self.home.update();
}

Expand Down
Loading

0 comments on commit 089a91d

Please sign in to comment.