mohamedmansour / prayer-times-extension

Under Development: Prayer Time Calculation based on Geolocation for Chromium and Firefox
https://chrome.google.com/webstore/detail/ndmbeogingkjkmmkoomnigifmpajmbkc
64 stars 23 forks source link

Implement Non Persistent Background Pages #21

Closed mohamedmansour closed 3 years ago

mohamedmansour commented 6 years ago

Non-persistent extensions do not always run in the background, and do not take the system resources all the time. The catch, however, is that they should follow an event-driven model. For Prayer Times, I think the only important event is the time change: It should wake up every minute, update the timestamp on its icon, show a notification if needed, and go back to sleep.

/via @msdousti

mohamedmansour commented 6 years ago

This would be the API to do this from: chrome.alarms

https://developer.chrome.com/extensions/alarms

So the way we can implement it for prayers would be:

  1. Set persistent page to false
  2. Query for next prayer time
  3. Set alarm for next prayer time
  4. Add listener to chrome.alarms when activated
  5. Once activated, get the current time, and verify if it is time to pray.
  6. If it is time to pray, then set the next alarm
  7. If it isn't time to pray, get the next prayer time, and set it

This will improve performance for Chrome so that it wont waste battery.