mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-549: Migrate storage/retrieval of local preferences to localStorageService.
This commit is contained in:
@@ -21,7 +21,11 @@
|
|||||||
* A service for setting and retrieving browser-local preferences. Preferences
|
* A service for setting and retrieving browser-local preferences. Preferences
|
||||||
* may be any JSON-serializable type.
|
* 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.
|
* Reference to the provider itself.
|
||||||
@@ -128,24 +132,18 @@ angular.module('settings').provider('preferenceService', function preferenceServ
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get stored preferences, ignore inability to use localStorage
|
// Get stored preferences from localStorage
|
||||||
try {
|
var storedPreferences = localStorageServiceProvider.getItem(GUAC_PREFERENCES_STORAGE_KEY);
|
||||||
|
if (storedPreferences)
|
||||||
if (localStorage) {
|
angular.extend(provider.preferences, storedPreferences);
|
||||||
var preferencesJSON = localStorage.getItem(GUAC_PREFERENCES_STORAGE_KEY);
|
|
||||||
if (preferencesJSON)
|
|
||||||
angular.extend(provider.preferences, JSON.parse(preferencesJSON));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
|
|
||||||
// Factory method required by provider
|
// Factory method required by provider
|
||||||
this.$get = ['$injector', function preferenceServiceFactory($injector) {
|
this.$get = ['$injector', function preferenceServiceFactory($injector) {
|
||||||
|
|
||||||
// Required services
|
// Required services
|
||||||
var $rootScope = $injector.get('$rootScope');
|
var $rootScope = $injector.get('$rootScope');
|
||||||
var $window = $injector.get('$window');
|
var $window = $injector.get('$window');
|
||||||
|
var localStorageService = $injector.get('localStorageService');
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
@@ -168,14 +166,7 @@ angular.module('settings').provider('preferenceService', function preferenceServ
|
|||||||
* Persists the current values of all preferences, if possible.
|
* Persists the current values of all preferences, if possible.
|
||||||
*/
|
*/
|
||||||
service.save = function save() {
|
service.save = function save() {
|
||||||
|
localStorageService.setItem(GUAC_PREFERENCES_STORAGE_KEY, service.preferences);
|
||||||
// Save updated preferences, ignore inability to use localStorage
|
|
||||||
try {
|
|
||||||
if (localStorage)
|
|
||||||
localStorage.setItem(GUAC_PREFERENCES_STORAGE_KEY, JSON.stringify(service.preferences));
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Persist settings when window is unloaded
|
// Persist settings when window is unloaded
|
||||||
@@ -195,4 +186,4 @@ angular.module('settings').provider('preferenceService', function preferenceServ
|
|||||||
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
});
|
}]);
|
||||||
|
@@ -26,5 +26,6 @@ angular.module('settings', [
|
|||||||
'list',
|
'list',
|
||||||
'navigation',
|
'navigation',
|
||||||
'notification',
|
'notification',
|
||||||
'rest'
|
'rest',
|
||||||
|
'storage'
|
||||||
]);
|
]);
|
||||||
|
Reference in New Issue
Block a user