From 4b567e35d50fe4e0e16863ac45a8ceaf68c8bbd4 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 12 Jan 2017 03:46:34 +0900 Subject: [PATCH] suppress refresh when user is inactive (#7219) --- public/app/core/services/context_srv.ts | 4 ++++ public/app/features/dashboard/timeSrv.js | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/public/app/core/services/context_srv.ts b/public/app/core/services/context_srv.ts index 3d048e4f869..f3d319f11c6 100644 --- a/public/app/core/services/context_srv.ts +++ b/public/app/core/services/context_srv.ts @@ -57,6 +57,10 @@ export class ContextSrv { store.set('grafana.sidemenu.pinned', val); } + isGrafanaVisible() { + return !!(document.visibilityState === undefined || document.visibilityState === 'visible'); + } + toggleSideMenu() { this.sidemenu = !this.sidemenu; if (!this.sidemenu) { diff --git a/public/app/features/dashboard/timeSrv.js b/public/app/features/dashboard/timeSrv.js index f83c2bf0517..8c600319589 100644 --- a/public/app/features/dashboard/timeSrv.js +++ b/public/app/features/dashboard/timeSrv.js @@ -10,7 +10,7 @@ define([ var module = angular.module('grafana.services'); - module.service('timeSrv', function($rootScope, $timeout, $routeParams, timer) { + module.service('timeSrv', function($rootScope, $timeout, $routeParams, timer, contextSrv) { var self = this; // default time @@ -95,7 +95,9 @@ define([ self.cancel_scheduled_refresh(); self.refresh_timer = timer.register($timeout(function () { self.start_scheduled_refresh(after_ms); - self.refreshDashboard(); + if (contextSrv.isGrafanaVisible()) { + self.refreshDashboard(); + } }, after_ms)); };