mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 21:51:23 +00:00
GUACAMOLE-549: Migrate recent connection history to localStorageService.
This commit is contained in:
@@ -20,4 +20,6 @@
|
|||||||
/**
|
/**
|
||||||
* The module for code relating to connection history.
|
* The module for code relating to connection history.
|
||||||
*/
|
*/
|
||||||
angular.module('history', []);
|
angular.module('history', [
|
||||||
|
'storage'
|
||||||
|
]);
|
||||||
|
@@ -20,7 +20,14 @@
|
|||||||
/**
|
/**
|
||||||
* A service for reading and manipulating the Guacamole connection history.
|
* A service for reading and manipulating the Guacamole connection history.
|
||||||
*/
|
*/
|
||||||
angular.module('history').factory('guacHistory', ['HistoryEntry', function guacHistory(HistoryEntry) {
|
angular.module('history').factory('guacHistory', ['$injector',
|
||||||
|
function guacHistory($injector) {
|
||||||
|
|
||||||
|
// Required types
|
||||||
|
var HistoryEntry = $injector.get('HistoryEntry');
|
||||||
|
|
||||||
|
// Required services
|
||||||
|
var localStorageService = $injector.get('localStorageService');
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
@@ -73,27 +80,15 @@ angular.module('history').factory('guacHistory', ['HistoryEntry', function guacH
|
|||||||
if (service.recentConnections.length > IDEAL_LENGTH)
|
if (service.recentConnections.length > IDEAL_LENGTH)
|
||||||
service.recentConnections.length = IDEAL_LENGTH;
|
service.recentConnections.length = IDEAL_LENGTH;
|
||||||
|
|
||||||
// Save updated history, ignore inability to use localStorage
|
// Save updated history
|
||||||
try {
|
localStorageService.setItem(GUAC_HISTORY_STORAGE_KEY, service.recentConnections);
|
||||||
if (localStorage)
|
|
||||||
localStorage.setItem(GUAC_HISTORY_STORAGE_KEY, JSON.stringify(service.recentConnections));
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get stored connection history, ignore inability to use localStorage
|
// Init stored connection history from localStorage
|
||||||
try {
|
var storedHistory = localStorageService.getItem(GUAC_HISTORY_STORAGE_KEY) || [];
|
||||||
|
if (storedHistory instanceof Array)
|
||||||
if (localStorage) {
|
service.recentConnections = storedHistory;
|
||||||
var storedHistory = JSON.parse(localStorage.getItem(GUAC_HISTORY_STORAGE_KEY) || "[]");
|
|
||||||
if (storedHistory instanceof Array)
|
|
||||||
service.recentConnections = storedHistory;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user