keep original header to have re-send ability

This commit is contained in:
yggverse 2025-02-07 20:38:46 +02:00
parent c90ec34ccc
commit faac9c60fe
3 changed files with 9 additions and 9 deletions

View file

@ -18,10 +18,10 @@ pub trait Titan {
impl Titan for gtk::Box {
fn titan(callback: impl Fn(Header, Bytes, Box<dyn Fn()>) + 'static) -> Self {
use gtk::{glib::uuid_string_random, prelude::ButtonExt, Label, TextView};
use std::{cell::Cell, rc::Rc};
use std::{cell::RefCell, rc::Rc};
// Init components
let header = Rc::new(Cell::new(Header {
let header = Rc::new(RefCell::new(Header {
mime: None,
token: None,
}));
@ -79,7 +79,7 @@ impl Titan for gtk::Box {
use control::Upload;
this.set_uploading();
callback(
header.take(), // @TODO copy?
header.borrow().clone(), // keep original header to have re-send ability
match notebook.current_page().unwrap() {
0 => text.to_bytes(),
1 => file.to_bytes().unwrap(),
@ -87,7 +87,7 @@ impl Titan for gtk::Box {
},
Box::new({
let this = this.clone();
move || this.set_resend() // on failure
move || this.set_resend() // re-activate button on failure
}),
)
});

View file

@ -9,7 +9,7 @@ use gtk::{
Align, Box, Button, Label, Orientation,
};
use options::Options;
use std::{cell::Cell, rc::Rc};
use std::{cell::RefCell, rc::Rc};
pub use upload::Upload;
pub struct Control {
@ -22,7 +22,7 @@ impl Control {
// Constructors
/// Build new `Self`
pub fn build(header: &Rc<Cell<Header>>) -> Self {
pub fn build(header: &Rc<RefCell<Header>>) -> Self {
// Init components
let counter = Label::counter();
let options = Button::options(header);

View file

@ -3,14 +3,14 @@ use gtk::{
prelude::{ButtonExt, WidgetExt},
Button,
};
use std::{cell::Cell, rc::Rc};
use std::{cell::RefCell, rc::Rc};
pub trait Options {
fn options(header: &Rc<Cell<Header>>) -> Self;
fn options(header: &Rc<RefCell<Header>>) -> Self;
}
impl Options for Button {
fn options(header: &Rc<Cell<Header>>) -> Self {
fn options(header: &Rc<RefCell<Header>>) -> Self {
let button = Button::builder()
.icon_name("emblem-system-symbolic")
.tooltip_text("Options")