need to make sure that get loop runs only once; closes #20
This commit is contained in:
@@ -121,8 +121,10 @@ td:last-child {
|
||||
list-style-type: none;
|
||||
border: 1px solid black;
|
||||
}
|
||||
#menu li, #menu li * {
|
||||
#menu li {
|
||||
padding: 0 1em 0 1em;
|
||||
}
|
||||
#menu li, #menu li * {
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
|
@@ -119,6 +119,20 @@ function status(text, msg) {
|
||||
});
|
||||
}
|
||||
|
||||
var getLoopTimeout = null; ///< store get timeout to make sure only one is running
|
||||
/// Set timeout for next get request
|
||||
/** @param time timeout time in ms, defaults to 10000 */
|
||||
function getLoop(time) {
|
||||
if (!time) time = 10000;
|
||||
getLoopStop();
|
||||
getLoopTimeout = setTimeout(get, time);
|
||||
}
|
||||
/// Stop get loop if it is running
|
||||
function getLoopStop() {
|
||||
if (getLoopTimeout) clearTimeout(getLoopTimeout);
|
||||
getLoopTimeout = null;
|
||||
}
|
||||
|
||||
/// Alert user
|
||||
/** Alert user, e.g. that a new message has arrived.
|
||||
@param */
|
||||
@@ -139,6 +153,7 @@ function togglemenu() {
|
||||
|
||||
/// Download Profile Backup
|
||||
function backup() {
|
||||
getLoopStop();
|
||||
status("<p>Starting backup download ...</p>");
|
||||
var download = document.createElement('a');
|
||||
download.href = 'data:attachment/text,'+encodeURI(JSON.stringify(localStorage));
|
||||
@@ -160,6 +175,7 @@ function backup() {
|
||||
|
||||
/// Upload Profile Backup
|
||||
function restore(evt) {
|
||||
getLoopStop();
|
||||
status("<p>Starting backup restore ...</p>");
|
||||
if (!window.FileReader)
|
||||
return error("your browser dows not support file upload", true);
|
||||
@@ -404,7 +420,7 @@ function get() {
|
||||
var res=JSON.parse(pk);
|
||||
var key=openpgp.key.readArmored(res);
|
||||
if (!res||key.err) {
|
||||
setTimeout(get, 10000);
|
||||
getLoop();
|
||||
return error("key of receiver not found", true);
|
||||
}
|
||||
var message = openpgp.message.readArmored(e.msg);
|
||||
@@ -449,7 +465,7 @@ function get() {
|
||||
}).fail(function(e) {
|
||||
error("offline", true)
|
||||
});
|
||||
setTimeout(get, 10000); // repeat every 10 seconds
|
||||
getLoop(); // repeat every 10 seconds
|
||||
}
|
||||
|
||||
/// Send Message To Server
|
||||
@@ -535,7 +551,7 @@ function chat() {
|
||||
$("#username").html(userid()+"@safechat.ch");
|
||||
$.ajax({url: "chat.html", success: function(res) {
|
||||
status(res);
|
||||
setTimeout(get, 2000);
|
||||
getLoop(2000);
|
||||
}}).fail(function() {
|
||||
error("offline")
|
||||
});
|
||||
|
Reference in New Issue
Block a user