diff --git a/src/electron/backend/encoding.ts b/src/electron/backend/encoding.ts index 05cbedb..bd48e4a 100644 --- a/src/electron/backend/encoding.ts +++ b/src/electron/backend/encoding.ts @@ -83,7 +83,9 @@ function deleteEncodedScreenshots() { const frames = stmt.all() as Frame[]; for (const frame of frames) { if (!frame.imgFilename) continue; - fs.unlinkSync(path.join(getScreenshotsDir(), frame.imgFilename)); + const imgPath = path.join(getScreenshotsDir(), frame.imgFilename); + if (!fs.existsSync(imgPath)) return; + fs.unlinkSync(imgPath); const updateStmt = db.prepare(` UPDATE frame SET imgFilename = NULL WHERE id = ?; `); diff --git a/src/electron/backend/scheduler.ts b/src/electron/backend/scheduler.ts index 485d103..1344e7c 100644 --- a/src/electron/backend/scheduler.ts +++ b/src/electron/backend/scheduler.ts @@ -5,7 +5,6 @@ interface Task { id: TaskId; func: TaskFunction; interval?: number; - maxInterval?: number; lastRun?: number; nextRun?: number; isPaused: boolean; @@ -21,8 +20,6 @@ export interface TaskStatus { export class Scheduler { private tasks: Map = new Map(); private timer: NodeJS.Timeout | null = null; - private nextTickTime: number | null = null; - constructor(private readonly minTickInterval: number = 500) { this.start(); } @@ -76,16 +73,6 @@ export class Scheduler { task.nextRun = now + task.interval!; } - const isTaskReadyForMaxIntervalRun = - task.maxInterval && task.lastRun && now - task.lastRun >= task.maxInterval; - if (isTaskReadyForMaxIntervalRun) { - task.func(); - task.lastRun = now; - if (task.interval) { - task.nextRun = now + task.interval; - } - } - const isTaskNextRunEarlierThanNextTick = task.nextRun && task.nextRun < getNextTick(); if (isTaskNextRunEarlierThanNextTick) { updateNextTick(task.nextRun!); @@ -113,15 +100,12 @@ export class Scheduler { * @param id A unique string identifier for the task. * @param func The function to be executed by the task. * @param interval The interval (in milliseconds) between task executions. - * @param maxInterval The maximum time (in milliseconds) that a task can wait before being executed. - * If a task has not been executed in this amount of time, it will be executed immediately. */ - addTask(id: TaskId, func: TaskFunction, interval?: number, maxInterval?: number): void { + addTask(id: TaskId, func: TaskFunction, interval?: number): void { this.tasks.set(id, { id, func, interval, - maxInterval, isPaused: false, lastRun: undefined, nextRun: interval ? Date.now() + interval : undefined @@ -165,7 +149,7 @@ export class Scheduler { } /** - * Resume a paused task, so that it can be executed according to its interval and maxInterval. + * Resume a paused task, so that it can be executed according to its interval. * * @param id The unique string identifier for the task. */ diff --git a/src/electron/index.ts b/src/electron/index.ts index 3a64ce9..cff1b44 100644 --- a/src/electron/index.ts +++ b/src/electron/index.ts @@ -110,10 +110,10 @@ app.on("ready", () => { }); }); initDatabase().then((db) => { - scheduler.addTask("screenshot", takeScreenshot, 2000, 2000); - scheduler.addTask("check-encoding", checkFramesForEncoding, 5000, 10000); - scheduler.addTask("process-encoding", processEncodingTasks, 10000, 30000); - scheduler.addTask("delete-screenshots", deleteUnnecessaryScreenshots, 20000, 60000); + scheduler.addTask("screenshot", takeScreenshot, 2000); + scheduler.addTask("check-encoding", checkFramesForEncoding, 5000); + scheduler.addTask("process-encoding", processEncodingTasks, 10000); + scheduler.addTask("delete-screenshots", deleteUnnecessaryScreenshots, 20000); dbConnection = db; cache.put("server:dbConnection", dbConnection); });