Skip to content

Commit 6481606

Browse files
authored
Merge pull request #15 from yuvipanda/no-hide
Don't poll server when page is not active
2 parents 9ff7d3f + bc14f96 commit 6481606

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

nbresuse/static/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ define(['jquery', 'base/js/utils'], function ($, utils) {
2121
}
2222

2323
var displayMetrics = function() {
24+
if (document.hidden) {
25+
// Don't poll when nobody is looking
26+
return;
27+
}
2428
$.getJSON(utils.get_body_data('baseUrl') + 'metrics', function(data) {
2529
// FIXME: Proper setups for MB and GB. MB should have 0 things
2630
// after the ., but GB should have 2.
@@ -48,6 +52,14 @@ define(['jquery', 'base/js/utils'], function ($, utils) {
4852
displayMetrics();
4953
// Update every five seconds, eh?
5054
setInterval(displayMetrics, 1000 * 5);
55+
56+
document.addEventListener("visibilitychange", function() {
57+
// Update instantly when user activates notebook tab
58+
// FIXME: Turn off update timer completely when tab not in focus
59+
if (!document.hidden) {
60+
displayMetrics();
61+
}
62+
}, false);
5163
};
5264

5365
return {

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setuptools.setup(
55
name="nbresuse",
6-
version='0.3.0',
6+
version='0.3.1',
77
url="https://github.com/yuvipanda/nbresuse",
88
author="Yuvi Panda",
99
description="Simple Jupyter extension to show how much resources (RAM) your notebook is using",

0 commit comments

Comments
 (0)