Skip to content

Commit

Permalink
Clipboard Content: remove none variant
Browse files Browse the repository at this point in the history
Doesn't really make sense to have this
  • Loading branch information
xarantolus committed Jan 13, 2024
1 parent 4ba868d commit 03b1f0b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
2 changes: 0 additions & 2 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ pub enum ActionMessage {
pub enum ClipboardContent {
Text(String),
Image(Vec<u8>),
None,
}

impl Debug for ClipboardContent {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
ClipboardContent::Text(text) => write!(f, "Text({:?})", text),
ClipboardContent::Image(content) => write!(f, "Image(len={})", content.len()),
ClipboardContent::None => write!(f, "None"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/src/clipboard/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ fn get_clipboard_content(output_format: &ImageOutputFormat) -> Result<ClipboardC
return Ok(ClipboardContent::Image(buf));
}
}
Ok(ClipboardContent::None)

Err(anyhow::anyhow!("No clipboard content"))
}

impl<T: From<ClipboardContent>> ClipboardHandler for &mut Watcher<T> {
Expand All @@ -95,7 +96,6 @@ impl<T: From<ClipboardContent>> ClipboardHandler for &mut Watcher<T> {

pub fn set_clipboard(content: &ClipboardContent) -> anyhow::Result<()> {
match &content {
ClipboardContent::None => Ok(()),
ClipboardContent::Text(text) => {
let mut clipboard = Clipboard::new()?;

Expand Down
2 changes: 1 addition & 1 deletion server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Manager {
config: config,
connections: Arc::new(RwLock::new(HashMap::new())),
counter: AtomicUsize::new(0),
last_clipboard_content: RwLock::new(ClipboardContent::None),
last_clipboard_content: RwLock::new(ClipboardContent::Text("".to_string())),
last_message: RwLock::new(None),
}
}
Expand Down
3 changes: 1 addition & 2 deletions server/src/web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn handle_read_clipboard_route(manager: Arc<RwLock<Manager>>) -> impl Reply {

match last_clipboard_content.clone() {
ClipboardContent::Text(text) => warp::reply::with_header(
text,
warp::reply::html(text),
"Content-Type",
"text/plain"
.parse::<warp::http::header::HeaderValue>()
Expand All @@ -101,7 +101,6 @@ fn handle_read_clipboard_route(manager: Arc<RwLock<Manager>>) -> impl Reply {
)
.into_response()
}
_ => warp::reply::html("No clipboard content".to_string()).into_response(),
}
}

Expand Down
12 changes: 3 additions & 9 deletions server/src/websocket.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::connection::Manager;
use anyhow::Result;
use common::{ActionMessage, ClipboardContent};
use common::ActionMessage;
use futures_util::{SinkExt, StreamExt};
use log::{error, info};
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -66,15 +66,9 @@ pub(crate) async fn handle_connection(
// Send the last clipboard content to the user
let manager = manager_clone.write().unwrap();
let last_clipboard_content = manager.last_clipboard_content.read().unwrap();
let content = last_clipboard_content.clone();

match content {
ClipboardContent::None => (),
_ => {
let message = ActionMessage::Clipboard(last_clipboard_content.clone());
let _ = ws_writer_clone.send(message);
}
}
let message = ActionMessage::Clipboard(last_clipboard_content.clone());
let _ = ws_writer_clone.send(message);
});

log::info!(
Expand Down

0 comments on commit 03b1f0b

Please sign in to comment.