Skip to content

Commit

Permalink
Merge branch 'feature-custome-update-delay'
Browse files Browse the repository at this point in the history
  • Loading branch information
yakovenko.dima committed Jun 11, 2012
2 parents 043227b + a3d666c commit 27b07cf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 20 additions & 2 deletions background.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
var loadingAnimation = new LoadingAnimation();

//REQUEST VARIABLES
var pollIntervalMin = 1000 * 60; // 1 minute
var pollIntervalMax = 1000 * 60 * 60; // 1 hour
var DEFAULT_POLL_INTERVAL_MIN_MS = 1000 * 60; // 1 minute
var DEFAULT_POLL_INTERVAL_MAX_MS = 1000 * 60 * 60; // 1 hour
var requestFailureCount = 0; // used for exponential backoff
var requestTimeout = 1000 * 5; // 5 seconds
var requestTimeoutHandler = null;
Expand Down Expand Up @@ -44,6 +44,22 @@
startRequest();
}

function getUpdateDelayMinMS() {
if( !localStorage.updateDelayMinMS ) {
return DEFAULT_POLL_INTERVAL_MIN_MS;
}

return localStorage.updateDelayMinMS;
}

function getUpdateDelayMaxMS() {
if( !localStorage.updateDelayMaxMS ) {
return DEFAULT_POLL_INTERVAL_MAX_MS;
}

return localStorage.updateDelayMaxMS;
}

function getRedmineUrl() {
if( !localStorage.redmineUrl ) {
return null;
Expand Down Expand Up @@ -103,6 +119,8 @@
function scheduleRequest() {
var randomness = Math.random() + 1;
var exponent = Math.pow(2, requestFailureCount);
var pollIntervalMin = getUpdateDelayMinMS();
var pollIntervalMax = getUpdateDelayMaxMS();
var delay = Math.min(randomness * pollIntervalMin * exponent, pollIntervalMax);
delay = Math.round(delay);

Expand Down
10 changes: 10 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<p>Password:</p>
<p><input type="password" id="user-password" oninput="markDirty()"></p>

<div class="section-header first">Update delay</div>
<p>Update delay (sec): <input type="text" id="update-delay-min" oninput="markDirty()">, max: <input type="text" id="update-delay-max" oninput="markDirty()"></p>

<div class="section-header first">Issues</div>
<p>Show number of issues:</p>
<ul>
Expand Down Expand Up @@ -144,6 +147,9 @@
function init() {
redmineUrlTextbox = document.getElementById("redmine-url");

updateDelayMinSec = document.getElementById("update-delay-min");
updateDelayMaxSec = document.getElementById("update-delay-max");

showActiveIssues = document.getElementById("issues-active");
showNewIssues = document.getElementById("issues-new");
showActiveNewIssues = document.getElementById("issues-active-new");
Expand Down Expand Up @@ -192,6 +198,8 @@
function loadDefaults()
{
redmineUrlTextbox.value = localStorage.redmineUrl || "";
updateDelayMinSec.value = localStorage.updateDelayMinMS / 1000 || 60;
updateDelayMaxSec.value = localStorage.updateDelayMaxMS / 1000 || 60 * 60;

showActiveIssues.checked = false;
showNewIssues.checked = false;
Expand Down Expand Up @@ -336,6 +344,8 @@
}

localStorage.notificationsTimeout = newTimeout;
localStorage.updateDelayMinMS = parseInt(updateDelayMinSec.value) * 1000;
localStorage.updateDelayMaxMS = parseInt(updateDelayMaxSec.value) * 1000;

localStorage.redmineUrl = newUrl;
markClean();
Expand Down

0 comments on commit 27b07cf

Please sign in to comment.