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

@ -0,0 +1,94 @@
import { GameflowHooks } from "../hooks/app";
import { PluginContextType, PluginDescriptionType, PluginType } from "../../types/typesc.schema";
import { config } from "../app";
export class PluginManager
{
hooks = new GameflowHooks();
plugins: Record<string, {
enabled: boolean,
loaded: boolean,
plugin: PluginType;
description: PluginDescriptionType,
source: PluginSourceType;
}> = {};
async register (plugin: PluginType, description: PluginDescriptionType, source: PluginSourceType)
{
try
{
if (this.plugins[description.name])
{
console.error("Plugin with name", description.name, "already registered");
}
else
{
if (plugin.setup) await plugin.setup();
this.plugins[description.name] = {
enabled: !config.get('disabledPlugins').includes(description.name),
loaded: false, plugin: plugin,
source: source,
description: description
};
this.reload(description.name);
console.log("Plugin", description.name, "registered");
}
}
catch (error)
{
console.log("Error While Registering plugin");
console.error(error);
};
}
private reload (name: string)
{
const plugin = this.plugins[name];
if (plugin)
{
const ctx: PluginContextType = { hooks: this.hooks };
if (plugin.loaded)
{
plugin.plugin.onBeforeReload?.(ctx);
plugin.loaded = false;
}
try
{
if (plugin.enabled)
{
plugin.plugin.load(ctx);
plugin.loaded = true;
}
} catch (error)
{
console.log("Error for plugin", plugin.description.name, "while loading");
console.error(error);
}
}
}
reloadAll ()
{
this.hooks = new GameflowHooks();
Object.keys(this.plugins).forEach(id => this.reload(id));
}
async cleanup ()
{
await Promise.all(Object.values(this.plugins).filter(p => p.loaded && p.plugin.cleanup).map(async p =>
{
try
{
await p.plugin.cleanup!();
} catch (error)
{
console.log("Error for plugin", p.description.name, "while cleaning up");
console.error(error);
}
}));
}
}