From c693e5d88ea460b60dbb27a5683456f029d73ba2 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 1 Dec 2024 12:35:47 +0200 Subject: [PATCH] delegate cancellable features to client api --- src/app/browser/window/tab/item/page.rs | 17 +++-------------- src/app/browser/window/tab/item/page/client.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index b9c95e57..8735aa8b 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -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(); diff --git a/src/app/browser/window/tab/item/page/client.rs b/src/app/browser/window/tab/item/page/client.rs index 6ebdc1e1..79e35e07 100644 --- a/src/app/browser/window/tab/item/page/client.rs +++ b/src/app/browser/window/tab/item/page/client.rs @@ -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 + } }