Many fixes for the clipboard and others

- Reverse connections must be maintained to ensure messages are
  processed in order. (Whoops!)
- The clipboard context must remain live in order for the data to
  remain available for applications, at least on X11. (And it couldn't
  hurt elsewhere, either, I guess.)
- Print out the server version at startup time, so we can be sure what
  we're talking to.
- Print out the full details of the error when something goes wrong
  with `browse` or `clip`.
This commit is contained in:
John Doty 2024-08-08 10:03:47 -07:00
parent a3fa032500
commit 2a582e25a8
7 changed files with 110 additions and 57 deletions

View file

@ -1,6 +1,7 @@
use super::{client_listen, config::ServerConfig};
use crate::message::PortDesc;
use anyhow::Result;
use copypasta::{ClipboardContext, ClipboardProvider};
use crossterm::{
event::{Event, EventStream, KeyCode, KeyEvent, KeyModifiers},
execute,
@ -33,6 +34,7 @@ pub enum UIEvent {
ServerLine(String),
LogLine(log::Level, String),
Ports(Vec<PortDesc>),
SetClipboard(String),
}
pub enum UIReturn {
@ -166,7 +168,6 @@ impl Listener {
}
}
#[derive(Debug)]
pub struct UI {
events: mpsc::Receiver<UIEvent>,
ports: HashMap<u16, Listener>,
@ -179,6 +180,7 @@ pub struct UI {
show_help: bool,
alternate_screen: bool,
raw_mode: bool,
clipboard: ClipboardContext,
}
impl UI {
@ -195,6 +197,8 @@ impl UI {
config,
alternate_screen: false,
raw_mode: false,
clipboard: ClipboardContext::new()
.expect("Unable to initialize clipboard context"),
}
}
@ -621,6 +625,14 @@ impl UI {
}
self.lines.push_back(format!("[CLIENT] {line}"));
}
Some(UIEvent::SetClipboard(contents)) => {
let length = contents.len();
if let Err(e) = self.clipboard.set_contents(contents) {
error!("Error setting clipboard contents: {e:#}");
} else {
info!("Received clipboard contents ({length} bytes)");
}
}
None => {
self.running = false;
}