diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-11 19:08:54 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-11 19:44:13 -0400 |
commit | 6014fe5344cd22ff783af18db2b567e2cd7ef819 (patch) | |
tree | 7ffe9a3de33a3079db2084cedbe02ce52d36c721 /ext/bg/js/settings.js | |
parent | 2bfc7e39725420a2a1a89d968b0a1f27687f70ea (diff) |
Add support for persistent storage
Diffstat (limited to 'ext/bg/js/settings.js')
-rw-r--r-- | ext/bg/js/settings.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 84b54ba9..7ad628ba 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -724,14 +724,13 @@ async function storageEstimate() { storageEstimate.mostRecent = null; async function storageInfoInitialize() { + storagePersistInitialize(); const browser = await getBrowser(); const container = document.querySelector('#storage-info'); container.setAttribute('data-browser', browser); await storageShowInfo(); - container.classList.remove('storage-hidden'); - document.querySelector('#storage-refresh').addEventListener('click', () => storageShowInfo(), false); } @@ -770,6 +769,35 @@ function storageSpinnerShow(show) { } } +async function storagePersistInitialize() { + if (!(navigator.storage && navigator.storage.persist)) { + // Not supported + return; + } + + const info = document.querySelector('#storage-persist-info'); + const button = document.querySelector('#storage-persist-button'); + const checkbox = document.querySelector('#storage-persist-button-checkbox'); + + info.classList.remove('storage-hidden'); + button.classList.remove('storage-hidden'); + + let persisted = await navigator.storage.persisted(); + if (persisted) { + checkbox.checked = true; + } + + button.addEventListener('click', async () => { + if (persisted) { + return; + } + if (await navigator.storage.persist()) { + persisted = true; + checkbox.checked = true; + } + }, false); +} + /* * Information |