From a24453db15e5ac8f6339e483c6d2a3c9b2ccc697 Mon Sep 17 00:00:00 2001
From: Jaifroid File handling and File System access
- In some modern browsers, you will see an experimental option "Use Private File System" under the File and Folder selectors. If you tick this option,
+ In some modern browsers, you will see the option "Use Private File System" under the File and Folder selectors. If you tick this option,
then the app will request an Origin Private File System
(OPFS) from the browser. Then, when you pick a ZIM file, instead of opening it, it will be stored in the OPFS. You may also select more than one archive to store in the OPFS,
including all the parts of a split ZIM file (.zimaa
, .zimab
, etc.). Note that in this case, only the .zimaa
entry will be displayed in
@@ -848,7 +848,7 @@
We are switching to the Private File System (OPFS).
' + + 'If asked, please accept a one-time Storage permission prompt.
' + + 'More info: the OPFS provides significant benefits such as: faster file system access; ' + + 'no permission prompts; automatic reload of archive on app start.', + 'Switching to OPFS', true, 'Use classic file picker') + .then(function (response) { + if (response) { + document.getElementById('useOPFSCheck').click(); + } else { + settingsStore.setItem('useOPFS', false, Infinity); + } + }); + }, 2000); + } else if (!settingsStore.getItem('useOPFS')) { + // This esnures that there is an explicit setting for useOPFS, which in turn allows us to tell if the + // app is running for the first time (so we don't keep prompting the user to use the OPFS) + settingsStore.setItem('useOPFS', false, Infinity); + } }); // Bottom bar : // @TODO Since bottom bar now hidden in Settings and About the returntoArticle code cannot be accessed; @@ -1506,7 +1528,7 @@ document.getElementById('useOPFSCheck').addEventListener('change', function (e) if (e.target.checked) { return cache.requestPersistentStorage(); } else { - return Promise.resolve(true); + return Promise.resolve(false); } }; if (e.target.checked && /Electron/i.test(params.appType)) { @@ -1533,6 +1555,7 @@ document.getElementById('useOPFSCheck').addEventListener('change', function (e) } else { e.target.checked = false; params.useOPFS = false; + settingsStore.setItem('useOPFS', false, Infinity); setOPFSUI(); } }); @@ -1552,6 +1575,7 @@ function loadOPFSDirectory () { }); } else { params.useOPFS = false; + settingsStore.setItem('useOPFS', false, Infinity); setOPFSUI(); return uiUtil.systemAlert('Your browser does not support the Origin Private File System!
Please try picking a folder instead.
'); } @@ -1588,7 +1612,6 @@ function setOPFSUI () { if ('showOpenFilePicker' in window) btnExportOPFSEntry.style.display = ''; cache.populateOPFSStorageQuota(); } else { - settingsStore.setItem('useOPFS', false, Infinity); useOPFS.checked = false; archiveFileCol.classList.remove('col-xs-5'); archiveFileCol.classList.add('col-xs-6'); @@ -3287,6 +3310,7 @@ if (storages !== null && storages.length > 0 || getNativeFSHandle(); } else { // We are in an app that cannot open files auotomatically, so populate archive list and show file pickers + document.getElementById('btnRescanDeviceStorage').click(); btnConfigure.click(); searchForArchivesInPreferencesOrStorage(true); } @@ -3362,7 +3386,7 @@ if (storages !== null && storages.length > 0 || } } else { // If DeviceStorage is not available, we display the file select components - displayFileSelect(); + document.getElementById('btnRescanDeviceStorage').click(); if (document.getElementById('archiveFilesLegacy').files && document.getElementById('archiveFilesLegacy').files.length > 0) { // Archive files are already selected, setLocalArchiveFromFileSelect(); diff --git a/www/js/init.js b/www/js/init.js index daee9e1d4..90df37030 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -34,7 +34,7 @@ window.onerror = function (msg, url, line, col, error) { // Set a beforeUnload handler to prevent app reloads without confirmation if a ZIM file is loaded window.addEventListener('beforeunload', function (event) { - if (params.interceptBeforeUnload && appstate && appstate.selectedArchive && params.appCache && !/Electron/.test(params.appType)) { + if (params.interceptBeforeUnload && !params.useOPFS && appstate && appstate.selectedArchive && params.appCache && !/Electron/.test(params.appType)) { var confirmationMessage = 'Warning: you may have to reload the ZIM archive if you leave this page!'; event.preventDefault(); // Included for legacy support, e.g. Chrome/Edge < 119 diff --git a/www/js/lib/kiwixServe.js b/www/js/lib/kiwixServe.js index 2aee2a8f0..386605b88 100644 --- a/www/js/lib/kiwixServe.js +++ b/www/js/lib/kiwixServe.js @@ -566,7 +566,9 @@ function requestXhttpData (URL, lang, subj, kiwixDate) { if (params.useOPFS || (window.showSaveFilePicker && params.pickedFolder && params.pickedFolder.kind === 'directory')) { bodyDoc += 'Direct download'; bodyDoc += params.useOPFS ? ' to Origin Private File System' : ' to your ZIM folder'; - bodyDoc += ', for smaller archives: (downloads archive in-app)
\r\n'; + bodyDoc += ', for smaller archives: (downloads archive in-app)Browser-managed download from mirrors, for larger archives:'; } else { bodyDoc += '
Browser-managed download from mirrors:';