fix(clipboard): gracefully fail if clipboard isn't available (#350)

Fixes #341
This commit is contained in:
Alexandre Pasmantier 2025-02-07 21:28:54 +01:00 committed by GitHub
parent 56be4dca4f
commit 8e38ffc3ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,6 +22,7 @@ use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use tokio::sync::mpsc::{Receiver, Sender, UnboundedSender};
use tracing::error;
#[derive(PartialEq, Copy, Clone, Hash, Eq, Debug, Serialize, Deserialize)]
pub enum Mode {
@ -480,7 +481,7 @@ impl Television {
pub fn handle_copy_entry_to_clipboard(&mut self) {
if self.mode == Mode::Channel {
if let Some(entries) = self.get_selected_entries(None) {
let mut ctx = ClipboardContext::new().unwrap();
if let Ok(mut ctx) = ClipboardContext::new() {
ctx.set_contents(
entries
.iter()
@ -488,7 +489,12 @@ impl Television {
.collect::<Vec<_>>()
.join(" "),
)
.unwrap();
.unwrap_or_else(|_| {
error!("Could not copy to clipboard");
});
} else {
error!("Could not copy to clipboard");
}
}
}
}