prevent non-spa navigation while uploading

This commit is contained in:
ed 2021-02-21 21:08:53 +01:00
parent b14b86990f
commit fa656577d1
2 changed files with 31 additions and 12 deletions

View file

@ -980,9 +980,11 @@ function apply_perms(perms) {
}
var act = document.querySelector('#ops>a.act');
var areq = act.getAttribute('data-perm');
if (areq && !has(perms, areq))
goto();
if (act) {
var areq = act.getAttribute('data-perm');
if (areq && !has(perms, areq))
goto();
}
var have_write = has(perms, "write");
var tds = document.querySelectorAll('#u2conf td');

View file

@ -424,6 +424,7 @@ function up2k_init(have_crypto) {
var tasker = (function () {
var mutex = false;
var was_busy = false;
function taskerd() {
if (mutex)
@ -442,16 +443,25 @@ function up2k_init(have_crypto) {
st.busy.upload.length;
}
if (flag) {
var need_flag = 0 !=
st.todo.hash.length +
st.todo.handshake.length +
st.todo.upload.length +
st.busy.hash.length +
st.busy.handshake.length +
st.busy.upload.length;
var is_busy = 0 !=
st.todo.hash.length +
st.todo.handshake.length +
st.todo.upload.length +
st.busy.hash.length +
st.busy.handshake.length +
st.busy.upload.length;
if (need_flag) {
if (was_busy != is_busy) {
was_busy = is_busy;
if (is_busy)
window.addEventListener("beforeunload", warn_uploader_busy);
else
window.removeEventListener("beforeunload", warn_uploader_busy);
}
if (flag) {
if (is_busy) {
var now = new Date().getTime();
flag.take(now);
if (!flag.ours) {
@ -1108,5 +1118,12 @@ function up2k_init(have_crypto) {
}
function warn_uploader_busy(e) {
e.preventDefault();
e.returnValue = '';
return "upload in progress, click abort and use the file-tree to navigate instead";
}
if (document.querySelector('#op_up2k.act'))
goto_up2k();