use client-side cancellable holder

This commit is contained in:
yggverse 2024-11-30 05:08:54 +02:00
parent 82ea70b538
commit 3052d03655

View File

@ -28,14 +28,13 @@ use gtk::{
gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags, gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags,
UriHideFlags, UriHideFlags,
}, },
prelude::{CancellableExt, EditableExt, SocketClientExt}, prelude::{EditableExt, SocketClientExt},
}; };
use sqlite::Transaction; use sqlite::Transaction;
use std::{cell::RefCell, rc::Rc, time::Duration}; use std::{rc::Rc, time::Duration};
pub struct Page { pub struct Page {
id: GString, id: GString,
cancellable: RefCell<Cancellable>,
profile: Rc<Profile>, profile: Rc<Profile>,
// Actions // Actions
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
@ -78,7 +77,6 @@ impl Page {
// Done // Done
Self { Self {
cancellable: RefCell::new(Cancellable::new()),
id, id,
profile, profile,
// Actions // Actions
@ -160,15 +158,6 @@ impl Page {
// Reset widgets // Reset widgets
self.input.unset(); self.input.unset();
// Cancel previous async operations
let cancellable = self.cancellable.take();
if !cancellable.is_cancelled() {
cancellable.cancel();
}
// Create new cancellable
self.cancellable.replace(Cancellable::new());
// Create shared variant value // Create shared variant value
let id = self.id.clone(); let id = self.id.clone();
@ -391,8 +380,10 @@ impl Page {
// @TODO move somewhere outside // @TODO move somewhere outside
fn load_gemini(&self, uri: Uri, is_history: bool) { fn load_gemini(&self, uri: Uri, is_history: bool) {
// Init new Cancellable
let cancellable = Cancellable::new();
// Init shared clones // Init shared clones
let cancellable = self.cancellable.borrow().clone();
let update = self.browser_action.update.clone(); let update = self.browser_action.update.clone();
let tab_action = self.tab_action.clone(); let tab_action = self.tab_action.clone();
let navigation = self.navigation.clone(); let navigation = self.navigation.clone();
@ -444,6 +435,9 @@ impl Page {
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected // https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
gemini::client::response::meta::Status::Input | gemini::client::response::meta::Status::Input |
gemini::client::response::meta::Status::SensitiveInput => { gemini::client::response::meta::Status::SensitiveInput => {
// Close connection
response.connection.close();
// Format response // Format response
let status = Status::Input; let status = Status::Input;
let title = match response.meta.data { let title = match response.meta.data {
@ -500,6 +494,9 @@ impl Page {
move |result|{ move |result|{
match result { match result {
Ok(buffer) => { Ok(buffer) => {
// Close connection
response.connection.close();
// Set children component // Set children component
let text_gemini = content.to_text_gemini( let text_gemini = content.to_text_gemini(
&uri, &uri,
@ -580,6 +577,10 @@ impl Page {
&memory_input_stream, &memory_input_stream,
Some(&cancellable), Some(&cancellable),
move |result| { move |result| {
// Close connection
response.connection.close();
// Process buffer data
match result { match result {
Ok(buffer) => { Ok(buffer) => {
// Update page meta // Update page meta