Skip to content

Commit

Permalink
Add chunk replication progressbar to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
jannickheisch committed Dec 11, 2023
1 parent c04fe66 commit cc01c74
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions android/tinySSB/app/src/main/assets/web/tremola.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@
<progress id='connection-overlay-progressbar-want' class='connection-overlay-progressbar' value="0" max="100"></progress>
<div id='connection-overlay-progressbar-label-want' class="connection-overlay-progressbar-label"></div>
</div>
<div style="position: relative; margin-bottom: 10px;">
<img src='img/receive.png' alt="Icon" class="progress-icon">
<progress id='connection-overlay-progressbar-chnk' class='connection-overlay-progressbar' value="0" max="100"></progress>
<div id='connection-overlay-progressbar-label-chnk' class="connection-overlay-progressbar-label"></div>
</div>
</div>

<div id='goset-progress-container' style="display: none;">
Expand Down
23 changes: 23 additions & 0 deletions android/tinySSB/app/src/main/assets/web/tremola_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,29 @@ function refresh_goset_progressbar(curr, max) {

}

var max_chnks = 0
function refresh_chunk_progressbar(remaining) {

if(remaining != 0) {
max_chnks = Math.max(max_chnks, remaining)
} else {
max_chnks = 0 // reset
}

console.log("refresh_chunk_progressbar", remaining, max_chnks)


if(remaining > 0) {
var percentage = (1 - ((remaining - 0) / (max_chnks - 0))) * 100
document.getElementById('connection-overlay-progressbar-chnk').value = percentage
document.getElementById('connection-overlay-progressbar-label-chnk').textContent = remaining + " Chunks left"
} else {
document.getElementById('connection-overlay-progressbar-chnk').value = 100
document.getElementById('connection-overlay-progressbar-label-chnk').textContent = "Chunks — Synchronized"
}

}

function refresh_connection_progressbar(min_entries, old_min_entries, old_want_entries, curr_want_entries, max_entries) {

console.log("min:", min_entries)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
"ready" -> {
eval("b2f_initialize(\"${act.idStore.identity.toRef()}\")")
frontend_ready = true
act.tinyRepo.addNumberOfPendingChunks(0) // initialize chunk progress bar
act.tinyNode.beacon()
}
"reset" -> { // UI reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
if (chunk_cnt > 0) {
val ptr = pkt.sliceArray(36 until 56)
state.pend_sc[seq] = Pending(0, chunk_cnt, ptr, state.max_pos + TINYSSB_PKT_LEN)
context.tinyRepo.addNumberOfPendingChunks(chunk_cnt)
val chunk_fct = { chunk: ByteArray, fid: ByteArray?, seq: Int -> context.tinyNode.incoming_chunk(chunk,fid,seq) }
context.tinyDemux.arm_blb(ptr, chunk_fct, fid, seq, 0)
} else { // no sidechain, entry is complete
Expand Down Expand Up @@ -225,6 +226,7 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
val chunk_fct = { chunk: ByteArray, fid: ByteArray?, seq: Int -> context.tinyNode.incoming_chunk(chunk,fid,seq) }
context.tinyDemux.arm_blb(pend.hptr, chunk_fct, fid, seq, pend.cnr)
}
context.tinyRepo.addNumberOfPendingChunks(-1)
val f = fnt.startWrite()
f.write(state.toWire())
fnt.finishWrite(f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Repo(val context: MainActivity) {
private var chnk_is_valid = false
private var want_offs = 0
private var chnk_offs = 0
private var numberOfPendingChunks = 0

private fun clean(dir: File) {
for (f in dir.listFiles() ?: emptyArray()) {
Expand Down Expand Up @@ -74,6 +75,7 @@ class Repo(val context: MainActivity) {
val chunk_fct = { chunk: ByteArray, fid: ByteArray?, seq: Int -> context.tinyNode.incoming_chunk(chunk,fid,seq) }
for ((seq, p) in chains) {
context.tinyDemux.arm_blb(p.hptr, chunk_fct,fid,seq, p.cnr)
addNumberOfPendingChunks(p.rem)
}


Expand Down Expand Up @@ -334,4 +336,13 @@ class Repo(val context: MainActivity) {
return loadingFinished
}

fun addNumberOfPendingChunks(amount: Int) {
numberOfPendingChunks += amount
context.wai.eval("refresh_chunk_progressbar($numberOfPendingChunks)")
}

fun getNumberOfPendingCHunks(): Int {
return numberOfPendingChunks
}

}

0 comments on commit cc01c74

Please sign in to comment.