Commit ee1af441 authored by Joel Martin's avatar Joel Martin

ui.js: use localStorage/chrome.storage for settings.

Switch from using cookies to store setting to using localStorage (or
chrome.storage.sync if available in extension/app mode) for the
settings. Also refactor to make the initializing of the setting and
and loading of the UI to be more asynchronous.
parent 3af1c275
...@@ -18,8 +18,14 @@ connSettingsOpen : false, ...@@ -18,8 +18,14 @@ connSettingsOpen : false,
clipboardOpen: false, clipboardOpen: false,
keyboardVisible: false, keyboardVisible: false,
// Setup rfb object, load settings from browser storage, then call
// UI.init to setup the UI/menus
load: function (callback) {
WebUtil.initSettings(UI.start, callback);
},
// Render default UI and initialize settings menu // Render default UI and initialize settings menu
load: function() { start: function(callback) {
var html = '', i, sheet, sheets, llevels; var html = '', i, sheet, sheets, llevels;
// Stylesheet selection dropdown // Stylesheet selection dropdown
...@@ -111,14 +117,18 @@ load: function() { ...@@ -111,14 +117,18 @@ load: function() {
// Open the connect panel on first load // Open the connect panel on first load
UI.toggleConnectPanel(); UI.toggleConnectPanel();
} }
if (typeof callback === "function") {
callback(UI.rfb);
}
}, },
// Read form control compatible setting from cookie // Read form control compatible setting from cookie
getSetting: function(name) { getSetting: function(name) {
var val, ctrl = $D('noVNC_' + name); var val, ctrl = $D('noVNC_' + name);
val = WebUtil.readCookie(name); val = WebUtil.readSetting(name);
if (ctrl.type === 'checkbox') { if (val !== null && ctrl.type === 'checkbox') {
if (val.toLowerCase() in {'0':1, 'no':1, 'false':1}) { if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
val = false; val = false;
} else { } else {
val = true; val = true;
...@@ -134,7 +144,7 @@ updateSetting: function(name, value) { ...@@ -134,7 +144,7 @@ updateSetting: function(name, value) {
var i, ctrl = $D('noVNC_' + name); var i, ctrl = $D('noVNC_' + name);
// Save the cookie for this session // Save the cookie for this session
if (typeof value !== 'undefined') { if (typeof value !== 'undefined') {
WebUtil.createCookie(name, value); WebUtil.writeSetting(name, value);
} }
// Update the settings control // Update the settings control
...@@ -170,7 +180,7 @@ saveSetting: function(name) { ...@@ -170,7 +180,7 @@ saveSetting: function(name) {
} else { } else {
val = ctrl.value; val = ctrl.value;
} }
WebUtil.createCookie(name, val); WebUtil.writeSetting(name, val);
//Util.Debug("Setting saved '" + name + "=" + val + "'"); //Util.Debug("Setting saved '" + name + "=" + val + "'");
return val; return val;
}, },
...@@ -182,7 +192,7 @@ initSetting: function(name, defVal) { ...@@ -182,7 +192,7 @@ initSetting: function(name, defVal) {
// Check Query string followed by cookie // Check Query string followed by cookie
val = WebUtil.getQueryVar(name); val = WebUtil.getQueryVar(name);
if (val === null) { if (val === null) {
val = WebUtil.readCookie(name, defVal); val = WebUtil.readSetting(name, defVal);
} }
UI.updateSetting(name, val); UI.updateSetting(name, val);
//Util.Debug("Setting '" + name + "' initialized to '" + val + "'"); //Util.Debug("Setting '" + name + "' initialized to '" + val + "'");
...@@ -240,6 +250,9 @@ toggleConnectPanel: function() { ...@@ -240,6 +250,9 @@ toggleConnectPanel: function() {
$D('noVNC_controls').style.display = "none"; $D('noVNC_controls').style.display = "none";
$D('connectButton').className = "noVNC_status_button"; $D('connectButton').className = "noVNC_status_button";
UI.connSettingsOpen = false; UI.connSettingsOpen = false;
UI.saveSetting('host');
UI.saveSetting('port');
//UI.saveSetting('password');
} else { } else {
$D('noVNC_controls').style.display = "block"; $D('noVNC_controls').style.display = "block";
$D('connectButton').className = "noVNC_status_button_selected"; $D('connectButton').className = "noVNC_status_button_selected";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment