fix: copy url to clipboard directly
This commit is contained in:
parent
a9837b7938
commit
c0049cbb8d
2 changed files with 7 additions and 15 deletions
|
@ -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;
|
||||
|
|
18
src/relm.rs
18
src/relm.rs
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue