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 serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
use tokio::sync::mpsc::{Receiver, Sender, UnboundedSender}; use tokio::sync::mpsc::{Receiver, Sender, UnboundedSender};
use tracing::error;
#[derive(PartialEq, Copy, Clone, Hash, Eq, Debug, Serialize, Deserialize)] #[derive(PartialEq, Copy, Clone, Hash, Eq, Debug, Serialize, Deserialize)]
pub enum Mode { pub enum Mode {
@ -480,15 +481,20 @@ impl Television {
pub fn handle_copy_entry_to_clipboard(&mut self) { pub fn handle_copy_entry_to_clipboard(&mut self) {
if self.mode == Mode::Channel { if self.mode == Mode::Channel {
if let Some(entries) = self.get_selected_entries(None) { 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( ctx.set_contents(
entries entries
.iter() .iter()
.map(|e| e.name.clone()) .map(|e| e.name.clone())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(" "), .join(" "),
) )
.unwrap(); .unwrap_or_else(|_| {
error!("Could not copy to clipboard");
});
} else {
error!("Could not copy to clipboard");
}
} }
} }
} }