Skip to content

Instantly share code, notes, and snippets.

@autonome
Created July 13, 2015 16:50
Show Gist options
  • Save autonome/abf43ffea35fce9bad56 to your computer and use it in GitHub Desktop.
Save autonome/abf43ffea35fce9bad56 to your computer and use it in GitHub Desktop.
mozAlarms example
/* Manifest snippets */
"type": "privileged",
"permissions": {
"alarms": {
"description": "Required to schedule alarms"
}
},
"messages": [
{ "alarm": "/index.html" }
]
/* Code */
function setUpAlarm() {
// This the date to schedule the alarm
var myDate = new Date(+new Date() + 60000);
console.log('date: ', myDate)
// This is arbitrary data pass to the alarm
var data = {
foo: "bar"
}
// The "honorTimezone" string is what make the alarm honoring it
var request = navigator.mozAlarms.add(myDate, "honorTimezone", data);
request.onsuccess = function () {
console.log("The alarm has been scheduled");
};
request.onerror = function () {
console.log("An error occurred: " + this.error.name);
};
}
navigator.mozSetMessageHandler("alarm", function (alarm) {
console.log('alarm fired')
alert("alarm fired: " + JSON.stringify(alarm.data));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment