From ca4f94469f9aaee5a577e7cbe4bdd7aa92967b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Tue, 26 Sep 2017 18:47:52 +0200 Subject: [PATCH] make Snap! work in Safari 11 offline (file:// protocol) again, Sheesh --- gui.js | 20 ++++++++++++++++---- history.txt | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gui.js b/gui.js index d8271a69..54eb8c93 100644 --- a/gui.js +++ b/gui.js @@ -269,7 +269,7 @@ IDE_Morph.prototype.openIn = function (world) { var hash, usr, myself = this, urlLanguage = null; // get persistent user data, if any - if (localStorage) { + if (this.hasLocalStorage()) { usr = localStorage['-snap-user']; if (usr) { usr = SnapCloud.parseResponse(usr)[0]; @@ -2188,24 +2188,36 @@ IDE_Morph.prototype.saveSetting = function (key, value) { if (!this.savingPreferences) { return; } - if (localStorage) { + if (this.hasLocalStorage()) { localStorage['-snap-setting-' + key] = value; } }; IDE_Morph.prototype.getSetting = function (key) { - if (localStorage) { + if (this.hasLocalStorage()) { return localStorage['-snap-setting-' + key]; } return null; }; IDE_Morph.prototype.removeSetting = function (key) { - if (localStorage) { + if (this.hasLocalStorage()) { delete localStorage['-snap-setting-' + key]; } }; +IDE_Morph.prototype.hasLocalStorage = function () { + // checks whether localStorage is available, + // this kludgy try/catch mechanism is needed + // because Safari 11 is paranoid about accessing + // localstorage from the file:// protocol + try { + return !isNil(localStorage); + } catch (err) { + return false; + } +}; + // IDE_Morph sprite list access IDE_Morph.prototype.addNewSprite = function () { diff --git a/history.txt b/history.txt index d3bbd95b..5e3a3f04 100755 --- a/history.txt +++ b/history.txt @@ -3659,6 +3659,7 @@ Fixes: * GUI: fixed camera support for Safari, thanks, Bernat! * Morphic: added stopEditing() event for keyboardReceiver * Blocks: added floating toggle for keyboard entry to scripts toolbar +* GUI: make Snap! work in Safari 11 offline (file:// protocol) again, Sheesh === v4.1 release candidate ===