mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
remove scheme from scope, rename build constructors
This commit is contained in:
parent
9371f16798
commit
089a91d5a2
25 changed files with 103 additions and 72 deletions
|
|
@ -97,7 +97,7 @@ impl Item {
|
||||||
// Route by scheme
|
// Route by scheme
|
||||||
let scheme = uri.scheme();
|
let scheme = uri.scheme();
|
||||||
if scheme == "gemini" || scheme == "titan" {
|
if scheme == "gemini" || scheme == "titan" {
|
||||||
return identity::new_gemini(
|
return identity::default(
|
||||||
(&browser_action, &window_action),
|
(&browser_action, &window_action),
|
||||||
&profile,
|
&profile,
|
||||||
&uri,
|
&uri,
|
||||||
|
|
@ -106,7 +106,7 @@ impl Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Show dialog with unsupported request message
|
// Show dialog with unsupported request message
|
||||||
identity::new_unsupported().present(Some(&parent));
|
identity::unsupported().present(Some(&parent));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
mod gemini;
|
mod default;
|
||||||
mod unsupported;
|
mod unsupported;
|
||||||
|
|
||||||
use gemini::Gemini;
|
use default::Default;
|
||||||
use unsupported::Unsupported;
|
use unsupported::Unsupported;
|
||||||
|
|
||||||
use super::{BrowserAction, Profile, WindowAction};
|
use super::{BrowserAction, Profile, WindowAction};
|
||||||
|
|
@ -9,15 +9,15 @@ use gtk::glib::Uri;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Create new identity widget for Gemini protocol match given URI
|
/// Create new identity widget for Gemini protocol match given URI
|
||||||
pub fn new_gemini(
|
pub fn default(
|
||||||
action: (&Rc<BrowserAction>, &Rc<WindowAction>),
|
action: (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||||
profile: &Rc<Profile>,
|
profile: &Rc<Profile>,
|
||||||
auth_uri: &Uri,
|
auth_uri: &Uri,
|
||||||
) -> Gemini {
|
) -> Default {
|
||||||
Gemini::new(action, profile, auth_uri)
|
Default::build(action, profile, auth_uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create new identity widget for unknown request
|
/// Create new identity widget for unknown request
|
||||||
pub fn new_unsupported() -> Unsupported {
|
pub fn unsupported() -> Unsupported {
|
||||||
Unsupported::new()
|
Unsupported::new()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,49 @@ mod widget;
|
||||||
use widget::{form::list::item::value::Value, Widget};
|
use widget::{form::list::item::value::Value, Widget};
|
||||||
|
|
||||||
use super::{BrowserAction, Profile, WindowAction};
|
use super::{BrowserAction, Profile, WindowAction};
|
||||||
use gtk::{glib::Uri, prelude::IsA};
|
use gtk::{
|
||||||
|
glib::{Regex, RegexCompileFlags, RegexMatchFlags, Uri},
|
||||||
|
prelude::IsA,
|
||||||
|
};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub struct Gemini {
|
pub struct Default {
|
||||||
// profile: Rc<Profile>,
|
// profile: Rc<Profile>,
|
||||||
widget: Rc<Widget>,
|
widget: Rc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gemini {
|
impl Default {
|
||||||
// Construct
|
// Construct
|
||||||
|
|
||||||
/// Create new `Self` for given `Profile`
|
/// Create new `Self` for given `Profile`
|
||||||
pub fn new(
|
pub fn build(
|
||||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||||
profile: &Rc<Profile>,
|
profile: &Rc<Profile>,
|
||||||
auth_uri: &Uri,
|
auth_uri: &Uri,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Init shared URL string from URI
|
// Init scope
|
||||||
let auth_url = auth_uri.to_string();
|
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
|
// Init widget
|
||||||
let widget = Rc::new(Widget::new(
|
let widget = Rc::new(Widget::build(
|
||||||
(browser_action, window_action),
|
(browser_action, window_action),
|
||||||
profile,
|
profile,
|
||||||
auth_uri,
|
&scope,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
|
|
@ -63,16 +81,15 @@ impl Gemini {
|
||||||
|
|
||||||
// Apply auth
|
// Apply auth
|
||||||
match option {
|
match option {
|
||||||
// Activate identity for `auth_uri`
|
// Activate identity for `scope`
|
||||||
Some(profile_identity_id) => {
|
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())
|
todo!("{}", e.to_string())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Remove all identity auths for `auth_uri`
|
// Remove all identity auths for `scope`
|
||||||
None => {
|
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())
|
todo!("{}", e.to_string())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ use adw::{
|
||||||
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
|
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
|
||||||
AlertDialog, ResponseAppearance,
|
AlertDialog, ResponseAppearance,
|
||||||
};
|
};
|
||||||
use gtk::{glib::Uri, prelude::IsA};
|
use gtk::prelude::IsA;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
|
|
@ -36,19 +36,19 @@ impl Widget {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(
|
pub fn build(
|
||||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||||
profile: &Rc<Profile>,
|
profile: &Rc<Profile>,
|
||||||
auth_uri: &Uri,
|
scope: &str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Init actions
|
// Init actions
|
||||||
let widget_action = Rc::new(WidgetAction::new());
|
let widget_action = Rc::new(WidgetAction::new());
|
||||||
|
|
||||||
// Init child container
|
// Init child container
|
||||||
let form = Rc::new(Form::new(
|
let form = Rc::new(Form::build(
|
||||||
(browser_action, window_action, &widget_action),
|
(browser_action, window_action, &widget_action),
|
||||||
profile,
|
profile,
|
||||||
auth_uri,
|
scope,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Init main widget
|
// Init main widget
|
||||||
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
app::browser::{action::Action as BrowserAction, window::action::Action as WindowAction},
|
app::browser::{action::Action as BrowserAction, window::action::Action as WindowAction},
|
||||||
Profile,
|
Profile,
|
||||||
};
|
};
|
||||||
use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation};
|
use gtk::{prelude::BoxExt, Box, Orientation};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub struct Form {
|
pub struct Form {
|
||||||
|
|
@ -29,7 +29,7 @@ pub struct Form {
|
||||||
pub name: Rc<Name>,
|
pub name: Rc<Name>,
|
||||||
pub save: Rc<Save>,
|
pub save: Rc<Save>,
|
||||||
pub g_box: Box,
|
pub g_box: Box,
|
||||||
auth_uri: Uri,
|
scope: String,
|
||||||
profile: Rc<Profile>,
|
profile: Rc<Profile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,26 +37,26 @@ impl Form {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(
|
pub fn build(
|
||||||
(browser_action, _window_action, widget_action): (
|
(browser_action, _window_action, widget_action): (
|
||||||
&Rc<BrowserAction>,
|
&Rc<BrowserAction>,
|
||||||
&Rc<WindowAction>,
|
&Rc<WindowAction>,
|
||||||
&Rc<WidgetAction>,
|
&Rc<WidgetAction>,
|
||||||
),
|
),
|
||||||
profile: &Rc<Profile>,
|
profile: &Rc<Profile>,
|
||||||
auth_uri: &Uri,
|
scope: &str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
let list = Rc::new(List::new(widget_action, profile, auth_uri));
|
let list = Rc::new(List::build(widget_action, profile, scope));
|
||||||
let file = Rc::new(File::new(widget_action));
|
let file = Rc::new(File::build(widget_action));
|
||||||
let name = Rc::new(Name::new(widget_action));
|
let name = Rc::new(Name::build(widget_action));
|
||||||
let save = Rc::new(Save::new(profile, &list));
|
let save = Rc::new(Save::build(profile, &list));
|
||||||
let drop = Rc::new(Drop::new(profile, &list));
|
let drop = Rc::new(Drop::build(profile, &list));
|
||||||
let exit = Rc::new(Exit::new(
|
let exit = Rc::new(Exit::build(
|
||||||
(browser_action, widget_action),
|
(browser_action, widget_action),
|
||||||
profile,
|
profile,
|
||||||
&list,
|
&list,
|
||||||
auth_uri,
|
scope,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Init main container
|
// Init main container
|
||||||
|
|
@ -79,7 +79,7 @@ impl Form {
|
||||||
name,
|
name,
|
||||||
save,
|
save,
|
||||||
g_box,
|
g_box,
|
||||||
auth_uri: auth_uri.clone(),
|
scope: scope.to_string(),
|
||||||
profile: profile.clone(),
|
profile: profile.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ impl Form {
|
||||||
.identity
|
.identity
|
||||||
.auth
|
.auth
|
||||||
.memory
|
.memory
|
||||||
.match_scope(&self.auth_uri.to_string())
|
.match_scope(&self.scope)
|
||||||
.is_some_and(|auth| auth.profile_identity_id == profile_identity_id),
|
.is_some_and(|auth| auth.profile_identity_id == profile_identity_id),
|
||||||
);
|
);
|
||||||
self.save.update(true);
|
self.save.update(true);
|
||||||
|
|
@ -29,7 +29,7 @@ impl Drop {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// 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
|
// Init main widget
|
||||||
let button = Button::builder()
|
let button = Button::builder()
|
||||||
.label(LABEL)
|
.label(LABEL)
|
||||||
|
|
@ -8,7 +8,6 @@ use adw::{
|
||||||
AlertDialog, ResponseAppearance,
|
AlertDialog, ResponseAppearance,
|
||||||
};
|
};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
glib::Uri,
|
|
||||||
prelude::{ButtonExt, WidgetExt},
|
prelude::{ButtonExt, WidgetExt},
|
||||||
Button,
|
Button,
|
||||||
};
|
};
|
||||||
|
|
@ -33,11 +32,11 @@ impl Exit {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(
|
pub fn build(
|
||||||
(browser_action, widget_action): (&Rc<BrowserAction>, &Rc<WidgetAction>),
|
(browser_action, widget_action): (&Rc<BrowserAction>, &Rc<WidgetAction>),
|
||||||
profile: &Rc<Profile>,
|
profile: &Rc<Profile>,
|
||||||
list: &Rc<List>,
|
list: &Rc<List>,
|
||||||
auth_uri: &Uri,
|
scope: &str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Init main widget
|
// Init main widget
|
||||||
let button = Button::builder()
|
let button = Button::builder()
|
||||||
|
|
@ -49,7 +48,7 @@ impl Exit {
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
button.connect_clicked({
|
button.connect_clicked({
|
||||||
let auth_uri = auth_uri.clone();
|
let scope = scope.to_string();
|
||||||
let browser_action = browser_action.clone();
|
let browser_action = browser_action.clone();
|
||||||
let button = button.clone();
|
let button = button.clone();
|
||||||
let list = list.clone();
|
let list = list.clone();
|
||||||
|
|
@ -84,7 +83,7 @@ impl Exit {
|
||||||
|
|
||||||
// Connect confirmation event
|
// Connect confirmation event
|
||||||
alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), {
|
alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), {
|
||||||
let auth_uri = auth_uri.clone();
|
let scope = scope.clone();
|
||||||
let button = button.clone();
|
let button = button.clone();
|
||||||
let list = list.clone();
|
let list = list.clone();
|
||||||
let profile = profile.clone();
|
let profile = profile.clone();
|
||||||
|
|
@ -92,19 +91,19 @@ impl Exit {
|
||||||
let widget_action = widget_action.clone();
|
let widget_action = widget_action.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
match profile.identity.auth.remove_ref(profile_identity_id) {
|
match profile.identity.auth.remove_ref(profile_identity_id) {
|
||||||
Ok(_) => match list
|
Ok(_) => {
|
||||||
.selected()
|
match list.selected().update(&profile, &scope.to_string()) {
|
||||||
.update(&profile, &auth_uri.to_string())
|
Ok(_) => {
|
||||||
{
|
button.set_css_classes(&["success"]);
|
||||||
Ok(_) => {
|
button
|
||||||
button.set_css_classes(&["success"]);
|
.set_label("Identity successfully disconnected")
|
||||||
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) => {
|
Err(e) => {
|
||||||
button.set_css_classes(&["error"]);
|
button.set_css_classes(&["error"]);
|
||||||
button.set_label(&e.to_string())
|
button.set_label(&e.to_string())
|
||||||
|
|
@ -21,7 +21,7 @@ impl File {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
|
pub fn build(widget_action: &Rc<WidgetAction>) -> Self {
|
||||||
// Init PEM
|
// Init PEM
|
||||||
let pem = Rc::new(RefCell::new(None));
|
let pem = Rc::new(RefCell::new(None));
|
||||||
|
|
||||||
|
|
@ -11,7 +11,6 @@ use gtk::{
|
||||||
prelude::{Cast, CastNone},
|
prelude::{Cast, CastNone},
|
||||||
ListStore,
|
ListStore,
|
||||||
},
|
},
|
||||||
glib::Uri,
|
|
||||||
prelude::{BoxExt, ListItemExt, ObjectExt, WidgetExt},
|
prelude::{BoxExt, ListItemExt, ObjectExt, WidgetExt},
|
||||||
Align, Box, DropDown, Image, Label, ListItem, Orientation, SignalListItemFactory,
|
Align, Box, DropDown, Image, Label, ListItem, Orientation, SignalListItemFactory,
|
||||||
};
|
};
|
||||||
|
|
@ -25,7 +24,7 @@ impl List {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// 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
|
// Init dropdown items
|
||||||
let guest_session = Item::new_guest_session();
|
let guest_session = Item::new_guest_session();
|
||||||
let generate_pem = Item::new_generate_pem();
|
let generate_pem = Item::new_generate_pem();
|
||||||
|
|
@ -42,8 +41,7 @@ impl List {
|
||||||
Ok(identities) => {
|
Ok(identities) => {
|
||||||
let mut is_guest_session = true;
|
let mut is_guest_session = true;
|
||||||
for identity in identities {
|
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) => {
|
Ok(item) => {
|
||||||
if item.is_active() {
|
if item.is_active() {
|
||||||
is_guest_session = false;
|
is_guest_session = false;
|
||||||
|
|
@ -19,7 +19,7 @@ impl Name {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
|
pub fn build(widget_action: &Rc<WidgetAction>) -> Self {
|
||||||
// Init main gobject
|
// Init main gobject
|
||||||
let entry = Entry::builder()
|
let entry = Entry::builder()
|
||||||
.margin_top(MARGIN)
|
.margin_top(MARGIN)
|
||||||
|
|
@ -23,7 +23,7 @@ impl Save {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// 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
|
// Init main widget
|
||||||
let button = Button::builder()
|
let button = Button::builder()
|
||||||
.label(LABEL)
|
.label(LABEL)
|
||||||
|
|
@ -76,14 +76,8 @@ impl Navigation {
|
||||||
.update(self.profile.bookmark.get(&request).is_ok());
|
.update(self.profile.bookmark.get(&request).is_ok());
|
||||||
self.history.update();
|
self.history.update();
|
||||||
self.reload.update(!request.is_empty());
|
self.reload.update(!request.is_empty());
|
||||||
self.request.update(
|
self.request
|
||||||
self.profile
|
.update(self.profile.identity.match_scope(&request).is_some());
|
||||||
.identity
|
|
||||||
.auth
|
|
||||||
.memory
|
|
||||||
.match_scope(&request)
|
|
||||||
.is_some(),
|
|
||||||
);
|
|
||||||
self.home.update();
|
self.home.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,10 @@ impl Memory {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
|
||||||
// Get all records starts with `scope`
|
// Get all records starts with `scope`
|
||||||
|
let query = filter_scope(request);
|
||||||
|
|
||||||
for (scope, &profile_identity_id) in self.index.borrow().iter() {
|
for (scope, &profile_identity_id) in self.index.borrow().iter() {
|
||||||
if request.starts_with(scope) {
|
if query.starts_with(scope) {
|
||||||
result.push(Auth {
|
result.push(Auth {
|
||||||
profile_identity_id,
|
profile_identity_id,
|
||||||
scope: scope.clone(),
|
scope: scope.clone(),
|
||||||
|
|
@ -81,3 +83,24 @@ impl Memory {
|
||||||
result.first().cloned()
|
result.first().cloned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get valid identity scope for given URL
|
||||||
|
/// * helper function for different protocol drivers implementation
|
||||||
|
fn filter_scope(url: &str) -> String {
|
||||||
|
use gtk::glib::{Regex, RegexCompileFlags, RegexMatchFlags};
|
||||||
|
|
||||||
|
match Regex::split_simple(
|
||||||
|
r"^\w+://(.*)",
|
||||||
|
url,
|
||||||
|
RegexCompileFlags::DEFAULT,
|
||||||
|
RegexMatchFlags::DEFAULT,
|
||||||
|
)
|
||||||
|
.get(1)
|
||||||
|
{
|
||||||
|
Some(postfix) => postfix.to_string(),
|
||||||
|
None => url.to_string(),
|
||||||
|
}
|
||||||
|
.trim()
|
||||||
|
.trim_end_matches("/")
|
||||||
|
.to_lowercase()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue