From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- comm/mail/components/AppIdleManager.jsm | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 comm/mail/components/AppIdleManager.jsm (limited to 'comm/mail/components/AppIdleManager.jsm') diff --git a/comm/mail/components/AppIdleManager.jsm b/comm/mail/components/AppIdleManager.jsm new file mode 100644 index 0000000000..cc42c23178 --- /dev/null +++ b/comm/mail/components/AppIdleManager.jsm @@ -0,0 +1,45 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const EXPORTED_SYMBOLS = ["appIdleManager"]; + +// This module provides a mechanism to turn window focus and blur events +// into app idle notifications. If we get a blur notification that is not +// followed by a focus notification in less than some small number of seconds, +// then we send a begin app idle notification. +// If we get a focus event, and we're app idle, then we send an end app idle +// notification. +// The notification topic is "mail:appIdle", the values are "idle", and "back" + +var appIdleManager = { + _appIdle: false, + _timerInterval: 5000, // 5 seconds ought to be plenty + get _timer() { + delete this._timer; + return (this._timer = Cc["@mozilla.org/timer;1"].createInstance( + Ci.nsITimer + )); + }, + + _timerCallback() { + appIdleManager._appIdle = true; + Services.obs.notifyObservers(null, "mail:appIdle", "idle"); + }, + + onBlur() { + appIdleManager._timer.initWithCallback( + appIdleManager._timerCallback, + appIdleManager._timerInterval, + Ci.nsITimer.TYPE_ONE_SHOT + ); + }, + + onFocus() { + appIdleManager._timer.cancel(); + if (appIdleManager._appIdle) { + appIdleManager._appIdle = false; + Services.obs.notifyObservers(null, "mail:appIdle", "back"); + } + }, +}; -- cgit v1.2.3