fix: copy url to clipboard directly

This commit is contained in:
uku 2025-05-19 18:55:21 +02:00
parent a9837b7938
commit c0049cbb8d
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o
2 changed files with 7 additions and 15 deletions

View file

@ -353,9 +353,7 @@ impl AsyncComponent for Tyrolienne {
self.step = Step::Waiting;
self.progress = 0;
self.total = 1;
// TODO copy to clipboard here instead, the toast disappears after a short while
self.toast.emit(ToastInput::Show(url));
self.toast.emit(ToastInput::ShowAndCopy(url));
}
ProgressMessage::Error(e) => {
self.step = Step::Waiting;

View file

@ -1,3 +1,4 @@
use arboard::Clipboard;
use relm4::{
SimpleComponent,
adw::{self, prelude::*},
@ -91,8 +92,7 @@ pub struct Toast {
#[derive(Debug)]
pub enum ToastInput {
Show(String),
Copy,
ShowAndCopy(String),
Dismiss,
}
@ -107,8 +107,6 @@ impl SimpleComponent for Toast {
adw::Toast {
#[watch]
set_title: &model.text,
set_button_label: Some("Copy"),
connect_button_clicked => ToastInput::Copy,
connect_dismissed => ToastInput::Dismiss,
}
}
@ -130,18 +128,14 @@ impl SimpleComponent for Toast {
fn update(&mut self, message: Self::Input, _sender: relm4::ComponentSender<Self>) {
match message {
ToastInput::Show(text) => {
ToastInput::ShowAndCopy(text) => {
self.visible = true;
self.text = text;
}
ToastInput::Copy => {
if let Err(e) =
arboard::Clipboard::new().and_then(|mut c| c.set_text(self.text.clone()))
{
if let Err(e) = Clipboard::new().and_then(|mut c| c.set_text(text)) {
tracing::error!("could not copy url to clipboard: {e}");
self.text = "Could not copy".into();
} else {
self.visible = false;
self.text = "Copied url to clipboard".into();
}
}
ToastInput::Dismiss => self.visible = false,