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
271 changes: 259 additions & 12 deletions crates/filesync/src/client.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion crates/filesync/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ pub enum ChunkOutcome {

pub enum LargeFileEndOutcome {
Committed,
CommittedWithConflict(ConflictInfo),
MissingChunks(Vec<u32>),
}

Expand Down Expand Up @@ -408,7 +409,7 @@ pub fn handle_recv_large_file_end(
}),
);
}
Ok(LargeFileEndOutcome::Committed)
Ok(LargeFileEndOutcome::CommittedWithConflict(ci))
}
FinishResult::MissingChunks(indices) => {
warn!(
Expand Down
19 changes: 9 additions & 10 deletions crates/filesync/src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct DashboardState {
log_expanded: bool,
file_tree: Vec<FileNode>,
active_tab: SideTab,
had_conflicts: bool,
last_tree_refresh: Instant,
}

Expand Down Expand Up @@ -159,6 +160,7 @@ impl FileSyncGui {
log_expanded: false,
file_tree,
active_tab: SideTab::Stats,
had_conflicts: false,
last_tree_refresh: Instant::now(),
})
}
Expand Down Expand Up @@ -315,6 +317,7 @@ impl FileSyncGui {
log_expanded: false,
file_tree,
active_tab: SideTab::Stats,
had_conflicts: false,
last_tree_refresh: Instant::now(),
});
}
Expand All @@ -333,14 +336,15 @@ impl FileSyncGui {
}

if let Screen::Dashboard(d) = &mut self.screen {
d.state
.write()
.end_sync_activity_if_quiet(std::time::Duration::from_millis(1500));
d.snapshot = d.state.read().clone();
// Auto-switch to Conflicts tab when conflicts appear.
if !d.snapshot.conflicts.is_empty() && d.active_tab == SideTab::Stats {
let now_has_conflicts = !d.snapshot.conflicts.is_empty();
if now_has_conflicts && !d.had_conflicts {
d.active_tab = SideTab::Conflicts;
} else if d.snapshot.conflicts.is_empty() && d.active_tab == SideTab::Conflicts
{
d.active_tab = SideTab::Stats;
}
d.had_conflicts = now_has_conflicts;
// Periodically refresh the file tree from disk.
if d.last_tree_refresh.elapsed() >= std::time::Duration::from_secs(5) {
d.file_tree = refresh_file_tree(&d.file_tree, &d.config.sync_root);
Expand Down Expand Up @@ -498,7 +502,6 @@ impl FileSyncGui {
}
}


fn view_setup(s: &SetupState) -> Element<'_, Message> {
let step_num = match s.step {
SetupStep::Folder => 1u8,
Expand Down Expand Up @@ -790,7 +793,6 @@ fn view_setup_review(s: &SetupState) -> Element<'_, Message> {
setup_card(inner.into())
}


fn view_dashboard(d: &DashboardState) -> Element<'_, Message> {
let snap = &d.snapshot;
let is_paused = d.manager.is_paused();
Expand Down Expand Up @@ -843,7 +845,6 @@ fn main_content(d: &DashboardState) -> Element<'_, Message> {
.into()
}


fn toggle_expanded(nodes: &mut Vec<FileNode>, id: usize) {
for node in nodes.iter_mut() {
if node.id == id && node.is_dir {
Expand Down Expand Up @@ -965,7 +966,6 @@ fn refresh_file_tree(old_tree: &[FileNode], root: &std::path::Path) -> Vec<FileN
new_tree
}


/// Escapes a bare string value for embedding inside a TOML double-quoted string.
fn toml_escape(s: &str) -> String {
s.replace('\\', "\\\\").replace('"', "\\\"")
Expand Down Expand Up @@ -1004,7 +1004,6 @@ exclude_regex = []
)
}


fn setup_card(content: Element<Message>) -> Element<Message> {
container(content)
.width(Length::Fill)
Expand Down
6 changes: 6 additions & 0 deletions crates/filesync/src/gui/components/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn connection_badge(status: &ConnectionStatus) -> Element<'_, Message> {
match status {
ConnectionStatus::Idle => (theme::GREEN, theme::green_text),
ConnectionStatus::InitialSync => (theme::AMBER, theme::amber_text),
ConnectionStatus::Syncing => (theme::AMBER, theme::amber_text),
ConnectionStatus::Connecting => (theme::YELLOW, theme::yellow_text),
ConnectionStatus::AwaitingApproval => (theme::YELLOW, theme::yellow_text),
ConnectionStatus::Paused => (theme::YELLOW, theme::yellow_text),
Expand Down Expand Up @@ -111,6 +112,11 @@ mod tests {
let _ = super::view(&ConnectionStatus::InitialSync);
}

#[test]
fn view_syncing_does_not_panic() {
let _ = super::view(&ConnectionStatus::Syncing);
}

#[test]
fn view_idle_does_not_panic() {
let _ = super::view(&ConnectionStatus::Idle);
Expand Down
45 changes: 33 additions & 12 deletions crates/filesync/src/gui/components/status_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,31 @@ use crate::gui::theme;
pub fn view(snap: &SyncSnapshot, is_paused: bool) -> Element<'_, Message> {
let status_label = text(snap.status.label()).size(13).style(theme::secondary);

let right_detail: Element<Message> = if matches!(snap.status, ConnectionStatus::InitialSync) {
let is_transferring = matches!(
snap.status,
ConnectionStatus::InitialSync | ConnectionStatus::Syncing
);

let right_detail: Element<Message> = if is_transferring {
let transferred = snap.bytes_sent + snap.bytes_received;
let files = snap.files_sent + snap.files_received;
if snap.transfer_total > 0 {
let pct = (transferred as f32 / snap.transfer_total as f32 * 100.0) as u32;
text(format!("{} ({pct}%)", fmt_bytes(transferred)))
.size(12)
.style(theme::muted)
.into()
text(format!(
"{files} file(s) \u{b7} {} ({pct}%)",
fmt_bytes(transferred)
))
.size(12)
.style(theme::muted)
.into()
} else {
text(format!("{} transferred", fmt_bytes(transferred)))
.size(12)
.style(theme::muted)
.into()
text(format!(
"{files} file(s) \u{b7} {} transferred",
fmt_bytes(transferred)
))
.size(12)
.style(theme::muted)
.into()
}
} else {
Space::new().width(0).into()
Expand Down Expand Up @@ -68,7 +80,7 @@ pub fn view(snap: &SyncSnapshot, is_paused: bool) -> Element<'_, Message> {
]
.align_y(Alignment::Center);

let progress: Element<Message> = if matches!(snap.status, ConnectionStatus::InitialSync) {
let progress: Element<Message> = if is_transferring {
let transferred = snap.bytes_sent + snap.bytes_received;
let fraction = if snap.transfer_total > 0 {
(transferred as f32 / snap.transfer_total as f32).clamp(0.0, 1.0)
Expand Down Expand Up @@ -99,6 +111,7 @@ fn status_indicator_dot(status: &ConnectionStatus) -> Element<'static, Message>
let color = match status {
ConnectionStatus::Idle => theme::GREEN,
ConnectionStatus::InitialSync => theme::AMBER,
ConnectionStatus::Syncing => theme::AMBER,
ConnectionStatus::Connecting => theme::AMBER,
ConnectionStatus::Paused => theme::YELLOW,
ConnectionStatus::AwaitingApproval => theme::YELLOW,
Expand Down Expand Up @@ -202,7 +215,6 @@ mod tests {
use super::fmt_bytes;
use crate::gui::state::{ConnectionStatus, SyncSnapshot};


#[test]
fn fmt_bytes_zero() {
assert_eq!(fmt_bytes(0), "0 B");
Expand Down Expand Up @@ -243,7 +255,6 @@ mod tests {
assert_eq!(fmt_bytes(2_147_483_648), "2.00 GiB");
}


#[test]
fn view_disconnected_not_paused_does_not_panic() {
let _ = super::view(&SyncSnapshot::default(), false);
Expand All @@ -264,6 +275,16 @@ mod tests {
let _ = super::view(&snap, false);
}

#[test]
fn view_syncing_no_total_does_not_panic() {
let mut snap = SyncSnapshot::default();
snap.status = ConnectionStatus::Syncing;
snap.transfer_total = 0;
snap.files_received = 3;
snap.bytes_received = 4096;
let _ = super::view(&snap, false);
}

#[test]
fn view_initial_sync_with_total_does_not_panic() {
let mut snap = SyncSnapshot::default();
Expand Down
Loading
Loading