Browse Source

Correctly feature detect localStorage (fixes #1632)

Jakob Borg 10 years ago
parent
commit
a027a60f5d
2 changed files with 17 additions and 2 deletions
  1. 16 1
      gui/scripts/syncthing/core/services/localeService.js
  2. 1 1
      internal/auto/gui.files.go

+ 16 - 1
gui/scripts/syncthing/core/services/localeService.js

@@ -32,8 +32,23 @@ angular.module('syncthing.core')
             }
 
             function autoConfigLocale() {
+                // Feature detect localStorage; https://mathiasbynens.be/notes/localstorage-pattern
+                var storage;
+                var fail;
+                var uid;
+                try {
+                    uid = new Date;
+                    (storage = window.localStorage).setItem(uid, uid);
+                    fail = storage.getItem(uid) != uid;
+                    storage.removeItem(uid);
+                    fail && (storage = false);
+                } catch (exception) {}
+
                 var params = $location.search();
-                var savedLang = typeof(localStorage) != 'undefined' && localStorage[_SYNLANG];
+                var savedLang;
+                if (storage) {
+                    savedLang = storage[_SYNLANG];
+                }
 
                 if(params.lang) {
                     useLocale(params.lang, true);

File diff suppressed because it is too large
+ 1 - 1
internal/auto/gui.files.go


Some files were not shown because too many files changed in this diff