diff options
author | Andrew Dolgov <[email protected]> | 2024-01-15 21:26:04 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2024-01-15 21:26:04 +0300 |
commit | 4aa5b7ce48d927f4ad04f7a9f34c7f4e89b1cc73 (patch) | |
tree | ab2bb5eba9d343d24c13da431e81ad8d0569bad5 /js | |
parent | 1f62d01cc14bfec5bff18713b3ede6ffb91206bd (diff) |
add back horrible hacks because epubjs can't open location on load (sometimes) from first attempt
Diffstat (limited to 'js')
-rw-r--r-- | js/reader.js | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/js/reader.js b/js/reader.js index 1a8bf10..682578a 100644 --- a/js/reader.js +++ b/js/reader.js @@ -1332,6 +1332,8 @@ const Reader = { } }, openLastRead: async function() { + $(".loading-message").html("Opening last read pageā¦"); + const rendition = window.book.rendition; if (!rendition) { @@ -1346,10 +1348,7 @@ const Reader = { if (lr_local && lr_local.cfi) { console.log('using local lastread cfi', lr_local.cfi); try { - Reader.Page.blockLastReadUpdate(); - - await rendition.display(lr_local.cfi); - + await Reader.Page.moveToCfiVerify(rendition, lr_local.cfi); location_found = true; } catch (e) { console.warn(e); @@ -1366,12 +1365,10 @@ const Reader = { if (lr_remote.cfi && lr_local.cfi != lr_remote.cfi && (!lr_local.timestamp || lr_remote.timestamp <= lr_local.timestamp)) { console.log(`using remote lastread cfi ${lr_remote.cfi} (timestamp is newer or local timestamp is missing)`); - Reader.Page.blockLastReadUpdate(); - await localforage.setItem(Reader.cacheId("lastread"), {cfi: lr_remote.cfi, page: lr_remote.page, total: lr_remote.total, timestamp: lr_remote.timestamp}); - await rendition.display(lr_remote.cfi); + await Reader.Page.moveToCfiVerify(rendition, lr_remote.cfi); location_found = true; } @@ -1388,6 +1385,23 @@ const Reader = { $(".loading").hide(); }, + moveToCfiVerify: async function(rendition, cfi, attempts = 3) { + for (let att = 1; att < attempts; att++) { + Reader.Page.blockLastReadUpdate(); + + console.log(`trying to open ${cfi}: attempt ${att} of ${attempts}...`); + + /* eslint-disable no-await-in-loop */ + await rendition.display(cfi); // we need to be synchronous here + + const moved_to = rendition.currentLocation().start.cfi; + + console.log(`opened cfi ${moved_to} expected ${cfi}`); + + if (moved_to == cfi) + return; + } + }, }, Settings: { onThemeChanged: async function(elem) { |