diff --git a/src/main.rs b/src/main.rs index d5c807c..19caac3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/relm.rs b/src/relm.rs index 4a230f4..0b0c578 100644 --- a/src/relm.rs +++ b/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) { 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,