mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
implement shared cancellable reference
This commit is contained in:
parent
9658e772da
commit
609cdf8512
@ -28,7 +28,7 @@ use gtk::{
|
|||||||
gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags,
|
gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags,
|
||||||
UriHideFlags,
|
UriHideFlags,
|
||||||
},
|
},
|
||||||
prelude::{EditableExt, SocketClientExt},
|
prelude::{CancellableExt, EditableExt, SocketClientExt},
|
||||||
};
|
};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::{rc::Rc, time::Duration};
|
use std::{rc::Rc, time::Duration};
|
||||||
@ -378,10 +378,19 @@ impl Page {
|
|||||||
|
|
||||||
// Private helpers
|
// Private helpers
|
||||||
|
|
||||||
// @TODO move somewhere outside
|
// @TODO move outside
|
||||||
fn load_gemini(&self, uri: Uri, is_history: bool) {
|
fn load_gemini(&self, uri: Uri, is_history: bool) {
|
||||||
|
// Cancel previous client operations
|
||||||
|
{
|
||||||
|
let cancellable = self.client.cancellable.take();
|
||||||
|
if !cancellable.is_cancelled() {
|
||||||
|
cancellable.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init new Cancellable
|
// Init new Cancellable
|
||||||
let cancellable = Cancellable::new();
|
let cancellable = Cancellable::new();
|
||||||
|
self.client.cancellable.replace(cancellable.clone());
|
||||||
|
|
||||||
// Init shared clones
|
// Init shared clones
|
||||||
let update = self.browser_action.update.clone();
|
let update = self.browser_action.update.clone();
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
/// Single client instance holder for `Page` object.
|
use gtk::gio::Cancellable;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
/// Multi-client holder for single `Page` object
|
||||||
///
|
///
|
||||||
/// unlike new client instance init on every page open,
|
/// Unlike init new client instance on every page load,
|
||||||
/// this solution provide additional client-side features
|
/// this struct creates single holder for different protocol drivers;
|
||||||
/// e.g. session cache management on certificate change in runtime
|
/// it also provides additional client-side features
|
||||||
|
/// e.g. session resumption or multi-thread connection management (depending of client type selected)
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
|
// Shared reference to cancel async operations
|
||||||
|
pub cancellable: RefCell<Cancellable>,
|
||||||
|
// Clients
|
||||||
pub gemini: gemini::Client,
|
pub gemini: gemini::Client,
|
||||||
// other supported clients here..
|
// other clients..
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
@ -14,6 +21,7 @@ impl Client {
|
|||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
cancellable: RefCell::new(Cancellable::new()),
|
||||||
gemini: gemini::Client::new(),
|
gemini: gemini::Client::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user