remove deprecated redirect chunk implementation

This commit is contained in:
yggverse 2025-01-17 04:44:08 +02:00
parent dabff4f4cb
commit 99c3c5b0e5
4 changed files with 6 additions and 90 deletions

View File

@ -31,7 +31,9 @@ impl Client {
pub fn init(profile: &Rc<Profile>, callback: impl Fn(Status) + 'static) -> Self {
Self {
cancellable: Cell::new(Cancellable::new()),
driver: Driver::init(profile, move |status| callback(Status::Driver(status))),
driver: Driver::init(profile.clone(), move |status| {
callback(Status::Driver(status))
}),
status: Rc::new(RefCell::new(Status::Cancellable { time: now() })), // e.g. "ready to use"
}
}

View File

@ -2,11 +2,9 @@
//! by extending it features with new protocol, please make sub-module implementation
mod gemini;
mod redirect;
pub mod status;
// Local dependencies
use redirect::Redirect;
pub use status::Status;
// Global dependencies
@ -19,10 +17,8 @@ use gtk::{
use std::rc::Rc;
pub struct Driver {
/// Profile reference required for Gemini protocol auth (match request)
/// Profile reference required for Gemini protocol auth (match scope)
profile: Rc<Profile>,
/// Redirect resolver for different protocols
redirect: Rc<Redirect>,
/// Supported clients
/// * gemini driver should be initiated once (on page object init)
/// to process all it connection features properly
@ -34,7 +30,7 @@ impl Driver {
// Constructors
/// Init new `Self`
pub fn init(profile: &Rc<Profile>, callback: impl Fn(Status) + 'static) -> Self {
pub fn init(profile: Rc<Profile>, callback: impl Fn(Status) + 'static) -> Self {
// Init supported protocol libraries
let gemini = Rc::new(ggemini::Client::new());
@ -58,11 +54,7 @@ impl Driver {
// other client listeners here..
// Done
Self {
profile: profile.clone(),
redirect: Rc::new(Redirect::new()),
gemini,
}
Self { profile, gemini }
}
// Actions

View File

@ -1,67 +0,0 @@
mod item;
use item::Item;
use gtk::glib::Uri;
use std::cell::{Cell, RefCell};
/// Global limit to prevent infinitive redirection issues
/// * defined value is globally applicable to ALL drivers
/// * every driver implement its own value, according to protocol specification
/// * the `Client` will forcefully break redirection loop when iteration reach this value
pub const LIMIT: usize = 10; // @TODO make optional
pub struct Redirect {
chain: RefCell<Vec<Item>>,
}
impl Default for Redirect {
fn default() -> Self {
Self::new()
}
}
impl Redirect {
// Constructors
/// Create new `Self`
pub fn new() -> Self {
Self {
chain: RefCell::new(Vec::new()),
}
}
// Actions
/// Register new redirect in chain
pub fn add(&self, request: Uri, referrer: Option<Uri>, is_foreground: bool) -> &Self {
self.chain.borrow_mut().push(Item {
request,
referrer,
is_foreground,
is_processed: Cell::new(false),
});
self
}
/// Clear redirect chain
pub fn clear(&self) {
self.chain.borrow_mut().clear()
}
// Getters
/// Get total redirects count in chain
pub fn count(&self) -> usize {
self.chain.borrow().len() + 1
}
/// Get last redirection `Item` copy
pub fn last(&self) -> Option<Item> {
if let Some(redirect) = self.chain.borrow().last() {
if !redirect.is_processed.replace(true) {
return Some(redirect.clone());
}
}
None
}
}

View File

@ -1,11 +0,0 @@
use gtk::glib::Uri;
use std::cell::Cell;
/// Single redirect `Item`
#[derive(Clone)]
pub struct Item {
pub is_foreground: bool,
pub is_processed: Cell<bool>,
pub referrer: Option<Uri>,
pub request: Uri,
}