Dashboard: Auto-refresh even if focus is supported

* No change if unsupported
* If supported, still auto-refresh at the selected frequency (if any),
  but only if not hidden.

This is useful for always-on displays (e.g. a "baby clock"). Fixes #253
This commit is contained in:
Ohad Lutzky 2021-07-13 23:49:09 +01:00 committed by Christopher Charbonneau Wells
parent 411641903f
commit 798d7663fd
8 changed files with 12 additions and 3 deletions

View File

@ -18,8 +18,8 @@ class Settings(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
dashboard_refresh_rate = models.DurationField(
verbose_name=_('Refresh rate'),
help_text=_('This setting will only be used when a browser does not '
'support refresh on focus.'),
help_text=_('If supported by browser, the dashboard will only refresh '
'when visible, and also when receiving focus.'),
blank=True,
null=True,
default=timezone.timedelta(minutes=1),

View File

@ -34,6 +34,9 @@ BabyBuddy.Dashboard = function ($) {
}
else {
window.addEventListener('focus', Dashboard.handleVisibilityChange, false);
if (refresh_rate) {
runIntervalId = setInterval(Dashboard.handleVisibilityChange, refresh_rate);
}
}
},

View File

@ -207,6 +207,9 @@ BabyBuddy.Dashboard = function ($) {
}
else {
window.addEventListener('focus', Dashboard.handleVisibilityChange, false);
if (refresh_rate) {
runIntervalId = setInterval(Dashboard.handleVisibilityChange, refresh_rate);
}
}
},

Binary file not shown.

View File

@ -207,6 +207,9 @@ BabyBuddy.Dashboard = function ($) {
}
else {
window.addEventListener('focus', Dashboard.handleVisibilityChange, false);
if (refresh_rate) {
runIntervalId = setInterval(Dashboard.handleVisibilityChange, refresh_rate);
}
}
},

Binary file not shown.

File diff suppressed because one or more lines are too long