diff options
author | Andrew Dolgov <[email protected]> | 2018-09-13 14:11:49 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-09-13 14:11:49 +0300 |
commit | b5b914878733d9c1a7f95f833dcda15cad9770d9 (patch) | |
tree | 5c70fb4d2de5e8b48e90be0c593f9525744b5e5f /js | |
parent | f9030b3157226733a8154abe235f78a8f35a1df5 (diff) |
add download complete notifications
Diffstat (limited to 'js')
-rw-r--r-- | js/index.js | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/js/index.js b/js/index.js index c51515b..b16a742 100644 --- a/js/index.js +++ b/js/index.js @@ -1,5 +1,7 @@ 'use strict'; +var _dl_progress_timeout; + function cache_refresh(force) { if ('serviceWorker' in navigator) { localforage.getItem("epube.cache-timestamp").then(function(stamp) { @@ -94,7 +96,9 @@ function offline_cache(bookId, callback) { console.log(cacheId + ' got data'); - fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) { + var promises = []; + + promises.push(fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) { if (resp.status == 200) { console.log(cacheId + ' got book'); @@ -102,9 +106,9 @@ function offline_cache(bookId, callback) { localforage.setItem(cacheId + '.book', resp.blob()); } - }); + })); - fetch("backend.php?op=getpagination&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) { + promises.push(fetch("backend.php?op=getpagination&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) { if (resp.status == 200) { console.log(cacheId + ' got pagination'); @@ -112,30 +116,41 @@ function offline_cache(bookId, callback) { localforage.setItem(cacheId + '.locations', JSON.parse(text)); }); } - }); + })); - fetch("backend.php?op=getlastread&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) { + promises.push(fetch("backend.php?op=getlastread&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) { if (resp.status == 200) { console.log(cacheId + ' got lastread'); resp.text().then(function(text) { localforage.setItem(cacheId + '.lastread', JSON.parse(text)); }); } - }); + })); if (data.has_cover) { - fetch("backend.php?op=cover&id=" + bookId, {credentials: 'same-origin'}).then(function(resp) { + promises.push(fetch("backend.php?op=cover&id=" + bookId, {credentials: 'same-origin'}).then(function(resp) { if (resp.status == 200) { console.log(cacheId + ' got cover'); localforage.setItem(cacheId + '.cover', resp.blob()); } - }); + })); } + Promise.all(promises).then(function() { + $(".dl-progress") + .show() + .html("Finished downloading <b>" + data.title + "</b>"); + + window.clearTimeout(_dl_progress_timeout); + + _dl_progress_timeout = window.setTimeout(function() { + $(".dl-progress").fadeOut(); + }, 5*1000); + }); }); } |