()
| 2 | import { KeepAlive } from './keepAlive'; |
| 3 | |
| 4 | export function listSyncInit() { |
| 5 | chrome.alarms.get('listSync', async function (a) { |
| 6 | const listSyncLast = await api.storage.get('listSyncLast'); |
| 7 | const syncInterval = 23 * 60; |
| 8 | |
| 9 | if (typeof a !== 'undefined' && Date.now() - listSyncLast < syncInterval * 60 * 1000) { |
| 10 | con.log('listSync already set and on time', listSyncLast, a); |
| 11 | return; |
| 12 | } |
| 13 | |
| 14 | if (a) chrome.alarms.clear('listSync'); |
| 15 | |
| 16 | con.log('Create listSync Alarm', syncInterval, listSyncLast); |
| 17 | chrome.alarms.create('listSync', { |
| 18 | periodInMinutes: syncInterval, |
| 19 | when: Date.now() + 1000, |
| 20 | }); |
| 21 | }); |
| 22 | |
| 23 | chrome.alarms.onAlarm.addListener(function (alarm) { |
| 24 | if (alarm.name === 'listSync') { |
| 25 | api.storage.set('listSyncLast', Date.now()); |
| 26 | api.settings.init().then(async () => { |
| 27 | console.groupCollapsed('listSync'); |
| 28 | const alive = new KeepAlive(); |
| 29 | alive.start(); |
| 30 | |
| 31 | Sync.background.sync().finally(() => { |
| 32 | alive.stop(); |
| 33 | console.groupEnd(); |
| 34 | }); |
| 35 | }); |
| 36 | } |
| 37 | }); |
| 38 | } |
no test coverage detected