feat First implementation of plugins system

feat: Added PCSX2 integration
feat: Revamped UI a bit made it look better on light mode
This commit is contained in:
Simeon Radivoev 2026-03-25 21:51:10 +02:00
parent d85268fad7
commit a78e75335f
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
95 changed files with 2639 additions and 1259 deletions

View file

@ -1,5 +1,5 @@
import Elysia from "elysia";
import z, { _ZodType, ZodAny, ZodObject, ZodTypeAny } from "zod";
import z, { _ZodType } from "zod";
import { taskQueue } from "../app";
import { LoginJob } from "./login-job";
import TwitchLoginJob from "./twitch-login-job";
@ -7,22 +7,27 @@ import UpdateStoreJob from "./update-store";
import { EmulatorDownloadJob } from "./emulator-download-job";
import { getErrorMessage } from "@/bun/utils";
import { IJob } from "../task-queue";
import { LaunchGameJob } from "./launch-game-job";
import { BiosDownloadJob } from "./bios-download-job";
import { InstallJob } from "./install-job";
function registerJob<
const Path extends string,
const Schema extends ZodTypeAny,
const Schema extends z.ZodTypeAny,
const Query extends z.ZodTypeAny,
const States extends string,
T extends IJob<z.infer<Schema>, States>
> (_job: { id: Path; dataSchema: Schema; } & (new (...args: any[]) => T))
> (_job: { id: Path; dataSchema: Schema; query?: (q: any) => string; } & (new (...args: any[]) => T))
{
return new Elysia().ws(_job.id, {
body: z.discriminatedUnion('type', [
z.object({ type: z.literal('cancel') })
]),
query: z.record(z.string(), z.any()),
response: z.discriminatedUnion('type', [
z.object({
type: z.literal(['data', 'started', 'progress']),
status: z.string(),
state: z.string().optional(),
progress: z.number(),
data: _job.dataSchema
}),
@ -31,44 +36,45 @@ function registerJob<
]),
open (ws)
{
const job = taskQueue.findJob(_job.id, _job);
const jobId = (_job.query ? _job.query(ws.data.query) : _job.id);
const job = taskQueue.findJob(jobId, _job);
if (job)
{
ws.send({ type: 'data', status: job.status, progress: job.progress, data: job.job.exposeData?.() });
ws.send({ type: 'data', state: job.state, progress: job.progress, data: job.job.exposeData?.() });
}
(ws.data as any).cleanup = [
taskQueue.on('started', ({ id, job }) =>
{
if (id === _job.id)
if (id === jobId)
{
ws.send({ type: 'started', status: job.status, progress: job.progress, data: job.job.exposeData?.() });
ws.send({ type: 'started', state: job.state, progress: job.progress, data: job.job.exposeData?.() });
}
}),
taskQueue.on('progress', ({ id, job }) =>
{
if (id === _job.id)
if (id === jobId)
{
ws.send({ type: 'started', status: job.status, progress: job.progress, data: job.job.exposeData?.() });
ws.send({ type: 'progress', state: job.state, progress: job.progress, data: job.job.exposeData?.() });
}
}),
taskQueue.on('completed', ({ id, job }) =>
{
if (id === _job.id)
if (id === jobId)
{
ws.send({ type: 'completed', data: job.job.exposeData?.() });
}
}),
taskQueue.on('ended', ({ id, job }) =>
{
if (id === _job.id)
if (id === jobId)
{
ws.send({ type: 'ended', data: job.job.exposeData?.() });
}
}),
taskQueue.on('error', ({ id, error }) =>
{
if (id === _job.id)
if (id === jobId)
{
ws.send({ type: 'error', error: getErrorMessage(error) });
}
@ -83,7 +89,8 @@ function registerJob<
{
if (message.type === 'cancel')
{
taskQueue.findJob(_job.id, _job)?.abort('cancel');
const jobId = (_job.query ? _job.query(this.query) : _job.id);
taskQueue.findJob(jobId, _job)?.abort('cancel');
}
},
});
@ -93,4 +100,7 @@ export const jobs = new Elysia({ prefix: '/api/jobs' })
.use(registerJob(LoginJob))
.use(registerJob(TwitchLoginJob))
.use(registerJob(UpdateStoreJob))
.use(registerJob(LaunchGameJob))
.use(registerJob(BiosDownloadJob))
.use(registerJob(InstallJob))
.use(registerJob(EmulatorDownloadJob));