loleaflet: configurable dimming timeout and fire event

Two timeout are now configurable.
idleTimeoutSecs, which controls when to dim because
of user inactivity, even if the tab is in focus.
outOfFocusTimeoutSecs, which controls when to dim
when the tab loses focus.

Currently they are set to 15 minutes and 30 seconds
respectively by default.

User_Idle event is now fired on dimming.

Change-Id: I894f6df44825b6814872f1c4986fab8dcd4d6cef
Reviewed-on: https://gerrit.libreoffice.org/37373
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
Ashod Nakashian 2017-05-07 11:37:51 -04:00 committed by Ashod Nakashian
parent 9798eafb8c
commit f9ee1c6150

View file

@ -18,7 +18,9 @@ L.Map = L.Evented.extend({
defaultZoom: 10,
tileWidthTwips: 3840,
tileHeightTwips: 3840,
urlPrefix: 'lool'
urlPrefix: 'lool',
idleTimeoutSecs: 15 * 60, // Dim when user is idle.
outOfFocusTimeoutSecs: 30, // Dim after switching tabs.
},
lastActiveTime: Date.now(),
@ -853,12 +855,13 @@ L.Map = L.Evented.extend({
this._doclayer && this._docLayer._onMessage('textselection:', null);
console.debug('_dim: sending userinactive');
map.fire('postMessage', {msgId: 'User_Idle'});
this._socket.sendMessage('userinactive');
},
_dimIfInactive: function () {
console.debug('_dimIfInactive: diff=' + (Date.now() - this.lastActiveTime));
if ((Date.now() - this.lastActiveTime) >= 10 * 60 * 1000) { // Dim 10 minutes after last user activity
if ((Date.now() - this.lastActiveTime) >= this.options.idleTimeoutSecs * 1000) {
this._dim();
} else {
this._startInactiveTimer();
@ -894,7 +897,7 @@ L.Map = L.Evented.extend({
var map = this;
vex.timer = setTimeout(function() {
map._dim();
}, 30 * 1000); // Dim in 30 seconds.
}, this.options.outOfFocusTimeoutSecs * 1000);
},
_onLostFocus: function () {