cobalt/web/src/lib/state/queen-bee/current-tasks.ts
wukko 44a99bdb3a
web/queue: add remuxing progress & general improvements
and a bunch of other stuff:
- size and percentage in queue
- indeterminate progress bar
- if libav wasm freezes, the worker kill itself
- cleaner states
- cleaner props
2025-01-25 01:25:53 +06:00

41 lines
972 B
TypeScript

import { readable, type Updater } from "svelte/store";
import type { CobaltWorkerProgress } from "$lib/types/workers";
import type { CobaltCurrentTasks, CobaltCurrentTaskItem } from "$lib/types/queen-bee";
let update: (_: Updater<CobaltCurrentTasks>) => void;
const currentTasks = readable<CobaltCurrentTasks>(
{},
(_, _update) => { update = _update }
);
export function addWorkerToQueue(workerId: string, item: CobaltCurrentTaskItem) {
update(tasks => {
tasks[workerId] = item;
return tasks;
});
}
export function removeWorkerFromQueue(id: string) {
update(tasks => {
delete tasks[id];
return tasks;
});
}
export function updateWorkerProgress(workerId: string, progress: CobaltWorkerProgress) {
update(allTasks => {
allTasks[workerId].progress = progress;
return allTasks;
});
}
export function clearQueue() {
update(() => {
return {};
});
}
export { currentTasks };