Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions television/television.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -480,15 +481,20 @@ 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();
ctx.set_contents(
entries
.iter()
.map(|e| e.name.clone())
.collect::<Vec<_>>()
.join(" "),
)
.unwrap();
if let Ok(mut ctx) = ClipboardContext::new() {
ctx.set_contents(
entries
.iter()
.map(|e| e.name.clone())
.collect::<Vec<_>>()
.join(" "),
)
.unwrap_or_else(|_| {
error!("Could not copy to clipboard");
});
} else {
error!("Could not copy to clipboard");
}
}
}
}
Expand Down