Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 55 additions & 12 deletions crates/adapter-ipc-grpc/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::{path::PathBuf, time::Duration};
use app_services::{
SharedControlPlaneApp, commands as app_commands,
queries::{
AntiIdleConfigSnapshot, AntiIdleStatusSnapshot, ConsoleSnapshot, StatusSnapshot,
TransportEventSnapshot, UiDiscoveredPeer, UiPairedPeer, UiPendingRequest, UiSnapshot,
AntiIdleConfigSnapshot, AntiIdleStatusSnapshot, ConsoleSnapshot,
FileTransferConfigSnapshot, StatusSnapshot, TransportEventSnapshot, UiDiscoveredPeer,
UiPairedPeer, UiPendingRequest, UiSnapshot,
},
};
use tokio::{sync::mpsc, time};
Expand All @@ -14,16 +15,17 @@ use tonic::{Request, Response, Status};
use ipc_api::boundless::v1::{
AntiIdleConfigReply, AntiIdleSetRequest, AntiIdleStatusReply, ConsoleSnapshotReply,
DiagnosticsDumpReply, DiagnosticsDumpRequest, DiscoveredPeerInfo, Empty, FeatureListReply,
FeatureSetRequest, HotkeySetRequest, HotkeyTriggerRequest, ImportTrustBundleRequest,
InputCaptureTargetReply, InputCaptureTargetRequest, InputOwnerReply, InputOwnerRequest,
LayoutReply, LayoutSetRequest, NearbyJoinStartRequest, NearbyJoinStatusReply,
NearbyJoinStatusRequest, NearbyPairingCompletionReply, NearbyPairingDecisionRequest,
NearbyPairingRequestInfo, NearbyRequestCodeStartReply, NearbyRequestCodeStartRequest,
NearbySubmitCodeRequest, OperationReply, PairCreateCodeReply, PairCreateCodeRequest,
PairJoinReply, PairJoinRequest, PeerInfo, PeerListReply, RemovePeerRequest, SafeResetRequest,
SendClipboardImageRequest, SendClipboardTextRequest, SendFileRequest, SendInputKeyRequest,
SendInputMoveRequest, StatusReply, StatusRequest, TransportEvent, TransportEventsReply,
TrustBundleReply, UiSnapshotReply,
FeatureSetRequest, FileTransferConfigReply, FileTransferSetRequest, HotkeySetRequest,
HotkeyTriggerRequest, ImportTrustBundleRequest, InputCaptureTargetReply,
InputCaptureTargetRequest, InputOwnerReply, InputOwnerRequest, LayoutReply, LayoutSetRequest,
NearbyJoinStartRequest, NearbyJoinStatusReply, NearbyJoinStatusRequest,
NearbyPairingCompletionReply, NearbyPairingDecisionRequest, NearbyPairingRequestInfo,
NearbyRequestCodeStartReply, NearbyRequestCodeStartRequest, NearbySubmitCodeRequest,
OperationReply, PairCreateCodeReply, PairCreateCodeRequest, PairJoinReply, PairJoinRequest,
PeerInfo, PeerListReply, RemovePeerRequest, SafeResetRequest, SendClipboardImageRequest,
SendClipboardTextRequest, SendFileRequest, SendInputKeyRequest, SendInputMoveRequest,
StatusReply, StatusRequest, TransportEvent, TransportEventsReply, TrustBundleReply,
UiSnapshotReply,
control_plane_service_server::{ControlPlaneService, ControlPlaneServiceServer},
};

Expand Down Expand Up @@ -286,6 +288,37 @@ impl ControlPlaneService for ControlPlaneApi {
}))
}

async fn get_file_transfer_config(
&self,
_request: Request<Empty>,
) -> Result<Response<FileTransferConfigReply>, Status> {
let snapshot =
self.app.file_transfer_config().await.map_err(|error| {
Status::internal(format!("build file-transfer config: {error:#}"))
})?;
Ok(Response::new(map_file_transfer_config(snapshot)))
}

async fn set_file_transfer_config(
&self,
request: Request<FileTransferSetRequest>,
) -> Result<Response<OperationReply>, Status> {
let request = request.into_inner();
let reply = self
.app
.set_file_transfer_config(app_commands::SetFileTransferConfigCommand {
receive_dir: request.receive_dir,
organize_by_peer: request.organize_by_peer,
auto_accept_trusted_peers: request.auto_accept_trusted_peers,
})
.await
.map_err(|error| Status::invalid_argument(error.to_string()))?;
Ok(Response::new(OperationReply {
ok: reply.ok,
message: reply.message,
}))
}

async fn set_hotkey(
&self,
request: Request<HotkeySetRequest>,
Expand Down Expand Up @@ -838,6 +871,7 @@ fn map_ui_snapshot(snapshot: UiSnapshot) -> UiSnapshotReply {
.collect(),
anti_idle_config: Some(map_anti_idle_config(snapshot.anti_idle_config)),
anti_idle_status: Some(map_anti_idle_status(snapshot.anti_idle_status)),
file_transfer_config: Some(map_file_transfer_config(snapshot.file_transfer_config)),
}
}

Expand All @@ -862,6 +896,7 @@ fn map_console_snapshot(snapshot: ConsoleSnapshot) -> ConsoleSnapshotReply {
local_display_name: snapshot.local_display_name,
anti_idle_config: Some(map_anti_idle_config(snapshot.anti_idle_config)),
anti_idle_status: Some(map_anti_idle_status(snapshot.anti_idle_status)),
file_transfer_config: Some(map_file_transfer_config(snapshot.file_transfer_config)),
}
}

Expand Down Expand Up @@ -904,6 +939,14 @@ fn map_anti_idle_status(snapshot: AntiIdleStatusSnapshot) -> AntiIdleStatusReply
}
}

fn map_file_transfer_config(snapshot: FileTransferConfigSnapshot) -> FileTransferConfigReply {
FileTransferConfigReply {
receive_dir: snapshot.receive_dir,
organize_by_peer: snapshot.organize_by_peer,
auto_accept_trusted_peers: snapshot.auto_accept_trusted_peers,
}
}

fn map_peer_info(peer: UiPairedPeer) -> PeerInfo {
PeerInfo {
peer_id: peer.peer_id,
Expand Down
14 changes: 10 additions & 4 deletions crates/app-services/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use crate::{
NearbyRequestCodeCommand, NearbySubmitCodeCommand, OperationReply, PairJoinCommand,
PairJoinReply, PairingCodeReply, PairingCodeRequest, RemovePeerCommand, SafeResetCommand,
SendClipboardImageCommand, SendClipboardTextCommand, SendFileCommand, SendInputKeyCommand,
SendInputMoveCommand, SetAntiIdleConfigCommand,
SendInputMoveCommand, SetAntiIdleConfigCommand, SetFileTransferConfigCommand,
},
queries::{
AntiIdleConfigSnapshot, AntiIdleStatusSnapshot, ConsoleSnapshot, NearbyJoinStatusSnapshot,
NearbyPairingCompletionSnapshot, NearbyRequestCodeStartSnapshot, StatusSnapshot,
TransportEventSnapshot, TrustBundleSnapshot, UiSnapshot,
AntiIdleConfigSnapshot, AntiIdleStatusSnapshot, ConsoleSnapshot,
FileTransferConfigSnapshot, NearbyJoinStatusSnapshot, NearbyPairingCompletionSnapshot,
NearbyRequestCodeStartSnapshot, StatusSnapshot, TransportEventSnapshot,
TrustBundleSnapshot, UiSnapshot,
},
};

Expand All @@ -40,6 +41,11 @@ pub trait ControlPlaneApp: Send + Sync {
&self,
command: SetAntiIdleConfigCommand,
) -> Result<OperationReply>;
async fn file_transfer_config(&self) -> Result<FileTransferConfigSnapshot>;
async fn set_file_transfer_config(
&self,
command: SetFileTransferConfigCommand,
) -> Result<OperationReply>;
async fn set_hotkey(&self, command: HotkeySetCommand) -> Result<OperationReply>;
async fn trigger_hotkey_action(&self, command: HotkeyTriggerCommand) -> Result<OperationReply>;
async fn export_trust_bundle(&self) -> Result<TrustBundleSnapshot>;
Expand Down
7 changes: 7 additions & 0 deletions crates/app-services/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ pub struct SetAntiIdleConfigCommand {
pub keep_display_on: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SetFileTransferConfigCommand {
pub receive_dir: String,
pub organize_by_peer: bool,
pub auto_accept_trusted_peers: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HotkeySetCommand {
pub action: String,
Expand Down
9 changes: 9 additions & 0 deletions crates/app-services/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ pub struct AntiIdleStatusSnapshot {
pub reason: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileTransferConfigSnapshot {
pub receive_dir: String,
pub organize_by_peer: bool,
pub auto_accept_trusted_peers: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StatusSnapshot {
pub daemon_version: String,
Expand Down Expand Up @@ -73,6 +80,7 @@ pub struct UiSnapshot {
pub pending_requests: Vec<UiPendingRequest>,
pub anti_idle_config: AntiIdleConfigSnapshot,
pub anti_idle_status: AntiIdleStatusSnapshot,
pub file_transfer_config: FileTransferConfigSnapshot,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -90,6 +98,7 @@ pub struct ConsoleSnapshot {
pub local_display_name: String,
pub anti_idle_config: AntiIdleConfigSnapshot,
pub anti_idle_status: AntiIdleStatusSnapshot,
pub file_transfer_config: FileTransferConfigSnapshot,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
63 changes: 53 additions & 10 deletions crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,40 @@ pub(super) async fn anti_idle_set(
Ok(())
}

pub(super) async fn file_transfer_config(endpoint: &str) -> Result<()> {
let mut client = connect_control_plane(endpoint).await?;
let config = client
.get_file_transfer_config(Empty {})
.await?
.into_inner();

println!(
"receive_dir={} organize_by_peer={} auto_accept_trusted_peers={}",
config.receive_dir, config.organize_by_peer, config.auto_accept_trusted_peers
);
Ok(())
}

pub(super) async fn file_transfer_set_receive_dir(
endpoint: &str,
path: String,
organize_by_peer: bool,
auto_accept_trusted_peers: bool,
) -> Result<()> {
let mut client = connect_control_plane(endpoint).await?;
let response = client
.set_file_transfer_config(FileTransferSetRequest {
receive_dir: path,
organize_by_peer,
auto_accept_trusted_peers,
})
.await?
.into_inner();

println!("ok={} message={}", response.ok, response.message);
Ok(())
}

pub(super) async fn hotkey_set(endpoint: &str, action: String, combo: String) -> Result<()> {
let mut client = connect_control_plane(endpoint).await?;
let response = client
Expand Down Expand Up @@ -996,21 +1030,30 @@ pub(super) async fn transport_send_image(
Ok(())
}

pub(super) async fn transport_send_file(
pub(super) async fn transport_send_files(
endpoint: &str,
peer_id: String,
path: String,
paths: Vec<String>,
) -> Result<()> {
let mut client = connect_control_plane(endpoint).await?;
let response = client
.send_file(SendFileRequest {
peer_id,
file_path: path,
})
.await?
.into_inner();
let total = paths.len();
for path in paths {
let response = client
.send_file(SendFileRequest {
peer_id: peer_id.clone(),
file_path: path.clone(),
})
.await?
.into_inner();

println!("ok={} message={}", response.ok, response.message);
println!(
"path={} ok={} message={}",
path, response.ok, response.message
);
}
if total > 1 {
println!("queued_files={total}");
}
Ok(())
}

Expand Down
45 changes: 39 additions & 6 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::{
use tokio::time::Instant;

use ipc_api::boundless::v1::{
AntiIdleSetRequest, DiagnosticsDumpRequest, Empty, FeatureSetRequest, HotkeySetRequest,
HotkeyTriggerRequest, ImportTrustBundleRequest, InputCaptureTargetRequest, InputOwnerRequest,
LayoutSetRequest, NearbyJoinStartRequest, NearbyJoinStatusRequest,
AntiIdleSetRequest, DiagnosticsDumpRequest, Empty, FeatureSetRequest, FileTransferSetRequest,
HotkeySetRequest, HotkeyTriggerRequest, ImportTrustBundleRequest, InputCaptureTargetRequest,
InputOwnerRequest, LayoutSetRequest, NearbyJoinStartRequest, NearbyJoinStatusRequest,
NearbyPairingDecisionRequest, NearbyRequestCodeStartRequest, NearbySubmitCodeRequest,
PairCreateCodeRequest, PairJoinRequest, RemovePeerRequest, SafeResetRequest,
SendClipboardImageRequest, SendClipboardTextRequest, SendFileRequest, SendInputKeyRequest,
Expand Down Expand Up @@ -85,6 +85,10 @@ enum Command {
#[command(subcommand)]
command: AntiIdleCommand,
},
FileTransfer {
#[command(subcommand)]
command: FileTransferCommand,
},
Transport {
#[command(subcommand)]
command: TransportCommand,
Expand Down Expand Up @@ -228,6 +232,18 @@ enum AntiIdleCommand {
},
}

#[derive(Debug, Subcommand)]
enum FileTransferCommand {
Config,
SetReceiveDir {
path: String,
#[arg(long)]
organize_by_peer: bool,
#[arg(long, default_value_t = true)]
auto_accept_trusted_peers: bool,
},
}

#[derive(Debug, Subcommand)]
enum TransportCommand {
SendText {
Expand All @@ -240,7 +256,8 @@ enum TransportCommand {
},
SendFile {
peer_id: String,
path: String,
#[arg(required = true)]
paths: Vec<String>,
},
Events {
#[arg(long, default_value_t = 50)]
Expand Down Expand Up @@ -423,15 +440,31 @@ async fn main() -> Result<()> {
.await
}
},
Command::FileTransfer { command } => match command {
FileTransferCommand::Config => file_transfer_config(&cli.endpoint).await,
FileTransferCommand::SetReceiveDir {
path,
organize_by_peer,
auto_accept_trusted_peers,
} => {
file_transfer_set_receive_dir(
&cli.endpoint,
path,
organize_by_peer,
auto_accept_trusted_peers,
)
.await
}
},
Command::Transport { command } => match command {
TransportCommand::SendText { peer_id, text } => {
transport_send_text(&cli.endpoint, peer_id, text).await
}
TransportCommand::SendImage { peer_id, path } => {
transport_send_image(&cli.endpoint, peer_id, path).await
}
TransportCommand::SendFile { peer_id, path } => {
transport_send_file(&cli.endpoint, peer_id, path).await
TransportCommand::SendFile { peer_id, paths } => {
transport_send_files(&cli.endpoint, peer_id, paths).await
}
TransportCommand::Events { limit } => transport_events(&cli.endpoint, limit).await,
},
Expand Down
Loading
Loading