Skip to content

Commit

Permalink
Sometimes you can't get a clipboard, don't fail
Browse files Browse the repository at this point in the history
This should fix CI as well, but there are possibly folks out there
that don't have a functioning clipboard and still want to run.
  • Loading branch information
DeCarabas committed Aug 10, 2024
1 parent bb8c87b commit 69b9bc9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/client/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crossterm::{
EnterAlternateScreen, LeaveAlternateScreen,
},
};
use log::{error, info, Level, Metadata, Record};
use log::{error, info, warn, Level, Metadata, Record};
use std::collections::vec_deque::VecDeque;
use std::collections::{HashMap, HashSet};
use std::io::stdout;
Expand Down Expand Up @@ -218,7 +218,7 @@ pub struct UI {
show_help: bool,
alternate_screen: bool,
raw_mode: bool,
clipboard: ClipboardContext,
clipboard: Option<ClipboardContext>,
}

impl UI {
Expand All @@ -228,6 +228,8 @@ impl UI {
ports.insert(*port, Listener::from_config(config.clone()));
}

let clipboard = ClipboardContext::new().ok();

UI {
events,
ports,
Expand All @@ -240,8 +242,7 @@ impl UI {
config,
alternate_screen: false,
raw_mode: false,
clipboard: ClipboardContext::new()
.expect("Unable to initialize clipboard context"),
clipboard,
}
}

Expand Down Expand Up @@ -672,10 +673,14 @@ impl UI {
}
Some(UIEvent::SetClipboard(contents)) => {
let length = contents.len();
if let Err(e) = self.clipboard.set_contents(contents) {
error!("Error setting clipboard contents: {e:#}");
if let Some(clipboard) = self.clipboard.as_mut() {
if let Err(e) = clipboard.set_contents(contents) {
error!("Error setting clipboard contents: {e:#}");
} else {
info!("Received clipboard contents ({length} bytes)");
}
} else {
info!("Received clipboard contents ({length} bytes)");
warn!("No clipboard available, contents discarded");
}
}
None => {
Expand Down

0 comments on commit 69b9bc9

Please sign in to comment.