WebAPI/IdleAPI: Difference between revisions

Line 2: Line 2:


  partial interface Navigator {
  partial interface Navigator {
   readonly attribute boolean mozUserIdle;
   void addIdleObserver(IdleObserver);
  void removeIdleObserver(IdleObserver);
  };
  };
   
   
  partial interface Window {
  [NoInterfaceObject]
   attribute Function onmozuseridle;
interface IdleObserver {
   attribute Function onmozuseractive;
  attribute long time; // seconds
   attribute Function onidle;
   attribute Function onactive;
  };
  };


When the user has remained inactive for a period of time we schedule a task to set mozUserIdle to true and fire a "mozuseridle" event on the window (this matches the online/offline events).
Using this APi would look something like:


When the user becomes active again, we set mozUserIdle to false and fires a "mozuseractive" event on the window. Note that this happens *before* the mouse/keyboard/touch event which caused the user to become active.
navigator.addIdleObserver({ time: 4, onidle: myIdleHandler, onactive: myActiveHandler});
 
This will call the myIdleHandler function once the user has been inactive for 4 seconds. Once the user goes active again we'd call the myActiveHandler function. You can of course use any means of producing the object passed to the function, such as:
 
navigator.addIdleObserver(new WidgetUpdateThingy(...));
navigator.addIdleObserver(getIdleObserver());


== Security/Privacy considerations ==
== Security/Privacy considerations ==
Confirmed users
716

edits