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:
parent
a3fa032500
commit
2a582e25a8
7 changed files with 110 additions and 57 deletions
|
|
@ -1,7 +1,6 @@
|
|||
use crate::message::{Message, MessageReader, MessageWriter};
|
||||
use anyhow::{bail, Result};
|
||||
use bytes::BytesMut;
|
||||
use copypasta::{ClipboardContext, ClipboardProvider};
|
||||
use log::LevelFilter;
|
||||
use log::{debug, error, info, warn};
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -213,16 +212,11 @@ async fn client_handle_messages<T: AsyncRead + Unpin>(
|
|||
}
|
||||
|
||||
ClipStart(id) => {
|
||||
info!("Starting clip op {id}");
|
||||
clipboard_messages.insert(id, Vec::new());
|
||||
}
|
||||
|
||||
ClipData(id, mut data) => match clipboard_messages.get_mut(&id) {
|
||||
Some(bytes) => {
|
||||
info!(
|
||||
"Received data for clip op {id} ({len} bytes)",
|
||||
len = data.len()
|
||||
);
|
||||
if bytes.len() < MAX_CLIPBOARD_SIZE {
|
||||
bytes.append(&mut data);
|
||||
}
|
||||
|
|
@ -243,9 +237,10 @@ async fn client_handle_messages<T: AsyncRead + Unpin>(
|
|||
continue;
|
||||
};
|
||||
|
||||
let mut ctx = ClipboardContext::new().unwrap();
|
||||
if let Err(e) = ctx.set_contents(data) {
|
||||
error!("Unable to set clipboard data for op {id}: {e:?}");
|
||||
if let Err(e) =
|
||||
events.send(ui::UIEvent::SetClipboard(data)).await
|
||||
{
|
||||
error!("Error sending clipboard request: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue