Timer API - dcobbley/capstone-e GitHub Wiki
Research timer API
Options:
Alarm API (OS API):
The Alarm API allows applications to schedule actions to be run in the future.
Here is the link to the alarm app in firefox os which includes repeating alarms: https://github.com/mozilla-b2g/gaia/blob/master/apps/clock/js/alarm.js
Example: Source: http://stackoverflow.com/questions/24632762/firefox-os-alarm-to-wake-up-closed-app
Here's some simple code that adds and responds to an alarm (from app-days-dhaka).
var request = navigator.mozAlarms.add(new Date((+new Date()) + 30000), 'ignoreTimezone', {
type: 'yolo'
});
console.log('setting to', new Date((+new Date()) + 30000) + '')
request.onsuccess = function() {
console.log('success');
}
request.onerror = function() {
console.error('err');
}
navigator.mozSetMessageHandler('alarm', function() {
console.log('alarm');
launchSelf();
});
function launchSelf() {
var request = window.navigator.mozApps.getSelf();
request.onsuccess = function() {
if (request.result) {
request.result.launch();
}
};
}
Open the app (this will set the alarm), then close the app immediately (via long press on home). After 30 seconds the app will open again automatically.
The following will probably not be useful considering we aren't always connected to web.
Window Timers (Web API):
Calls a function or executes a code snippet repeatedly, with a fixed time delay between each call to that function. Returns an intervalID