Skip to content

Commit 69e299a

Browse files
committed
Refactor drop-core CLI and exchanges to unify dependencies and enhance QR code functionality
- Updated `Cargo.toml` to streamline dependency paths and remove duplicates. - Refactored imports in CLI and exchanges to use `arkdrop` namespaces consistently. - Improved QR code display and handling in file transfer processes for better user experience. - Cleaned up unused code and improved error handling in file receiving and sending logic. These changes enhance the maintainability of the codebase and improve the overall user experience during file transfers. Signed-off-by: Pushkar Mishra <[email protected]>
1 parent 2b34071 commit 69e299a

File tree

12 files changed

+79
-100
lines changed

12 files changed

+79
-100
lines changed

drop-core/cli/Cargo.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,13 @@ name = "arkdrop-cli"
2020
path = "src/main.rs"
2121

2222
[dependencies]
23-
arkdrop-common = { path = "../common" }
23+
arkdrop-common = { path = "../common" }
2424
arkdropx-sender = { path = "../exchanges/sender" }
25-
arkdropx-receiver = { path = "../exchanges/receiver" }
25+
arkdropx-receiver = { path = "../exchanges/receiver" }
2626

2727
toml = "0.8"
2828
anyhow = "1.0"
2929
base64 = "0.21"
30-
serde = { version = "1.0", features = ["derive"] }
31-
toml = "0.8"
32-
qrcode = "0.14"
33-
34-
dropx-receiver = { path = "../exchanges/receiver" }
35-
dropx-sender = { path = "../exchanges/sender" }
3630
clap = "4.5.47"
3731
uuid = "1.18.1"
3832
tokio = "1.47.1"

drop-core/cli/src/lib.rs

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ use arkdropx_receiver::{
8080
},
8181
receive_files,
8282
};
83-
use dropx_sender::{
84-
SendFilesConnectingEvent, SendFilesRequest, SendFilesSendingEvent,
85-
SendFilesSubscriber, SenderConfig, SenderFile, SenderFileData,
86-
SenderProfile, send_files,
83+
use arkdropx_sender::{
84+
SendFilesBubble, SendFilesConnectingEvent, SendFilesRequest,
85+
SendFilesSendingEvent, SendFilesSubscriber, SenderConfig, SenderFile,
86+
SenderFileData, SenderProfile, send_files,
8787
send_files_to::{
8888
SendFilesToBubble, SendFilesToConnectingEvent, SendFilesToRequest,
8989
SendFilesToSendingEvent, SendFilesToSubscriber, send_files_to,
@@ -153,12 +153,9 @@ impl FileSender {
153153
let subscriber = FileSendSubscriber::new(verbose);
154154
bubble.subscribe(Arc::new(subscriber));
155155

156-
// Display QR code and session info
157-
display_session_info(
158-
&bubble.get_ticket(),
159-
bubble.get_confirmation(),
160-
"Sender",
161-
);
156+
println!("📦 Ready to send files!");
157+
print_qr_to_console(&bubble)?;
158+
println!("⏳ Waiting for receiver... (Press Ctrl+C to cancel)");
162159

163160
tokio::select! {
164161
_ = tokio::signal::ctrl_c() => {
@@ -221,6 +218,25 @@ fn print_qr_to_console(bubble: &SendFilesBubble) -> Result<()> {
221218
Ok(())
222219
}
223220

221+
fn print_ready_to_receive_qr(ticket: &str, confirmation: u8) -> Result<()> {
222+
let data =
223+
format!("drop://send?ticket={ticket}&confirmation={confirmation}");
224+
225+
let code = QrCode::new(&data)?;
226+
let image = code
227+
.render::<char>()
228+
.quiet_zone(false)
229+
.module_dimensions(2, 1)
230+
.build();
231+
232+
println!("\nQR Code for Transfer:");
233+
println!("{}", image);
234+
println!("🎫 Ticket: {ticket}");
235+
println!("🔒 Confirmation: {confirmation}\n");
236+
237+
Ok(())
238+
}
239+
224240
async fn wait_for_send_completion(bubble: &arkdropx_sender::SendFilesBubble) {
225241
loop {
226242
if bubble.is_finished() {
@@ -967,34 +983,16 @@ pub async fn run_receive_files(
967983
format!("Invalid confirmation code: {confirmation}")
968984
})?;
969985

970-
// Determine the output directory
971-
let final_output_dir = match output_dir {
972-
Some(dir) => {
973-
let path = PathBuf::from(&dir);
974-
975-
// Save this directory as default if requested
976-
if save_dir {
977-
let mut config = CliConfig::load()?;
978-
config
979-
.set_default_receive_dir(dir.clone())
980-
.with_context(
981-
|| "Failed to save default receive directory",
982-
)?;
983-
println!("Saved '{}' as default receive directory", dir);
984-
}
985-
986-
path
987-
}
988-
None => {
989-
// Try to use saved default directory; otherwise use sensible
990-
// fallback
991-
let config = CliConfig::load()?;
992-
match config.get_default_receive_dir() {
993-
Some(default_dir) => PathBuf::from(default_dir),
994-
None => default_receive_dir_fallback(),
995-
}
996-
}
997-
};
986+
if save_out {
987+
let mut config = AppConfig::load()?;
988+
config.set_out_dir(out_dir.clone()).with_context(
989+
|| "Failed to save default output receive directory",
990+
)?;
991+
println!(
992+
"💾 Saved '{}' as default output receive directory",
993+
out_dir.display()
994+
);
995+
}
998996

999997
let receiver = FileReceiver::new(profile);
1000998
receiver
@@ -1618,23 +1616,12 @@ pub async fn run_ready_to_receive(
16181616
Some(dir) => {
16191617
let path = PathBuf::from(&dir);
16201618
if save_dir {
1621-
let mut config = CliConfig::load()?;
1622-
config
1623-
.set_default_receive_dir(dir.clone())
1624-
.with_context(
1625-
|| "Failed to save default receive directory",
1626-
)?;
1627-
println!("Saved '{}' as default receive directory", dir);
1619+
set_default_out_dir(path.clone())?;
1620+
println!("💾 Saved '{}' as default receive directory", dir);
16281621
}
16291622
path
16301623
}
1631-
None => {
1632-
let config = CliConfig::load()?;
1633-
match config.get_default_receive_dir() {
1634-
Some(default_dir) => PathBuf::from(default_dir),
1635-
None => default_receive_dir_fallback(),
1636-
}
1637-
}
1624+
None => get_default_out_dir(),
16381625
};
16391626

16401627
// Create output directory if it doesn't exist
@@ -1672,26 +1659,27 @@ pub async fn run_ready_to_receive(
16721659
let confirmation = bubble.get_confirmation();
16731660

16741661
// Display QR code and session info
1675-
display_session_info(&ticket, confirmation, "Receiver");
1676-
1677-
println!("Files will be saved to: {}", receiving_path.display());
1662+
println!("📦 Ready to receive files!");
1663+
print_ready_to_receive_qr(&ticket, confirmation)?;
1664+
println!("📁 Files will be saved to: {}", receiving_path.display());
1665+
println!("⏳ Waiting for sender... (Press Ctrl+C to cancel)");
16781666

16791667
let subscriber =
16801668
ReadyToReceiveSubscriberImpl::new(receiving_path.clone(), verbose);
16811669
bubble.subscribe(Arc::new(subscriber));
16821670

16831671
tokio::select! {
16841672
_ = tokio::signal::ctrl_c() => {
1685-
println!("Cancelling file transfer...");
1673+
println!("🚫 Cancelling file transfer...");
16861674
let _ = bubble.cancel().await;
1687-
println!("Transfer cancelled");
1688-
std::process::exit(0);
1675+
println!("✅ Transfer cancelled");
16891676
}
16901677
_ = wait_for_ready_to_receive_completion(&bubble) => {
1691-
println!("All files received successfully!");
1692-
std::process::exit(0);
1678+
println!("✅ All files received successfully!");
16931679
}
16941680
}
1681+
1682+
Ok(())
16951683
}
16961684

16971685
/// Run send-files-to operation (sender connects to waiting receiver).

drop-core/common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,6 @@ impl TransferFile {
525525
pub fn get_pct(&self) -> f64 {
526526
let raw_pct = self.len / self.expected_len;
527527
let pct: u32 = raw_pct.try_into().unwrap_or(0);
528-
pct.try_into().unwrap_or(0.0)
528+
pct.into()
529529
}
530530
}

drop-core/exchanges/receiver/src/ready_to_receive/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//! chunk arrivals.
88
99
use anyhow::Result;
10-
use drop_entities::Profile;
11-
use dropx_common::{
10+
use arkdrop_entities::Profile;
11+
use arkdropx_common::{
1212
handshake::{
1313
HandshakeConfig, HandshakeProfile, NegotiatedConfig, ReceiverHandshake,
1414
SenderHandshake,

drop-core/exchanges/receiver/src/ready_to_receive/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
mod handler;
99

1010
use anyhow::Result;
11+
use arkdrop_entities::Profile;
1112
use chrono::{DateTime, Utc};
12-
use drop_entities::Profile;
1313
use handler::ReadyToReceiveHandler;
1414
use iroh::{Endpoint, Watcher, protocol::Router};
1515
use iroh_base::ticket::NodeTicket;
@@ -236,7 +236,7 @@ impl ReadyToReceiveBubble {
236236
/// Example:
237237
/// ```rust no_run
238238
/// use std::sync::Arc;
239-
/// use dropx_receiver::{
239+
/// use arkdropx_receiver::{
240240
/// ready_to_receive::*, ReceiverProfile,
241241
/// };
242242
///

drop-core/exchanges/receiver/src/receive_files.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,14 @@ impl Carrier {
430430
}
431431
}
432432

433-
while let Some(result) = join_set.join_next().await {
434-
if let Err(err) = result? {
435-
// Downcast anyhow::Error to ConnectionError
436-
if let Some(connection_err) =
437-
err.downcast_ref::<ConnectionError>()
438-
&& connection_err == &expected_close
439-
{
440-
continue;
441-
}
442-
return Err(err);
433+
while let Some(result) = join_set.join_next().await
434+
&& let Err(err) = result?
435+
{
436+
// Downcast anyhow::Error to ConnectionError
437+
if let Some(connection_err) = err.downcast_ref::<ConnectionError>()
438+
&& connection_err == &expected_close
439+
{
440+
continue;
443441
}
444442
return Err(err);
445443
}

drop-core/exchanges/sender/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct SenderFile {
6868
/// - `read_chunk(size)` returns the next chunk up to `size` bytes; an empty
6969
/// vector signals EOF.
7070
/// - `read` is a single-byte variant primarily to satisfy the
71-
/// `drop_entities::Data` trait; it can be implemented in terms of your
71+
/// `arkdrop_entities::Data` trait; it can be implemented in terms of your
7272
/// internal reader if needed.
7373
pub trait SenderFileData: Send + Sync {
7474
/// Total length in bytes.
@@ -86,10 +86,10 @@ pub trait SenderFileData: Send + Sync {
8686
fn read_chunk(&self, size: u64) -> Vec<u8>;
8787
}
8888

89-
/// Internal adapter to bridge `SenderFileData` with `drop_entities::Data`.
89+
/// Internal adapter to bridge `SenderFileData` with `arkdrop_entities::Data`.
9090
///
9191
/// This type is not exposed publicly; it allows the rest of the pipeline to
92-
/// operate on the generic `drop_entities::File` type.
92+
/// operate on the generic `arkdrop_entities::File` type.
9393
struct SenderFileDataAdapter {
9494
inner: Arc<dyn SenderFileData>,
9595
}

drop-core/exchanges/sender/src/send_files/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl Carrier {
445445

446446
let mut uni = connection.open_uni().await?;
447447

448-
Self::notify_progress(&file, sent, remaining, subscribers.clone());
448+
Self::notify_progress(file, sent, remaining, subscribers.clone());
449449

450450
loop {
451451
chunk_buffer.clear();
@@ -470,7 +470,7 @@ impl Carrier {
470470
sent += data_len;
471471
remaining = remaining.saturating_sub(data_len);
472472

473-
Self::notify_progress(&file, sent, remaining, subscribers.clone());
473+
Self::notify_progress(file, sent, remaining, subscribers.clone());
474474
}
475475

476476
uni.finish()?;

drop-core/exchanges/sender/src/send_files_to.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
77
use crate::{SenderConfig, SenderFile, SenderFileDataAdapter, SenderProfile};
88
use anyhow::Result;
9-
use drop_entities::{File, Profile};
10-
use dropx_common::{
9+
use arkdrop_entities::{File, Profile};
10+
use arkdropx_common::{
1111
handshake::{
1212
HandshakeConfig, HandshakeFile, HandshakeProfile, NegotiatedConfig,
1313
ReceiverHandshake, SenderHandshake,
@@ -493,7 +493,7 @@ impl Carrier {
493493
/// Example:
494494
/// ```rust no_run
495495
/// use std::sync::Arc;
496-
/// use dropx_sender::{
496+
/// use arkdropx_sender::{
497497
/// send_files_to::*, SenderProfile, SenderConfig, SenderFile,
498498
/// };
499499
///

drop-core/uniffi/src/receiver/receive_files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub async fn receive_files(
174174
let bubble = runtime
175175
.block_on(async {
176176
let adapted_request = create_adapted_request(request);
177-
return arkdropx_receiver::receive_files(adapted_request).await;
177+
arkdropx_receiver::receive_files(adapted_request).await
178178
})
179179
.map_err(|e| DropError::TODO(e.to_string()))?;
180180
Ok(Arc::new(ReceiveFilesBubble {
@@ -200,7 +200,7 @@ fn create_adapted_request(
200200
chunk_size: c.chunk_size,
201201
parallel_streams: c.parallel_streams,
202202
});
203-
return arkdropx_receiver::ReceiveFilesRequest {
203+
arkdropx_receiver::ReceiveFilesRequest {
204204
profile,
205205
ticket: request.ticket,
206206
confirmation: request.confirmation,

0 commit comments

Comments
 (0)