From 1425b396b08f0e91d45bbd0f92b1309115c7c870 Mon Sep 17 00:00:00 2001 From: Aylur Date: Sun, 19 May 2024 02:39:53 +0200 Subject: init 0.1.0 --- js/src/application.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 js/src/application.ts (limited to 'js/src/application.ts') diff --git a/js/src/application.ts b/js/src/application.ts new file mode 100644 index 0000000..10f840e --- /dev/null +++ b/js/src/application.ts @@ -0,0 +1,28 @@ +export type RequestHandler = { + (request: string, res: (response: string) => void): void +} + +export type Config = Partial<{ + instanceName: string + gtkTheme: string + iconTheme: string + cursorTheme: string + css: string + requestHandler: RequestHandler + hold: boolean +}> + +export function runJS(body: string): Promise { + return new Promise((res, rej) => { + try { + const fn = Function(`return (async function() { + ${body.includes(";") ? body : `return ${body};`} + })`) + fn()() + .then(res) + .catch(rej) + } catch (error) { + rej(error) + } + }) +} -- cgit v1.2.3