Skip to content

Commit 97f8540

Browse files
committed
Fix clipboard copy warning on linux
1 parent 5a2ceab commit 97f8540

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/app.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) struct App<'a> {
2727
// App state
2828
running: bool,
2929
event_sender: Sender<AppEvent>,
30+
clipboard: Result<Clipboard, ()>,
3031
// UI
3132
pub current_pane: Pane,
3233
pub active_out_pane: Pane,
@@ -55,6 +56,7 @@ impl App<'_> {
5556
Self {
5657
running: false,
5758
event_sender: tx,
59+
clipboard: Clipboard::new().map_err(|_| ()),
5860
// UI
5961
current_pane: Pane::Params,
6062
active_out_pane: Pane::Info,
@@ -183,7 +185,7 @@ impl App<'_> {
183185
}
184186

185187
fn copy_preset(&mut self) {
186-
let (kind, msg) = match Clipboard::new().map(|mut ctx| {
188+
let (kind, msg) = match self.clipboard.as_mut().map(|ctx| {
187189
let preset = save_preset(&mut self.params);
188190
ctx.set_text(preset)
189191
}) {
@@ -194,10 +196,12 @@ impl App<'_> {
194196
}
195197

196198
fn copy_command(&mut self) {
197-
let (kind, msg) = match Clipboard::new().map(|mut ctx| {
198-
let args = self.build_ffmpeg_command(false);
199-
ctx.set_text(format!("ffmpeg {}", args.join(" ")))
200-
}) {
199+
let args = self.build_ffmpeg_command(false);
200+
let (kind, msg) = match self
201+
.clipboard
202+
.as_mut()
203+
.map(|ctx| ctx.set_text(format!("ffmpeg {}", args.join(" "))))
204+
{
201205
Ok(_) => (AlertKind::Info, "Command has been copied to clipboard"),
202206
Err(_) => (AlertKind::Error, "Failed to copy the command to clipboard"),
203207
};

0 commit comments

Comments
 (0)