summaryrefslogtreecommitdiff
path: root/js/src/application.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/application.ts')
-rw-r--r--js/src/application.ts28
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)
+ }
+ })
+}