feat: resumable transfer UX — surface partial downloads to UI on reconnect

Daemon scans the download directory for .tmp.meta sidecars on network join
and emits resumable_transfers IPC event. Web UI shows them in the Transfers
panel with a dimmed progress bar and "will resume on reconnect" note.

- proto: ResumableFile type, EvtResumableTransfers, resumable_files IpcMessage field
- mesh: ScanResumable() scans download dir and emits the event
- netmgr: call ScanResumable() after join (both Join and JoinByHash paths)
- web: resumableFiles store state, resumable_transfers handler, Transfers UI section

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-29 10:02:49 +02:00
parent 9de625d617
commit f319721e01
6 changed files with 93 additions and 4 deletions

View File

@@ -91,6 +91,47 @@ func writePartialMeta(path string, t *inboundTransfer) {
os.WriteFile(path, data, 0o644) //nolint:errcheck os.WriteFile(path, data, 0o644) //nolint:errcheck
} }
// ScanResumable scans the download directory for .tmp.meta sidecars left by
// interrupted transfers and emits a resumable_transfers IPC event listing them.
// Called once after a network is joined so the UI can show pending transfers.
func (m *Mesh) ScanResumable() {
if m.DownloadDir == "" {
return
}
metas, _ := filepath.Glob(filepath.Join(m.DownloadDir, "*.tmp.meta"))
var files []proto.ResumableFile
for _, mp := range metas {
data, err := os.ReadFile(mp)
if err != nil {
continue
}
var meta partialMeta
if err := json.Unmarshal(data, &meta); err != nil {
continue
}
tp := strings.TrimSuffix(mp, ".meta")
info, err := os.Stat(tp)
if err != nil {
continue
}
files = append(files, proto.ResumableFile{
Name: meta.Name,
SHA256: meta.SHA256,
From: meta.From,
Size: meta.Size,
Offset: info.Size(),
})
}
if len(files) == 0 {
return
}
m.emit(proto.IpcMessage{
Type: proto.EvtResumableTransfers,
ResumableFiles: files,
})
log.Printf("transfer: %d resumable transfer(s) found in %s", len(files), m.DownloadDir)
}
// OfferFile reads filename from ShareDir, computes its SHA-256, and sends a // OfferFile reads filename from ShareDir, computes its SHA-256, and sends a
// file-offer to peerID over the existing "yaw" DataChannel. // file-offer to peerID over the existing "yaw" DataChannel.
func (m *Mesh) OfferFile(peerID proto.PeerID, filename string) error { func (m *Mesh) OfferFile(peerID proto.PeerID, filename string) error {

View File

@@ -162,6 +162,8 @@ func (mgr *Manager) Join(name, shareDir string) (string, error) {
}() }()
} }
go m.ScanResumable()
mgr.emit(proto.IpcMessage{ mgr.emit(proto.IpcMessage{
Type: proto.EvtNetworkJoined, Type: proto.EvtNetworkJoined,
NetworkID: netID, NetworkID: netID,
@@ -249,6 +251,8 @@ func (mgr *Manager) JoinByHash(netHash64, shareDir string) (string, error) {
}() }()
} }
go m.ScanResumable()
mgr.emit(proto.IpcMessage{ mgr.emit(proto.IpcMessage{
Type: proto.EvtNetworkJoined, Type: proto.EvtNetworkJoined,
NetworkID: netID, NetworkID: netID,

View File

@@ -99,6 +99,15 @@ type PeerMessage struct {
HistoryDone bool `json:"history_done,omitempty"` HistoryDone bool `json:"history_done,omitempty"`
} }
// ResumableFile describes a partially-downloaded file found on daemon startup.
type ResumableFile struct {
Name string `json:"name"`
SHA256 string `json:"sha256"`
From string `json:"from"` // peer ID hex
Size int64 `json:"size"`
Offset int64 `json:"offset"` // bytes already received
}
// HistoryEntry is one message in a history_chunk response. // HistoryEntry is one message in a history_chunk response.
type HistoryEntry struct { type HistoryEntry struct {
Mid string `json:"mid"` Mid string `json:"mid"`
@@ -292,6 +301,7 @@ const (
EvtSharesList IpcMsgType = "shares_list" EvtSharesList IpcMsgType = "shares_list"
EvtRoomCreated IpcMsgType = "room_created" // field: room (name) EvtRoomCreated IpcMsgType = "room_created" // field: room (name)
EvtHistoryLoaded IpcMsgType = "history_loaded" // fields: room, messages EvtHistoryLoaded IpcMsgType = "history_loaded" // fields: room, messages
EvtResumableTransfers IpcMsgType = "resumable_transfers" // field: resumable_files
) )
// NetworkInfo summarises one joined network for state_snapshot and network_joined events. // NetworkInfo summarises one joined network for state_snapshot and network_joined events.
@@ -347,6 +357,7 @@ type IpcMessage struct {
InviteGenerated string `json:"invite,omitempty"` InviteGenerated string `json:"invite,omitempty"`
Files []FileEntry `json:"files,omitempty"` Files []FileEntry `json:"files,omitempty"`
Messages []ChatMessage `json:"messages,omitempty"` // history_loaded Messages []ChatMessage `json:"messages,omitempty"` // history_loaded
ResumableFiles []ResumableFile `json:"resumable_files,omitempty"` // resumable_transfers
Shares []ShareEntry `json:"shares,omitempty"` Shares []ShareEntry `json:"shares,omitempty"`
ShareNetworks []string `json:"network_ids,omitempty"` // for add_share command: scope to specific network IDs, or ["*"] for global ShareNetworks []string `json:"network_ids,omitempty"` // for add_share command: scope to specific network IDs, or ["*"] for global
// export_identity / import_identity // export_identity / import_identity

View File

@@ -7,12 +7,13 @@ function fmt(bytes: number): string {
} }
export function Transfers() { export function Transfers() {
const { pendingOffers, fileProgress, acceptOffer, rejectOffer, cancelTransfer, connectedPeers } = useWaste() const { pendingOffers, fileProgress, resumableFiles, acceptOffer, rejectOffer, cancelTransfer, connectedPeers } = useWaste()
const hasPending = Object.keys(pendingOffers).length > 0 const hasPending = Object.keys(pendingOffers).length > 0
const hasActive = Object.keys(fileProgress).length > 0 const hasActive = Object.keys(fileProgress).length > 0
const hasResumable = Object.keys(resumableFiles).length > 0
if (!hasPending && !hasActive) return null if (!hasPending && !hasActive && !hasResumable) return null
function alias(peerId: string) { function alias(peerId: string) {
return connectedPeers.find(p => p.id === peerId)?.alias ?? peerId.slice(0, 8) return connectedPeers.find(p => p.id === peerId)?.alias ?? peerId.slice(0, 8)
@@ -22,6 +23,24 @@ export function Transfers() {
<div className="sidebar-section"> <div className="sidebar-section">
<span className="sidebar-label">Transfers</span> <span className="sidebar-label">Transfers</span>
{hasResumable && (
<>
<span className="sidebar-label" style={{ fontSize: 10, opacity: 0.6 }}>resumable</span>
{Object.entries(resumableFiles).map(([sha256, f]) => {
const pct = f.size > 0 ? Math.round((f.offset / f.size) * 100) : 0
return (
<div key={sha256} className="transfer-row">
<span className="transfer-name" title={f.name}>{f.name}</span>
<span className="transfer-meta">{fmt(f.offset)} / {fmt(f.size)} · {alias(f.from)} · will resume on reconnect</span>
<div className="transfer-progress">
<div className="transfer-progress-bar" style={{ width: `${pct}%`, opacity: 0.5 }} />
</div>
</div>
)
})}
</>
)}
{Object.entries(pendingOffers).map(([xid, offer]) => ( {Object.entries(pendingOffers).map(([xid, offer]) => (
<div key={xid} className="transfer-row"> <div key={xid} className="transfer-row">
<span className="transfer-name" title={offer.name}>{offer.name}</span> <span className="transfer-name" title={offer.name}>{offer.name}</span>

View File

@@ -55,6 +55,8 @@ interface WasteState {
pendingOffers: Record<string, { peerId: string; name: string; size: number }> pendingOffers: Record<string, { peerId: string; name: string; size: number }>
// active in-progress transfers: xid → progress // active in-progress transfers: xid → progress
fileProgress: Record<string, { peerId: string; name: string; received: number; total: number }> fileProgress: Record<string, { peerId: string; name: string; received: number; total: number }>
// partial downloads found on daemon startup: sha256 → info
resumableFiles: Record<string, { name: string; from: string; size: number; offset: number }>
// actions // actions
connect: (url: string) => void connect: (url: string) => void
@@ -96,6 +98,7 @@ export const useWaste = create<WasteState>((set, get) => ({
sharedFilesByNetwork: {}, sharedFilesByNetwork: {},
pendingOffers: {}, pendingOffers: {},
fileProgress: {}, fileProgress: {},
resumableFiles: {},
connect(url: string) { connect(url: string) {
const adapter = new DaemonAdapter(url) const adapter = new DaemonAdapter(url)
@@ -355,6 +358,14 @@ export const useWaste = create<WasteState>((set, get) => ({
} }
break break
} }
case 'resumable_transfers': {
const files = (msg.resumable_files ?? []) as Array<{ name: string; sha256: string; from: string; size: number; offset: number }>
if (files.length === 0) break
const byHash: Record<string, { name: string; from: string; size: number; offset: number }> = {}
for (const f of files) byHash[f.sha256] = { name: f.name, from: f.from, size: f.size, offset: f.offset }
set(s => ({ resumableFiles: { ...s.resumableFiles, ...byHash } }))
break
}
case 'history_loaded': { case 'history_loaded': {
const room = msg.room const room = msg.room
const incoming = (msg.messages ?? []) as ChatMessage[] const incoming = (msg.messages ?? []) as ChatMessage[]

View File

@@ -85,6 +85,7 @@ export type IpcMsgType =
| 'history_loaded' | 'history_loaded'
| 'room_created' | 'room_created'
| 'create_room' | 'create_room'
| 'resumable_transfers'
export interface IpcMessage { export interface IpcMessage {
type: IpcMsgType type: IpcMsgType
@@ -129,4 +130,6 @@ export interface IpcMessage {
remote_address?: string remote_address?: string
// history_loaded // history_loaded
messages?: ChatMessage[] messages?: ChatMessage[]
// resumable_transfers
resumable_files?: Array<{ name: string; sha256: string; from: string; size: number; offset: number }>
} }