You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/04/20 09:13:19 UTC

[3/5] guacamole-client git commit: GUACAMOLE-549: Migrate storage/retrieval of local preferences to localStorageService.

GUACAMOLE-549: Migrate storage/retrieval of local preferences to localStorageService.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/1686e6f1
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/1686e6f1
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/1686e6f1

Branch: refs/heads/master
Commit: 1686e6f149fb6d3ea80217ed18792d22ded45e6f
Parents: 831e4e0
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Apr 18 20:43:30 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Thu Apr 19 12:49:19 2018 -0700

----------------------------------------------------------------------
 .../app/settings/services/preferenceService.js  | 37 ++++++++------------
 .../main/webapp/app/settings/settingsModule.js  |  3 +-
 2 files changed, 16 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1686e6f1/guacamole/src/main/webapp/app/settings/services/preferenceService.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/services/preferenceService.js b/guacamole/src/main/webapp/app/settings/services/preferenceService.js
index 9af4281..bcd8633 100644
--- a/guacamole/src/main/webapp/app/settings/services/preferenceService.js
+++ b/guacamole/src/main/webapp/app/settings/services/preferenceService.js
@@ -21,7 +21,11 @@
  * A service for setting and retrieving browser-local preferences. Preferences
  * may be any JSON-serializable type.
  */
-angular.module('settings').provider('preferenceService', function preferenceServiceProvider() {
+angular.module('settings').provider('preferenceService', ['$injector',
+    function preferenceServiceProvider($injector) {
+
+    // Required providers
+    var localStorageServiceProvider = $injector.get('localStorageServiceProvider');
 
     /**
      * Reference to the provider itself.
@@ -128,24 +132,18 @@ angular.module('settings').provider('preferenceService', function preferenceServ
 
     };
 
-    // Get stored preferences, ignore inability to use localStorage
-    try {
-
-        if (localStorage) {
-            var preferencesJSON = localStorage.getItem(GUAC_PREFERENCES_STORAGE_KEY);
-            if (preferencesJSON)
-                angular.extend(provider.preferences, JSON.parse(preferencesJSON));
-        }
-
-    }
-    catch (ignore) {}
+    // Get stored preferences from localStorage
+    var storedPreferences = localStorageServiceProvider.getItem(GUAC_PREFERENCES_STORAGE_KEY);
+    if (storedPreferences)
+        angular.extend(provider.preferences, storedPreferences);
 
     // Factory method required by provider
     this.$get = ['$injector', function preferenceServiceFactory($injector) {
 
         // Required services
-        var $rootScope = $injector.get('$rootScope');
-        var $window    = $injector.get('$window');
+        var $rootScope          = $injector.get('$rootScope');
+        var $window             = $injector.get('$window');
+        var localStorageService = $injector.get('localStorageService');
 
         var service = {};
 
@@ -168,14 +166,7 @@ angular.module('settings').provider('preferenceService', function preferenceServ
          * Persists the current values of all preferences, if possible.
          */
         service.save = function save() {
-
-            // Save updated preferences, ignore inability to use localStorage
-            try {
-                if (localStorage)
-                    localStorage.setItem(GUAC_PREFERENCES_STORAGE_KEY, JSON.stringify(service.preferences));
-            }
-            catch (ignore) {}
-
+            localStorageService.setItem(GUAC_PREFERENCES_STORAGE_KEY, service.preferences);
         };
 
         // Persist settings when window is unloaded
@@ -195,4 +186,4 @@ angular.module('settings').provider('preferenceService', function preferenceServ
 
     }];
 
-});
+}]);

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1686e6f1/guacamole/src/main/webapp/app/settings/settingsModule.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/settingsModule.js b/guacamole/src/main/webapp/app/settings/settingsModule.js
index 7adc0d1..62ad1c8 100644
--- a/guacamole/src/main/webapp/app/settings/settingsModule.js
+++ b/guacamole/src/main/webapp/app/settings/settingsModule.js
@@ -26,5 +26,6 @@ angular.module('settings', [
     'list',
     'navigation',
     'notification',
-    'rest'
+    'rest',
+    'storage'
 ]);