delegate cancellable features to client api

This commit is contained in:
yggverse 2024-12-01 12:35:47 +02:00
parent 609cdf8512
commit c693e5d88e
2 changed files with 19 additions and 15 deletions

View File

@ -23,12 +23,12 @@ use crate::Profile;
use gtk::{
gdk::Texture,
gdk_pixbuf::Pixbuf,
gio::{Cancellable, SocketClientEvent},
gio::SocketClientEvent,
glib::{
gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags,
UriHideFlags,
},
prelude::{CancellableExt, EditableExt, SocketClientExt},
prelude::{EditableExt, SocketClientExt},
};
use sqlite::Transaction;
use std::{rc::Rc, time::Duration};
@ -380,19 +380,8 @@ impl Page {
// @TODO move outside
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
let cancellable = Cancellable::new();
self.client.cancellable.replace(cancellable.clone());
// Init shared clones
let cancellable = self.client.cancellable();
let update = self.browser_action.update.clone();
let tab_action = self.tab_action.clone();
let navigation = self.navigation.clone();

View File

@ -1,4 +1,4 @@
use gtk::gio::Cancellable;
use gtk::{gio::Cancellable, prelude::CancellableExt};
use std::cell::RefCell;
/// Multi-client holder for single `Page` object
@ -25,4 +25,19 @@ impl Client {
gemini: gemini::Client::new(),
}
}
/// Get new [Cancellable](https://docs.gtk.org/gio/class.Cancellable.html) by cancel previous one
pub fn cancellable(&self) -> Cancellable {
// Init new Cancellable
let cancellable = Cancellable::new();
// Cancel previous client operations
let previous = self.cancellable.replace(cancellable.clone());
if !previous.is_cancelled() {
previous.cancel();
}
// Done
cancellable
}
}