Skip to content

Commit

Permalink
Do not refresh the display when the app is hidden. Fix fwenzel#14.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielesvelto committed Jan 14, 2016
1 parent 7e65997 commit de852e3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
var accounts;
var lis = []; // list items for accounts.
var refreshInterval;
var refreshing = false; // Indicates whether we should refresh the page

/* Shortcuts */
var $ = document.querySelector.bind(document);
Expand Down Expand Up @@ -67,6 +68,12 @@

/* Main screen */
function refreshAccounts() {
refreshing = true;

if (document.hidden) {
return; // Do not refresh when hidden
}

// Let's do this again sometime.
if (accounts && !refreshInterval) {
refreshInterval = window.setInterval(refreshAccounts, 1000);
Expand Down Expand Up @@ -112,10 +119,23 @@
}

function stopUpdating() {
refreshing = false;
window.clearInterval(refreshInterval);
refreshInterval = null;
}

window.addEventListener('visibilitychange', function(evt) {
if (document.hidden) {
window.clearInterval(refreshInterval);
refreshInterval = null;
} else {
if (refreshing) {
// Resume refreshing only if we hadn't stopped before
refreshAccounts();
}
}
});

// Long click for delete.
$('#main .delete').addEventListener('click', function() {
var delButton = this;
Expand Down

0 comments on commit de852e3

Please sign in to comment.