diff options
author | Aylur <[email protected]> | 2024-05-19 02:39:53 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-05-19 02:39:53 +0200 |
commit | 1425b396b08f0e91d45bbd0f92b1309115c7c870 (patch) | |
tree | 8af1a899a14d8a01a9ef50e248c077b48aed25bc /js/src/application.ts |
init 0.1.0
Diffstat (limited to 'js/src/application.ts')
-rw-r--r-- | js/src/application.ts | 28 |
1 files changed, 28 insertions, 0 deletions
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<any> { + 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) + } + }) +} |