MCPcopy Index your code
hub / github.com/MALSync/MALSync / initProgressScheduler

Function initProgressScheduler

src/background/releaseProgress.ts:11–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9} from './releaseProgressUtils';
10
11export function initProgressScheduler() {
12 chrome.alarms.get('progressSync', async a => {
13 const progressInterval = parseInt(await api.settings.getAsync('progressInterval'));
14 const progressSyncLast = await api.storage.get('progressSyncLast');
15 if (!progressInterval) {
16 con.log('progressSync disabled', progressInterval);
17 if (a) chrome.alarms.clear('progressSync');
18 return;
19 }
20
21 if (typeof a !== 'undefined' && Date.now() - progressSyncLast < progressInterval * 60 * 1000) {
22 con.log('progressSync already set and on time', progressSyncLast, a);
23 return;
24 }
25
26 if (a) chrome.alarms.clear('progressSync');
27
28 con.log('Create progressSync Alarm', progressInterval, progressSyncLast);
29 chrome.alarms.create('progressSync', {
30 periodInMinutes: progressInterval,
31 when: Date.now() + 1000,
32 });
33 });
34
35 chrome.alarms.onAlarm.addListener(alarm => {
36 if (alarm.name === 'progressSync') {
37 api.storage.set('progressSyncLast', Date.now());
38 api.settings.init().then(async () => {
39 console.groupCollapsed('Progress');
40 await main();
41 console.groupEnd();
42 });
43 }
44 });
45}
46
47export async function initUserProgressScheduler() {
48 setTimeout(async () => {

Callers 1

serviceworker.tsFile · 0.90

Calls 6

clearMethod · 0.80
mainFunction · 0.70
getMethod · 0.65
addListenerMethod · 0.65
setMethod · 0.65
initMethod · 0.45

Tested by

no test coverage detected