views:

62

answers:

3

I'm currently developing a firefox extension which checks some server side XML-File on a regular basis (every 2 minutes). I want to add the following feature:

Whenever the user is inactive for X minutes the check interval is extended by a multiplicatior of Y until a limit of Z is reached. In order to do so, I need the inactivity time. Is this value (or something like it) already generated by firefox internally? If so: How can I access it from my extension? And if not: Is there a way to generated it on my own?

A: 

You can only check that a user is inactive in you browser window/tab. This can be achieved using javascript.

onbody load -> store the time in lastactivitytime ()

onmouse movement -> store the time lastactivitytime (document.onmousemove)

on keypress -> store the time lastactivitytime (document.onkeypress)

every time your interval expires check the value versus the current time.

Stop polling full stop if the window is not active onblur event

Paul Whelan
that's great for a web page, but isn't there a more cunning solution for the whole browser?
Alexander Gyoshev
A: 

You won't know if the user is active in another window. If that's okay with you, then you should attach listeners for events like mousemove, keydown, mousescroll (?) and such to bodies of every open page, and also listen for creating?closing tabs by some internal FF means. Is some of this listeners isn't triggered for X minutes, then you have your inactivity.

n1313
+2  A: 

I would expect that if you overlay browser.xul you ought to be able to hook into events at the browser level rather than mess around with individual pages. XPCOM has an Idle Service, getting at it from an extension ought to be possible.

robertc
Thank you, I think this will do the trick
Martin