5 Commits

Author SHA1 Message Date
50a929d883 chore(release): v0.0.3 (#21)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.0.3

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: #21
2025-08-03 12:45:21 +02:00
f982f094be feat: don't use front
All checks were successful
continuous-integration/drone/push Build is passing
2025-08-03 12:45:01 +02:00
4408c1839e test commit
Some checks failed
continuous-integration/drone/push Build is failing
2025-08-03 12:39:14 +02:00
bef15cb280 feat: add paste command both local and remote
Some checks failed
continuous-integration/drone/push Build is failing
2025-08-03 12:30:07 +02:00
3e27fb2847 feat: add publish 2025-08-03 12:11:17 +02:00
12 changed files with 227 additions and 14 deletions

View File

@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.0.3] - 2025-08-03
### Added
- don't use front
- add paste command both local and remote
- add publish
### Other
- test commit
## [0.0.2] - 2025-08-02
### Added

2
Cargo.lock generated
View File

@@ -1326,7 +1326,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "voidpin"
version = "0.0.1"
version = "0.0.2"
dependencies = [
"anyhow",
"async-trait",

View File

@@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"
[workspace.package]
version = "0.0.2"
version = "0.0.3"
[workspace.dependencies]
voidpin = { path = "crates/voidpin" }

View File

@@ -1,6 +1,11 @@
[package]
name = "voidpin"
edition = "2024"
readme = "../../README.md"
license = "MIT"
authors = ["kjuulh <contact@kasperhermansen.com>"]
repository = "https://git.kjuulh.io/kjuulh/voidpin.git"
description = "Voidpin allows sending copy/paste commands across the wire. It is specifically intended for use in ssh tunnels for long running sessions, where you want to share a clipboard. The primary use case is when a remote machine is used for development, but clipboard continues to be an ergonomic hurdle."
version.workspace = true

View File

@@ -2,12 +2,20 @@ syntax = "proto3";
package voidpin.v1;
service VoidPin {
rpc Copy(CopyRequest) returns (CopyResponse);
}
message CopyRequest {
bytes content = 1;
}
message CopyResponse {}
message PasteRequest {
}
message PasteResponse {
bytes content = 1;
}
service VoidPin {
rpc Copy(CopyRequest) returns (CopyResponse);
rpc Paste(PasteRequest) returns (PasteResponse);
}

View File

@@ -1,7 +1,7 @@
use std::process::Stdio;
use anyhow::Context;
use tokio::io::AsyncWriteExt;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use crate::state::State;
@@ -30,10 +30,6 @@ impl LocalCopier {
#[cfg(target_os = "windows")]
let mut copy_process = {
todo!("windows not supported yet");
tokio::process::Command::new("wl-copy")
.stdin(Stdio::piped())
.spawn()?
};
if let Some(mut stdin_handle) = copy_process.stdin.take() {
@@ -52,6 +48,40 @@ impl LocalCopier {
Ok(())
}
pub async fn paste(&self) -> anyhow::Result<Vec<u8>> {
// FIXME: hardcode for macos
#[cfg(target_os = "macos")]
let mut paste_process = {
tokio::process::Command::new("pbpaste")
.stdin(Stdio::piped())
.spawn()?
};
#[cfg(target_os = "linux")]
let mut paste_process = {
tokio::process::Command::new("wl-paste")
.stdin(Stdio::piped())
.spawn()?
};
#[cfg(target_os = "windows")]
let mut paste_process = {
todo!("windows not supported yet");
};
let mut buf = Vec::new();
if let Some(mut stdout_handle) = paste_process.stdout.take() {
stdout_handle
.read_to_end(&mut buf)
.await
.context("failed to write input to paste process")?;
}
let status = paste_process.wait().await?;
tracing::info!("paste process ended with status: {:?}", status);
Ok(buf)
}
}
pub trait LocalCopierState {

View File

@@ -10,5 +10,15 @@ pub struct CopyRequest {
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct CopyResponse {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct PasteRequest {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PasteResponse {
#[prost(bytes="vec", tag="1")]
pub content: ::prost::alloc::vec::Vec<u8>,
}
include!("voidpin.v1.tonic.rs");
// @@protoc_insertion_point(module)

View File

@@ -105,6 +105,26 @@ pub mod void_pin_client {
req.extensions_mut().insert(GrpcMethod::new("voidpin.v1.VoidPin", "Copy"));
self.inner.unary(req, path, codec).await
}
///
pub async fn paste(
&mut self,
request: impl tonic::IntoRequest<super::PasteRequest>,
) -> std::result::Result<tonic::Response<super::PasteResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/voidpin.v1.VoidPin/Paste");
let mut req = request.into_request();
req.extensions_mut().insert(GrpcMethod::new("voidpin.v1.VoidPin", "Paste"));
self.inner.unary(req, path, codec).await
}
}
}
/// Generated server implementations.
@@ -119,6 +139,11 @@ pub mod void_pin_server {
&self,
request: tonic::Request<super::CopyRequest>,
) -> std::result::Result<tonic::Response<super::CopyResponse>, tonic::Status>;
///
async fn paste(
&self,
request: tonic::Request<super::PasteRequest>,
) -> std::result::Result<tonic::Response<super::PasteResponse>, tonic::Status>;
}
///
#[derive(Debug)]
@@ -244,6 +269,50 @@ pub mod void_pin_server {
};
Box::pin(fut)
}
"/voidpin.v1.VoidPin/Paste" => {
#[allow(non_camel_case_types)]
struct PasteSvc<T: VoidPin>(pub Arc<T>);
impl<T: VoidPin> tonic::server::UnaryService<super::PasteRequest>
for PasteSvc<T> {
type Response = super::PasteResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::PasteRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as VoidPin>::paste(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = PasteSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
Ok(

View File

@@ -1,4 +1,8 @@
use crate::{copy::LocalCopierState, state::State};
use crate::{
copy::LocalCopierState,
grpc::{PasteRequest, PasteResponse},
state::State,
};
#[derive(Clone)]
pub struct GrpcServer {
@@ -27,4 +31,20 @@ impl crate::grpc::void_pin_server::VoidPin for GrpcServer {
Ok(tonic::Response::new(crate::grpc::CopyResponse {}))
}
async fn paste(
&self,
_request: tonic::Request<PasteRequest>,
) -> std::result::Result<tonic::Response<PasteResponse>, tonic::Status> {
let output = self
.state
.local_copier()
.paste()
.await
.map_err(|e| tonic::Status::internal(e.to_string()))?;
Ok(tonic::Response::new(crate::grpc::PasteResponse {
content: output,
}))
}
}

View File

@@ -7,6 +7,7 @@ use grpc::void_pin_server::VoidPinServer;
use grpc_server::GrpcServer;
use remote_copy::RemoteCopierState;
use state::State;
use tokio::io::AsyncWriteExt;
use tonic::transport;
mod grpc {
@@ -33,6 +34,7 @@ enum Commands {
grpc: SocketAddr,
},
Copy {},
Paste {},
Remote {
#[command(subcommand)]
command: RemoteCommands,
@@ -49,6 +51,14 @@ enum RemoteCommands {
)]
remote_host: String,
},
Paste {
#[arg(
long = "remote-host",
env = "VOIDPIN_REMOTE",
default_value = "http://0.0.0.0:7900"
)]
remote_host: String,
},
}
#[tokio::main]
@@ -103,6 +113,21 @@ async fn main() -> anyhow::Result<()> {
tracing::debug!(content = &input, "found content");
state.local_copier().copy(input.as_bytes()).await?;
}
Commands::Paste {} => {
let mut stdout = tokio::io::stdout();
if let Ok(remote_host) = std::env::var("VOIDPIN_REMOTE") {
let output = state.remote_copier(&remote_host).paste().await?;
stdout.write_all(&output).await?;
stdout.flush().await?;
return Ok(());
}
let output = state.local_copier().paste().await?;
stdout.write_all(&output).await?;
stdout.flush().await?;
}
Commands::Remote { command } => match command {
RemoteCommands::Copy { remote_host } => {
let mut input = String::new();
@@ -121,6 +146,13 @@ async fn main() -> anyhow::Result<()> {
.copy(input.as_bytes())
.await?;
}
RemoteCommands::Paste { remote_host } => {
let output = state.remote_copier(&remote_host).paste().await?;
let mut stdout = tokio::io::stdout();
stdout.write_all(&output).await?;
stdout.flush().await?;
}
},
}

View File

@@ -1,6 +1,9 @@
use tonic::transport::{Channel, ClientTlsConfig};
use crate::{grpc::CopyRequest, state::State};
use crate::{
grpc::{CopyRequest, PasteRequest},
state::State,
};
#[derive(Default)]
pub struct RemoteCopier {
@@ -37,6 +40,29 @@ impl RemoteCopier {
Ok(())
}
pub async fn paste(&self) -> anyhow::Result<Vec<u8>> {
let tls = ClientTlsConfig::new();
let channel = Channel::from_shared(self.host.clone())?
.tls_config(if self.host.starts_with("https") {
tls.with_native_roots()
} else {
tls
})?
.connect()
.await?;
tracing::debug!("establishing connection to remote");
let mut client = crate::grpc::void_pin_client::VoidPinClient::new(channel);
tracing::info!("sending paste request");
let resp = client.paste(PasteRequest {}).await?;
tracing::info!("received paste response");
let output = resp.into_inner().content;
Ok(output)
}
}
pub trait RemoteCopierState {

View File

@@ -5,6 +5,8 @@ base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-cli-plan.git"
vars:
service: "voidpin"
registry: kasperhermansen
rust:
publish: {}
please:
project:
@@ -12,6 +14,6 @@ please:
repository: "voidpin"
branch: "main"
settings:
api_url: "https://git.front.kjuulh.io"
api_url: "https://git.kjuulh.io"
actions:
rust: