[TEST] try to improve sync
This commit is contained in:
parent
be439e5421
commit
0f3fbaa418
8 changed files with 374 additions and 145 deletions
|
|
@ -1405,8 +1405,11 @@ function renderProgressBar(bar, bytes, totalBytes) {
|
|||
|
||||
// Older peers only send the overall byte totals - then those drive the bar.
|
||||
function barValues(info) {
|
||||
const bytes = info.barBytes == null ? info.bytes : info.barBytes
|
||||
const total = info.barTotalBytes == null ? info.totalBytes : info.barTotalBytes
|
||||
let bytes = Math.max(0, Number(info.barBytes == null ? info.bytes : info.barBytes) || 0)
|
||||
let total = Math.max(0, Number(info.barTotalBytes == null ? info.totalBytes : info.barTotalBytes) || 0)
|
||||
// a provisional total can be smaller than what already moved (it grows as
|
||||
// entries arrive): the bar reads full, never over 100%
|
||||
if (total > 0 && bytes > total) bytes = total
|
||||
return [bytes, total]
|
||||
}
|
||||
|
||||
|
|
@ -1569,10 +1572,13 @@ async function runLanSync(device, code, categories, force) {
|
|||
state.lanPushing = true
|
||||
window.plwl.onLanSyncProgress(data => {
|
||||
if (!active) return
|
||||
// the file counter is cumulative across units; only the bar follows phases
|
||||
phase.textContent = t('lansync.phase.' + data.phase, data.label || '').trim()
|
||||
// waiting phases have no translation under lansync.phase.*
|
||||
const phaseKey = data.phase === 'wait' ? 'lansync.waiting' : 'lansync.phase.' + data.phase
|
||||
phase.textContent = t(phaseKey, data.label || '').trim()
|
||||
renderProgressBar(bar, ...barValues(data))
|
||||
// phases without a file count clear it: a stale "5 / 10" must not linger
|
||||
if (data.total > 0) count.textContent = t('lansync.progressFiles', data.done, data.total)
|
||||
else count.textContent = ''
|
||||
stats.textContent = lanStatsLine(data.items, data.itemsDone, data.totals)
|
||||
bytes.textContent = lanBytesLine(data.bytes, data.totalBytes)
|
||||
})
|
||||
|
|
@ -1635,6 +1641,8 @@ function onLanIncoming(info) {
|
|||
if (totals.apps > 0) parts.push(t('lansync.statsApps', totals.apps))
|
||||
if (totals.wines > 0) parts.push(t('lansync.statsWines', totals.wines))
|
||||
if (totals.prefixes > 0) parts.push(t('lansync.statsPrefixes', totals.prefixes))
|
||||
// a settings-only sync moves no units, but it is still a real request
|
||||
if (!parts.length && totals.settings > 0) parts.push(t('lansync.incomingSettings'))
|
||||
const modal = showModal(`
|
||||
<h2 id="ls-incoming-title"></h2>
|
||||
<p id="ls-incoming-text"></p>
|
||||
|
|
@ -1724,7 +1732,9 @@ function armReceiveWatchdog() {
|
|||
receiveStall = setTimeout(() => {
|
||||
receiveStall = null
|
||||
const parts = receiveModalParts()
|
||||
if (parts) parts.phase.textContent = t('lansync.recvStalled')
|
||||
if (!parts) return
|
||||
// silence also means no bytes: freeze the bar and ask for patience
|
||||
parts.phase.textContent = t('lansync.waiting')
|
||||
}, RECEIVE_STALL_MS)
|
||||
}
|
||||
|
||||
|
|
@ -1759,16 +1769,18 @@ function onLanReceiving(info) {
|
|||
function renderReceiving(info) {
|
||||
const parts = receiveModalParts()
|
||||
if (!parts) return
|
||||
// a ping keeps the screen as it is; only a reopened popup needs a phase line
|
||||
// a ping keeps the bar and counters as they are; only the phase line moves
|
||||
if (info.stage === 'wait') {
|
||||
if (!parts.phase.textContent) parts.phase.textContent = t('lansync.recvWaiting')
|
||||
parts.phase.textContent = t('lansync.waiting')
|
||||
return
|
||||
}
|
||||
// the same phases, worded for receiving
|
||||
const phaseKey = RECV_PHASE_KEYS[info.stage] || 'lansync.phase.' + info.stage
|
||||
parts.phase.textContent = (info.stage === 'start' ? t('lansync.recvWaiting') : t(phaseKey, info.label || '')).trim()
|
||||
parts.phase.textContent = (info.stage === 'start' ? t('lansync.waiting') : t(phaseKey, info.label || '')).trim()
|
||||
renderProgressBar(parts.bar, ...barValues(info))
|
||||
if (info.total > 0) parts.count.textContent = t('lansync.progressFiles', info.done, info.total)
|
||||
// the file counter belongs to the copy/done phases; receive events for other
|
||||
// phases carry cumulative numbers that would look stale mid-phase
|
||||
if ((info.stage === 'copy' || info.stage === 'done') && info.total > 0) parts.count.textContent = t('lansync.progressFiles', info.done, info.total)
|
||||
else parts.count.textContent = ''
|
||||
parts.stats.textContent = lanStatsLine(info.items, info.itemsDone, info.totals)
|
||||
parts.bytes.textContent = lanBytesLine(info.bytes, info.totalBytes)
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.3 KiB |
Loading…
Add table
Add a link
Reference in a new issue