Local history for scrubbing.

This commit is contained in:
Patrick Fic
2026-02-25 10:50:46 -08:00
parent e97f644373
commit 4915e05ac9
15 changed files with 1413 additions and 479 deletions

View File

@@ -23,6 +23,11 @@ import {
ipcMainHandleAuthStateChanged,
ipMainHandleResetPassword,
} from "./ipcMainHandler.user";
import {
ScrubHistoryClearAll,
ScrubHistoryDeleteJob,
ScrubHistoryGetAll,
} from "./ipcMainHandler.scrubHistory";
// Log all IPC messages and their payloads
const logIpcMessages = (): void => {
@@ -56,6 +61,11 @@ ipcMain.on(ipcTypes.toMain.test, () =>
ipcMain.on(ipcTypes.toMain.authStateChanged, ipcMainHandleAuthStateChanged);
ipcMain.on(ipcTypes.toMain.user.resetPassword, ipMainHandleResetPassword);
// Scrub History Handlers
ipcMain.handle(ipcTypes.toMain.scrubHistory.getAll, ScrubHistoryGetAll);
ipcMain.handle(ipcTypes.toMain.scrubHistory.deleteJob, ScrubHistoryDeleteJob);
ipcMain.handle(ipcTypes.toMain.scrubHistory.clearAll, ScrubHistoryClearAll);
// Add debug handlers if in development
if (import.meta.env.DEV) {
log.debug("[IPC Debug Functions] Adding Debug Handlers");

View File

@@ -0,0 +1,67 @@
import { BrowserWindow } from "electron";
import log from "electron-log/main";
import ipcTypes from "../../util/ipcTypes.json";
import {
clearScrubHistory,
deleteScrubHistoryJob,
getScrubHistory,
getScrubHistoryPage,
} from "../db/scrub-history-db";
export async function ScrubHistoryGetAll(
_event: Electron.IpcMainInvokeEvent,
params?: { page?: number; pageSize?: number },
): Promise<
ReturnType<typeof getScrubHistory> | ReturnType<typeof getScrubHistoryPage>
> {
try {
if (
params &&
(params.page !== undefined || params.pageSize !== undefined)
) {
return getScrubHistoryPage({
page: params.page ?? 1,
pageSize: params.pageSize ?? 10,
});
}
return getScrubHistory();
} catch (error) {
log.error("[ScrubHistoryGetAll] failed", error);
return [];
}
}
function notifyHistoryUpdated(): void {
const mainWindow = BrowserWindow.getAllWindows()[0];
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send(ipcTypes.toRenderer.scrub.historyUpdated);
}
}
export async function ScrubHistoryDeleteJob(
_event: Electron.IpcMainInvokeEvent,
jobId: string,
): Promise<{ ok: boolean; deletedJobs: number }> {
try {
const { deletedJobs } = deleteScrubHistoryJob(jobId);
if (deletedJobs > 0) notifyHistoryUpdated();
return { ok: true, deletedJobs };
} catch (error) {
log.error("[ScrubHistoryDeleteJob] failed", error);
return { ok: false, deletedJobs: 0 };
}
}
export async function ScrubHistoryClearAll(): Promise<{
ok: boolean;
clearedJobs: number;
}> {
try {
const { clearedJobs } = clearScrubHistory();
if (clearedJobs > 0) notifyHistoryUpdated();
return { ok: true, clearedJobs };
} catch (error) {
log.error("[ScrubHistoryClearAll] failed", error);
return { ok: false, clearedJobs: 0 };
}
}