diff --git a/public/index.html b/public/index.html
index 7c6662b..1a1b07b 100644
--- a/public/index.html
+++ b/public/index.html
@@ -303,6 +303,7 @@
+
diff --git a/public/sw.js b/public/sw.js
index ed08810..3c5a17a 100644
--- a/public/sw.js
+++ b/public/sw.js
@@ -1,4 +1,4 @@
-const CACHE_VERSION = 'duimstok-v1';
+const CACHE_VERSION = 'duimstok-v2';
const APP_SHELL = [
'./',
@@ -19,6 +19,7 @@ const APP_SHELL = [
'../src/Infrastructure/utils.js',
'../src/Infrastructure/geolocation.js',
'../src/Infrastructure/db.js',
+ '../src/Infrastructure/persistentStorage.js',
'../src/Infrastructure/seedOrders.js',
'../src/Infrastructure/csvLoader.js',
'../src/Application/state.js',
diff --git a/src/Application/persistence.js b/src/Application/persistence.js
index 8c8dd14..2e3e54b 100644
--- a/src/Application/persistence.js
+++ b/src/Application/persistence.js
@@ -1,4 +1,6 @@
(function (A, I) {
+ let persistenceRequested = false;
+
function readFormFields() {
const fd = A.state.formData;
fd.inspecteur = document.getElementById('inp_inspecteur').value;
@@ -14,6 +16,10 @@
await I.saveInspection(A.state.formData);
document.getElementById('statusSaved').textContent =
'Opgeslagen: ' + new Date().toLocaleTimeString('nl-NL');
+ if (!persistenceRequested) {
+ persistenceRequested = true;
+ I.requestPersistence();
+ }
};
A.autoSave = function () {
diff --git a/src/Infrastructure/persistentStorage.js b/src/Infrastructure/persistentStorage.js
new file mode 100644
index 0000000..6486677
--- /dev/null
+++ b/src/Infrastructure/persistentStorage.js
@@ -0,0 +1,20 @@
+(function (I) {
+ function supported() {
+ return navigator.storage && typeof navigator.storage.persist === 'function';
+ }
+
+ I.isPersisted = async function () {
+ if (!supported()) return false;
+ return navigator.storage.persisted();
+ };
+
+ I.requestPersistence = async function () {
+ if (!supported()) return false;
+ if (await navigator.storage.persisted()) return true;
+ try {
+ return await navigator.storage.persist();
+ } catch {
+ return false;
+ }
+ };
+})(window.App.Infrastructure);