1

I have a Chrome kiosk app that basically just uses webview to allow someone to browse through a catalog.

I found the chrome.idle API, and believe I understand how to set idle time and query if the device is idle, but can I have it restart the application when the state changes to idle or at least navigate back to a set URL?

The end goal is to have the catalog reset itself for the next user after being left idle for a set period of time.

https://developer.chrome.com/apps/idle

TOWEN
  • 13
  • 4
  • What exactly you don't understand about the API? The documentation is quite good about it. – Xan Feb 24 '15 at 21:31
  • Sorry, the documentation might be good but this is all relatively new to me. I haven't been able to find a method to restart the application which is ideally what I'd like to accomplish. Can I just do this to restart after 120 seconds with a listener? `chrome.idle.queryState(120, function(state) { if (state == "idle") { RESTART } });` – TOWEN Feb 24 '15 at 21:57

1 Answers1

1

Well, the documentation is pretty clear..

First, you need to declare in the manifest that you want to use this API, as it needs a permission.

"permissions" : ["idle"],

You could go with a poll-based approach as you suggested, but why? There's an event provided. So, we go on to use that.

You need to inform Chrome how long an interval without user input you consider an idle state.

chrome.idle.setDetectionInterval(120); // 120 seconds

Lastly, you need to react to a change to an idle state.

chrome.idle.onStateChanged.addListener(function(newState) {
  if(newState == "idle") {
    // Reset the state as you wish
  }
});
Xan
  • 74,770
  • 16
  • 179
  • 206
  • Thanks, this makes sense over my method and I just found the chrome.runtime.reload() function. I'm in business! – TOWEN Feb 24 '15 at 22:14
  • chrome.runtime.reload() is a very harsh method, but probably works. Consider just somehow resetting state of the window (navigating the webview to a URL and clearing browsing data, perhaps) – Xan Feb 24 '15 at 22:16