Up-in-the-Air – commitdiff

You can use Git to clone the repository via the web URL. Download snapshot (zip)
Gracefully handle being blocked from local storage, no more crash on open
authorJulian Fietkau <git@fietkau.software>
Thu, 3 Oct 2024 21:01:06 +0000 (23:01 +0200)
committerJulian Fietkau <git@fietkau.software>
Thu, 3 Oct 2024 21:05:29 +0000 (23:05 +0200)
index.html
main.js

index f1af2912e896b8c814004a835db81c373a32bf04..5112f4d288774eedbbfa407c4cfdd9e39d1bd105 100644 (file)
         drop-shadow(.1em .1em 0 #fff) 
         drop-shadow(-.1em .1em 0 #fff);
   }
+  .upInTheAirGame .ui-page.options .warning.storage {
+    display: none;
+  }
   .upInTheAirGame .ui-page.options .feather label:nth-child(1) { z-index: 50; }
   .upInTheAirGame .ui-page.options .feather label:nth-child(2) { z-index: 49; }
   .upInTheAirGame .ui-page.options .feather label:nth-child(3) { z-index: 48; }
 </div>
 </div>
 
+<div class="area warning storage"><strong>Unable to store data:</strong> Your browser is preventing the game from using the local data storage, possibly due to strict privacy settings. Your in-game data will not be saved between visits.</div>
 
 <button class="goto title">Back</button>
 </div>
diff --git a/main.js b/main.js
index 80c789081d6ea6ae1c605a6effb03b7e6ce5442a..4336a9b88917994e057081faf777c80f52b98d05 100644 (file)
--- a/main.js
+++ b/main.js
@@ -1149,7 +1149,13 @@ game['fn'].loadSettings = () => {
       'tapmode': false,
     },
   };
-  let stored = window['localStorage'].getItem('upInTheAirGameSettings');
+  let stored;
+  try {
+    stored = window['localStorage'].getItem('upInTheAirGameSettings');
+    game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'none';
+  } catch(error) {
+    game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'block';
+  }
   if(stored) {
     let merge = (source, target) => {
       for(let k of Object.keys(source)) {
@@ -1306,7 +1312,12 @@ game['fn'].applySettings = () => {
     game.settings['keyboard'][direction] = ui.querySelector('.keyboard button.' + direction).value.split('|');
   }
   game.settings['keyboard']['tapmode'] = ui.querySelector('input[value="tapmode"]').checked;
-  window['localStorage'].setItem('upInTheAirGameSettings', JSON.stringify(game.settings));
+  try {
+    window['localStorage'].setItem('upInTheAirGameSettings', JSON.stringify(game.settings));
+    game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'none';
+  } catch(error) {
+    game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'block';
+  }
 
   for(let audioCategory of ['music', 'sounds']) {
     game.settings['audio'][audioCategory] = parseInt(ui.querySelector('.audio input[type=range].' + audioCategory).value, 10) / 100;
@@ -1826,7 +1837,7 @@ game['fn'].moveToPage = (target, skipFade = false) => {
         btn.classList.remove('active');
       }
     });
-    game.ui.root.querySelectorAll('.options > div.area').forEach((area) => {
+    game.ui.root.querySelectorAll('.options > div.area.twocol').forEach((area) => {
       if(area.classList.contains('general')) {
         area.style.display = 'flex';
       } else {