mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-09-25 01:20:55 +00:00
feat: initial plugin support
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import type { PluginAPI } from "./types";
|
||||
export class PluginSandbox {
|
||||
static evaluate(api: PluginAPI, code: string): void {
|
||||
const fn = new Function("api", code);
|
||||
fn(api);
|
||||
}
|
||||
|
||||
static evaluateAsync(api: PluginAPI, code: string): Promise<void> {
|
||||
try {
|
||||
const asyncFn = new Function("api", `return (async () => { ${code} })()`);
|
||||
return Promise.resolve(asyncFn(api));
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user