summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2012-09-14 16:23:03 -0500
committerJoel Martin <github@martintribe.org>2012-09-14 16:23:03 -0500
commit4d7f73df2f4a4c53abb9e5a349c520ec76221f2b (patch)
tree6181282dcf4e81e4d182d6f4fe6b31515074b7c0
parentd59d446583aa4770e0ec76f6c1abc24fca357bd2 (diff)
downloadnovnc-4d7f73df2f4a4c53abb9e5a349c520ec76221f2b.tar.gz
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.
-rw-r--r--include/ui.js27
1 files changed, 20 insertions, 7 deletions
diff --git a/include/ui.js b/include/ui.js
index dc837e6..a2f91e7 100644
--- a/include/ui.js
+++ b/include/ui.js
@@ -18,8 +18,14 @@ connSettingsOpen : false,
clipboardOpen: 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
-load: function() {
+start: function(callback) {
var html = '', i, sheet, sheets, llevels;
// Stylesheet selection dropdown
@@ -111,14 +117,18 @@ load: function() {
// Open the connect panel on first load
UI.toggleConnectPanel();
}
+
+ if (typeof callback === "function") {
+ callback(UI.rfb);
+ }
},
// Read form control compatible setting from cookie
getSetting: function(name) {
var val, ctrl = $D('noVNC_' + name);
- val = WebUtil.readCookie(name);
- if (ctrl.type === 'checkbox') {
- if (val.toLowerCase() in {'0':1, 'no':1, 'false':1}) {
+ val = WebUtil.readSetting(name);
+ if (val !== null && ctrl.type === 'checkbox') {
+ if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
val = false;
} else {
val = true;
@@ -134,7 +144,7 @@ updateSetting: function(name, value) {
var i, ctrl = $D('noVNC_' + name);
// Save the cookie for this session
if (typeof value !== 'undefined') {
- WebUtil.createCookie(name, value);
+ WebUtil.writeSetting(name, value);
}
// Update the settings control
@@ -170,7 +180,7 @@ saveSetting: function(name) {
} else {
val = ctrl.value;
}
- WebUtil.createCookie(name, val);
+ WebUtil.writeSetting(name, val);
//Util.Debug("Setting saved '" + name + "=" + val + "'");
return val;
},
@@ -182,7 +192,7 @@ initSetting: function(name, defVal) {
// Check Query string followed by cookie
val = WebUtil.getQueryVar(name);
if (val === null) {
- val = WebUtil.readCookie(name, defVal);
+ val = WebUtil.readSetting(name, defVal);
}
UI.updateSetting(name, val);
//Util.Debug("Setting '" + name + "' initialized to '" + val + "'");
@@ -240,6 +250,9 @@ toggleConnectPanel: function() {
$D('noVNC_controls').style.display = "none";
$D('connectButton').className = "noVNC_status_button";
UI.connSettingsOpen = false;
+ UI.saveSetting('host');
+ UI.saveSetting('port');
+ //UI.saveSetting('password');
} else {
$D('noVNC_controls').style.display = "block";
$D('connectButton').className = "noVNC_status_button_selected";