user1802143
user1802143

Reputation: 15672

chrome extension trigger alarm on boot

I have an alarm that triggers at midnight every day. It seems to me that if the user has quit chrome, the alarm will not trigger. Is there a way to trigger the alarm as soon as chrome is boot up (if the alarm didn't fire at midnight)? So to be clear, I only want to trigger on bootup if the alarm didn't fire at midnight. Here is what I have:

  chrome.alarms.create("alarm_test", {delayInMinutes: startMins, periodInMinutes: 1440} );
  chrome.alarms.onAlarm.addListener(function(alarm) {
  //do stuff
  });

Upvotes: 2

Views: 433

Answers (1)

Xan
Xan

Reputation: 77482

The logic is pretty obvious here: you should record (in, say, chrome.storage.local) the timestamp of last successful alarm execution.

Then, on extension initialization, see if the timestamp is over 1 day old. In that case, an alarm was missed and you should execute whatever it was supposed to run.

Upvotes: 3

Related Questions