diff --git a/api/api.go b/api/api.go index 5027ed8..b93f884 100644 --- a/api/api.go +++ b/api/api.go @@ -53,7 +53,7 @@ func NewApi(db *database.DBManager, c *config.Config) *API { // Configure Cookie Session Store store := cookie.NewStore(newToken) store.Options(sessions.Options{ - MaxAge: 60 * 60 * 24 * 7, + MaxAge: 60 * 60 * 24 * 7, Secure: true, HttpOnly: true, SameSite: http.SameSiteStrictMode, diff --git a/assets/reader/index.js b/assets/reader/index.js index 6a52fc5..e0051d2 100644 --- a/assets/reader/index.js +++ b/assets/reader/index.js @@ -35,6 +35,7 @@ class EBookReader { // Initialize this.initDevice(); + this.initWakeLock(); this.initThemes(); this.initRenditionListeners(); this.initDocumentListeners(); @@ -49,13 +50,13 @@ class EBookReader { if (!currentCFI) this.bookState.currentWord = 0; await this.rendition.display(currentCFI); - // Restore Theme - this.setTheme(this.readerSettings.theme || "tan"); - let getStats = function () { // Start Timer this.bookState.pageStart = Date.now(); + // Restore Theme + this.setTheme(this.readerSettings.theme || "tan"); + // Get Stats let stats = this.getBookStats(); this.updateBookStats(stats); @@ -84,6 +85,46 @@ class EBookReader { this.saveSettings(); } + /** + * This is a hack and maintains a wake lock. It will + * automatically disable if there's been no input for + * 10 minutes. + * + * Ideally we use "navigator.wakeLock", but there's a + * bug in Safari (as of iOS 17.03) when intalled as a + * PWA that doesn't allow it to work [0] + * + * Unfortunate downside is iOS indicates that "No Sleep" + * is playing in both the Control Center and Lock Screen. + * iOS also stops any background sound. + * + * [0] https://progressier.com/pwa-capabilities/screen-wake-lock + **/ + initWakeLock() { + // Setup Wake Lock (Adding to DOM Necessary - iOS 17.03) + let timeoutID = null; + let wakeLock = new NoSleep(); + + // Override Standalone (Modified No-Sleep) + if (window.navigator.standalone) { + Object.assign(wakeLock.noSleepVideo.style, { + position: "absolute", + top: "-100%", + }); + document.body.append(wakeLock.noSleepVideo); + } + + // User Action Required (Manual bubble up from iFrame) + document.addEventListener("wakelock", function () { + // 10 Minute Timeout + if (timeoutID) clearTimeout(timeoutID); + timeoutID = setTimeout(wakeLock.disable, 1000 * 60 * 10); + + // Enable + wakeLock.enable(); + }); + } + /** * Register all themes with reader **/ @@ -92,20 +133,37 @@ class EBookReader { THEMES.forEach((theme) => this.rendition.themes.register(theme, THEME_FILE) ); + + let themeLinkEl = document.createElement("link"); + themeLinkEl.setAttribute("id", "themes"); + themeLinkEl.setAttribute("rel", "stylesheet"); + themeLinkEl.setAttribute("href", THEME_FILE); + document.head.append(themeLinkEl); } /** * Set theme & meta theme color **/ setTheme(themeName) { + // Update Settings + this.readerSettings.theme = themeName; + this.saveSettings(); + + // Set Reader Theme this.rendition.themes.select(themeName); + + // Get Reader Theme let themeColorEl = document.querySelector("[name='theme-color']"); - let backgroundColor = window.getComputedStyle( - this.rendition.getContents()[0].content - ).backgroundColor; + let themeStyleSheet = document.querySelector("#themes").sheet; + let themeStyleRule = Array.from(themeStyleSheet.cssRules).find( + (item) => item.selectorText == "." + themeName + ); + + // Match Reader Theme + if (!themeStyleRule) return; + let backgroundColor = themeStyleRule.style.backgroundColor; themeColorEl.setAttribute("content", backgroundColor); document.body.style.backgroundColor = backgroundColor; - this.saveSettings(); } /** @@ -156,6 +214,16 @@ class EBookReader { "*": { "font-size": "var(--editor-font-size) !important" }, }); + // ------------------------------------------------ // + // ---------------- Wake Lock Hack ---------------- // + // ------------------------------------------------ // + let wakeLockListener = function () { + doc.window.parent.document.dispatchEvent(new CustomEvent("wakelock")); + }; + renderDoc.addEventListener("click", wakeLockListener); + renderDoc.addEventListener("gesturechange", wakeLockListener); + renderDoc.addEventListener("touchstart", wakeLockListener); + // ------------------------------------------------ // // ---------------- Resize Helpers ---------------- // // ------------------------------------------------ // @@ -356,10 +424,11 @@ class EBookReader { // "t" Key (Theme Cycle) if ((e.keyCode || e.which) == 84) { let currentThemeIdx = THEMES.indexOf(this.readerSettings.theme); - if (THEMES.length == currentThemeIdx + 1) - this.readerSettings.theme = THEMES[0]; - else this.readerSettings.theme = THEMES[currentThemeIdx + 1]; - this.setTheme(this.readerSettings.theme); + let newTheme = + THEMES.length == currentThemeIdx + 1 + ? THEMES[0] + : THEMES[currentThemeIdx + 1]; + this.setTheme(newTheme); } }.bind(this), false @@ -370,9 +439,7 @@ class EBookReader { item.addEventListener( "click", function (event) { - this.readerSettings.theme = event.target.innerText; - - this.setTheme(this.readerSettings.theme); + this.setTheme(event.target.innerText); }.bind(this) ); }.bind(this) @@ -633,24 +700,46 @@ class EBookReader { // Get first visible node let contents = this.rendition.getContents()[0]; - let currentNode = contents.range(currentPos.start.cfi).startContainer - .parentNode; + let node = contents.range(currentPos.start.cfi).startContainer; // Walk upwards and build progress until body let childPos = ""; - while (currentNode.nodeName != "BODY") { - let relativeIndex = - Array.from(currentNode.parentNode.children) - .filter((item) => item.nodeName == currentNode.nodeName) - .indexOf(currentNode) + 1; + while (node.nodeName != "BODY") { + let ownValue; - // E.g: /div[10] - let itemPos = - "/" + currentNode.nodeName.toLowerCase() + "[" + relativeIndex + "]"; + switch (node.nodeType) { + case Node.ELEMENT_NODE: + let relativeIndex = + Array.from(node.parentNode.children) + .filter((item) => item.nodeName == node.nodeName) + .indexOf(node) + 1; - // Prepend childPos & Update currentNode refernce - childPos = itemPos + childPos; - currentNode = currentNode.parentNode; + ownValue = node.nodeName.toLowerCase() + "[" + relativeIndex + "]"; + break; + case Node.ATTRIBUTE_NODE: + ownValue = "@" + node.nodeName; + break; + case Node.TEXT_NODE: + case Node.CDATA_SECTION_NODE: + ownValue = "text()"; + break; + case Node.PROCESSING_INSTRUCTION_NODE: + ownValue = "processing-instruction()"; + break; + case Node.COMMENT_NODE: + ownValue = "comment()"; + break; + case Node.DOCUMENT_NODE: + ownValue = ""; + break; + default: + ownValue = ""; + break; + } + + // Prepend childPos & Update node reference + childPos = "/" + ownValue + childPos; + node = node.parentNode; } // Return derived progress diff --git a/assets/reader/no-sleep.js b/assets/reader/no-sleep.js new file mode 100644 index 0000000..cafda16 --- /dev/null +++ b/assets/reader/no-sleep.js @@ -0,0 +1,365 @@ +/*! NoSleep.js v0.12.0 - git.io/vfn01 - Rich Tibbett - MIT license */ +(function webpackUniversalModuleDefinition(root, factory) { + if (typeof exports === "object" && typeof module === "object") + module.exports = factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (typeof exports === "object") exports["NoSleep"] = factory(); + else root["NoSleep"] = factory(); +})(this, function () { + return /******/ (function (modules) { + // webpackBootstrap + /******/ // The module cache + /******/ var installedModules = {}; + /******/ + /******/ // The require function + /******/ function __webpack_require__(moduleId) { + /******/ + /******/ // Check if module is in cache + /******/ if (installedModules[moduleId]) { + /******/ return installedModules[moduleId].exports; + /******/ + } + /******/ // Create a new module (and put it into the cache) + /******/ var module = (installedModules[moduleId] = { + /******/ i: moduleId, + /******/ l: false, + /******/ exports: {}, + /******/ + }); + /******/ + /******/ // Execute the module function + /******/ modules[moduleId].call( + module.exports, + module, + module.exports, + __webpack_require__ + ); + /******/ + /******/ // Flag the module as loaded + /******/ module.l = true; + /******/ + /******/ // Return the exports of the module + /******/ return module.exports; + /******/ + } + /******/ + /******/ + /******/ // expose the modules object (__webpack_modules__) + /******/ __webpack_require__.m = modules; + /******/ + /******/ // expose the module cache + /******/ __webpack_require__.c = installedModules; + /******/ + /******/ // define getter function for harmony exports + /******/ __webpack_require__.d = function (exports, name, getter) { + /******/ if (!__webpack_require__.o(exports, name)) { + /******/ Object.defineProperty(exports, name, { + enumerable: true, + get: getter, + }); + /******/ + } + /******/ + }; + /******/ + /******/ // define __esModule on exports + /******/ __webpack_require__.r = function (exports) { + /******/ if (typeof Symbol !== "undefined" && Symbol.toStringTag) { + /******/ Object.defineProperty(exports, Symbol.toStringTag, { + value: "Module", + }); + /******/ + } + /******/ Object.defineProperty(exports, "__esModule", { value: true }); + /******/ + }; + /******/ + /******/ // create a fake namespace object + /******/ // mode & 1: value is a module id, require it + /******/ // mode & 2: merge all properties of value into the ns + /******/ // mode & 4: return value when already ns object + /******/ // mode & 8|1: behave like require + /******/ __webpack_require__.t = function (value, mode) { + /******/ if (mode & 1) value = __webpack_require__(value); + /******/ if (mode & 8) return value; + /******/ if ( + mode & 4 && + typeof value === "object" && + value && + value.__esModule + ) + return value; + /******/ var ns = Object.create(null); + /******/ __webpack_require__.r(ns); + /******/ Object.defineProperty(ns, "default", { + enumerable: true, + value: value, + }); + /******/ if (mode & 2 && typeof value != "string") + for (var key in value) + __webpack_require__.d( + ns, + key, + function (key) { + return value[key]; + }.bind(null, key) + ); + /******/ return ns; + /******/ + }; + /******/ + /******/ // getDefaultExport function for compatibility with non-harmony modules + /******/ __webpack_require__.n = function (module) { + /******/ var getter = + module && module.__esModule + ? /******/ function getDefault() { + return module["default"]; + } + : /******/ function getModuleExports() { + return module; + }; + /******/ __webpack_require__.d(getter, "a", getter); + /******/ return getter; + /******/ + }; + /******/ + /******/ // Object.prototype.hasOwnProperty.call + /******/ __webpack_require__.o = function (object, property) { + return Object.prototype.hasOwnProperty.call(object, property); + }; + /******/ + /******/ // __webpack_public_path__ + /******/ __webpack_require__.p = ""; + /******/ + /******/ + /******/ // Load entry module and return exports + /******/ return __webpack_require__((__webpack_require__.s = 0)); + /******/ + })( + /************************************************************************/ + /******/ [ + /* 0 */ + /***/ function (module, exports, __webpack_require__) { + "use strict"; + + var _createClass = (function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + })(); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _require = __webpack_require__(1), + webm = _require.webm, + mp4 = _require.mp4; + + // Detect iOS browsers < version 10 + + var oldIOS = function oldIOS() { + return ( + typeof navigator !== "undefined" && + parseFloat( + ( + "" + + (/CPU.*OS ([0-9_]{3,4})[0-9_]{0,1}|(CPU like).*AppleWebKit.*Mobile/i.exec( + navigator.userAgent + ) || [0, ""])[1] + ) + .replace("undefined", "3_2") + .replace("_", ".") + .replace("_", "") + ) < 10 && + !window.MSStream + ); + }; + + // Detect native Wake Lock API support + var nativeWakeLock = function nativeWakeLock() { + return "wakeLock" in navigator && window.navigator.standalone != true; + }; + + var NoSleep = (function () { + function NoSleep() { + var _this = this; + + _classCallCheck(this, NoSleep); + + this.enabled = false; + if (nativeWakeLock()) { + this._wakeLock = null; + var handleVisibilityChange = function handleVisibilityChange() { + if ( + _this._wakeLock !== null && + document.visibilityState === "visible" + ) { + _this.enable(); + } + }; + document.addEventListener( + "visibilitychange", + handleVisibilityChange + ); + document.addEventListener( + "fullscreenchange", + handleVisibilityChange + ); + } else if (oldIOS()) { + this.noSleepTimer = null; + } else { + // Set up no sleep video element + this.noSleepVideo = document.createElement("video"); + + this.noSleepVideo.setAttribute("title", "No Sleep"); + this.noSleepVideo.setAttribute("playsinline", ""); + + this._addSourceToVideo(this.noSleepVideo, "webm", webm); + this._addSourceToVideo(this.noSleepVideo, "mp4", mp4); + + this.noSleepVideo.addEventListener("loadedmetadata", function () { + if (_this.noSleepVideo.duration <= 1) { + // webm source + _this.noSleepVideo.setAttribute("loop", ""); + } else { + // mp4 source + _this.noSleepVideo.addEventListener( + "timeupdate", + function () { + if (_this.noSleepVideo.currentTime > 0.5) { + _this.noSleepVideo.currentTime = Math.random(); + } + } + ); + } + }); + } + } + + _createClass(NoSleep, [ + { + key: "_addSourceToVideo", + value: function _addSourceToVideo(element, type, dataURI) { + var source = document.createElement("source"); + source.src = dataURI; + source.type = "video/" + type; + element.appendChild(source); + }, + }, + { + key: "enable", + value: function enable() { + var _this2 = this; + + if (nativeWakeLock()) { + return navigator.wakeLock + .request("screen") + .then(function (wakeLock) { + _this2._wakeLock = wakeLock; + _this2.enabled = true; + console.log("Wake Lock active."); + _this2._wakeLock.addEventListener("release", function () { + // ToDo: Potentially emit an event for the page to observe since + // Wake Lock releases happen when page visibility changes. + // (https://web.dev/wakelock/#wake-lock-lifecycle) + console.log("Wake Lock released."); + }); + }) + .catch(function (err) { + _this2.enabled = false; + console.error(err.name + ", " + err.message); + throw err; + }); + } else if (oldIOS()) { + this.disable(); + console.warn( + "\n NoSleep enabled for older iOS devices. This can interrupt\n active or long-running network requests from completing successfully.\n See https://github.com/richtr/NoSleep.js/issues/15 for more details.\n " + ); + this.noSleepTimer = window.setInterval(function () { + if (!document.hidden) { + window.location.href = window.location.href.split("#")[0]; + window.setTimeout(window.stop, 0); + } + }, 15000); + this.enabled = true; + return Promise.resolve(); + } else { + var playPromise = this.noSleepVideo.play(); + return playPromise + .then(function (res) { + _this2.enabled = true; + return res; + }) + .catch(function (err) { + _this2.enabled = false; + throw err; + }); + } + }, + }, + { + key: "disable", + value: function disable() { + if (nativeWakeLock()) { + if (this._wakeLock) { + this._wakeLock.release(); + } + this._wakeLock = null; + } else if (oldIOS()) { + if (this.noSleepTimer) { + console.warn( + "\n NoSleep now disabled for older iOS devices.\n " + ); + window.clearInterval(this.noSleepTimer); + this.noSleepTimer = null; + } + } else { + this.noSleepVideo.pause(); + } + this.enabled = false; + }, + }, + { + key: "isEnabled", + get: function get() { + return this.enabled; + }, + }, + ]); + + return NoSleep; + })(); + + module.exports = NoSleep; + + /***/ + }, + /* 1 */ + /***/ function (module, exports, __webpack_require__) { + "use strict"; + + module.exports = { + webm: "data:video/webm;base64,GkXfowEAAAAAAAAfQoaBAUL3gQFC8oEEQvOBCEKChHdlYm1Ch4EEQoWBAhhTgGcBAAAAAAAVkhFNm3RALE27i1OrhBVJqWZTrIHfTbuMU6uEFlSua1OsggEwTbuMU6uEHFO7a1OsghV17AEAAAAAAACkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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UCkIqJZVSAADYgQMA2IGFUGjISgAgDwCAMEYpxhhzTiKkFGPOOScRUoox55yTSjHmnHPOSSkZc8w556SUzjnnnHNSSuacc845KaVzzjnnnJRSSuecc05KKSWEzkEnpZTSOeecEwAAVOAAABBgo8jmBCNBhYasBABSAQAMjmNZmuZ5omialiRpmud5niiapiZJmuZ5nieKqsnzPE8URdE0VZXneZ4oiqJpqirXFUXTNE1VVV2yLIqmaZqq6rowTdNUVdd1XZimaaqq67oubFtVVdV1ZRm2raqq6rqyDFzXdWXZloEsu67s2rIAAPAEBwCgAhtWRzgpGgssNGQlAJABAEAYg5BCCCFlEEIKIYSUUggJAAAYcAAACDChDBQashIASAUAAIyx1lprrbXWQGettdZaa62AzFprrbXWWmuttdZaa6211lJrrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmstpZRSSimllFJKKaWUUkoppZRSSgUA+lU4APg/2LA6wknRWGChISsBgHAAAMAYpRhzDEIppVQIMeacdFRai7FCiDHnJKTUWmzFc85BKCGV1mIsnnMOQikpxVZjUSmEUlJKLbZYi0qho5JSSq3VWIwxqaTWWoutxmKMSSm01FqLMRYjbE2ptdhqq7EYY2sqLbQYY4zFCF9kbC2m2moNxggjWywt1VprMMYY3VuLpbaaizE++NpSLDHWXAAAd4MDAESCjTOsJJ0VjgYXGrISAAgJACAQUooxxhhzzjnnpFKMOeaccw5CCKFUijHGnHMOQgghlIwx5pxzEEIIIYRSSsaccxBCCCGEkFLqnHMQQgghhBBKKZ1zDkIIIYQQQimlgxBCCCGEEEoopaQUQgghhBBCCKmklEIIIYRSQighlZRSCCGEEEIpJaSUUgohhFJCCKGElFJKKYUQQgillJJSSimlEkoJJYQSUikppRRKCCGUUkpKKaVUSgmhhBJKKSWllFJKIYQQSikFAAAcOAAABBhBJxlVFmGjCRcegEJDVgIAZAAAkKKUUiktRYIipRikGEtGFXNQWoqocgxSzalSziDmJJaIMYSUk1Qy5hRCDELqHHVMKQYtlRhC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EHAAABC8AAARLAAAEZwAABHoAAASWAAAEqQAABMUAAATYAAAE9AAABRAAAAUjAAAFPwAABVIAAAVuAAAFgQAABZ0AAAWwAAAFzAAABegAAAX7AAAGFwAAAGJ1ZHRhAAAAWm1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAALWlsc3QAAAAlqXRvbwAAAB1kYXRhAAAAAQAAAABMYXZmNTUuMzMuMTAw", + }; + + /***/ + }, + /******/ + ] + ); +}); diff --git a/database/query.sql b/database/query.sql index ba4b4bb..e235ef0 100644 --- a/database/query.sql +++ b/database/query.sql @@ -135,7 +135,8 @@ SELECT CAST(STRFTIME('%Y-%m-%d %H:%M:%S', devices.last_synced, users.time_offset) AS TEXT) AS last_synced FROM devices JOIN users ON users.id = devices.user_id -WHERE users.id = $user_id; +WHERE users.id = $user_id +ORDER BY devices.last_synced DESC; -- name: GetDocument :one SELECT * FROM documents diff --git a/database/query.sql.go b/database/query.sql.go index e540825..f5cce04 100644 --- a/database/query.sql.go +++ b/database/query.sql.go @@ -401,6 +401,7 @@ SELECT FROM devices JOIN users ON users.id = devices.user_id WHERE users.id = ?1 +ORDER BY devices.last_synced DESC ` type GetDevicesRow struct { diff --git a/templates/reader-base.html b/templates/reader-base.html index 0065ed2..8607e22 100644 --- a/templates/reader-base.html +++ b/templates/reader-base.html @@ -56,7 +56,7 @@ -
+
-
- {{block "content" .}}{{end}} -
+ {{block "content" .}}{{end}}
diff --git a/templates/reader.html b/templates/reader.html index 12f2034..b489894 100644 --- a/templates/reader.html +++ b/templates/reader.html @@ -1,12 +1,14 @@ {{template "base.html" .}} {{define "title"}}Reader{{end}} {{define "header"}} Documents {{end}} {{define "content"}} + +
+ + -
-