2025-12-11 10:40:55 +01:00
|
|
|
/*
|
2026-01-12 15:00:36 +01:00
|
|
|
* Copyright (c) 2026 by Christian Kellner.
|
2025-12-11 10:40:55 +01:00
|
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-13 17:06:18 +02:00
|
|
|
import cron from 'node-cron';
|
2025-12-09 13:56:46 +01:00
|
|
|
import { inDevMode } from '../../utils.js';
|
2025-09-22 09:57:50 +02:00
|
|
|
import { trackMainEvent } from '../tracking/Tracker.js';
|
2025-12-09 13:56:46 +01:00
|
|
|
import { getSettings } from '../storage/settingsStorage.js';
|
2025-09-13 17:06:18 +02:00
|
|
|
|
|
|
|
|
async function runTask() {
|
2025-12-09 13:56:46 +01:00
|
|
|
const settings = await getSettings();
|
2025-09-13 17:06:18 +02:00
|
|
|
//make sure to only send tracking events if the user gave us the green light and we are not in dev mode
|
2025-12-09 13:56:46 +01:00
|
|
|
if (settings.analyticsEnabled && !inDevMode()) {
|
2025-09-13 17:06:18 +02:00
|
|
|
await trackMainEvent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function initTrackerCron() {
|
|
|
|
|
//run directly on start
|
|
|
|
|
await runTask();
|
|
|
|
|
// then every 6 hours
|
|
|
|
|
cron.schedule('0 */6 * * *', runTask);
|
|
|
|
|
}
|