Stop watching gelocation if inacitve for a given time.

This commit is contained in:
Yuan Xulei 2015-01-06 16:55:12 +08:00
Родитель 07b7649de8
Коммит c52b03e6e5
1 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -456,7 +456,13 @@ DumbPipe.registerOpener("locationprovider", function(message, sender) {
var id = -1;
var waitForData = false;
// Used to stop watching geolocation if it hasn't been accessed for a given
// time period.
var clearWatchInterval = -1;
var lastVisited = 0;
function watchPosition() {
lastVisited = Date.now();
if (id !== -1) {
return;
}
@ -487,12 +493,20 @@ DumbPipe.registerOpener("locationprovider", function(message, sender) {
timeout: 2000,
maximumAge: 0
});
clearWatchInterval = setInterval(function() {
// Stop watching after being inactive for 30s to save power.
if (Date.now() - lastVisited > 30 * 1000) {
clearWatch();
}
}, 10000);
}
function clearWatch() {
if (id === -1) {
return;
}
clearInterval(clearWatchInterval);
clearWatchInterval = -1;
navigator.geolocation.clearWatch(id);
id = -1;
}