MCPcopy Create free account
hub / github.com/MALSync/MALSync / listSyncInit

Function listSyncInit

src/background/listSync.ts:4–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { KeepAlive } from './keepAlive';
3
4export 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}

Callers 1

serviceworker.tsFile · 0.90

Calls 8

startMethod · 0.95
stopMethod · 0.95
clearMethod · 0.80
syncMethod · 0.80
getMethod · 0.65
addListenerMethod · 0.65
setMethod · 0.65
initMethod · 0.45

Tested by

no test coverage detected