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

@ -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
}
}