summaryrefslogtreecommitdiff
path: root/js/node/application.ts
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-05-19 02:39:53 +0200
committerAylur <[email protected]>2024-05-19 02:39:53 +0200
commit1425b396b08f0e91d45bbd0f92b1309115c7c870 (patch)
tree8af1a899a14d8a01a9ef50e248c077b48aed25bc /js/node/application.ts
init 0.1.0
Diffstat (limited to 'js/node/application.ts')
-rw-r--r--js/node/application.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/js/node/application.ts b/js/node/application.ts
new file mode 100644
index 0000000..875c1c8
--- /dev/null
+++ b/js/node/application.ts
@@ -0,0 +1,51 @@
+import gi from "node-gtk"
+import { RequestHandler, Config, runJS } from "../src/application.js"
+const Astal = gi.require("Astal", "0.1")
+
+class AstalJS extends Astal.Application {
+ static GTypeName = "AstalJS"
+ static { gi.registerClass(this) }
+
+ eval = runJS
+ requestHandler?: RequestHandler
+
+ vfunc_response(msg: string, conn: any): void {
+ if (typeof this.requestHandler === "function") {
+ this.requestHandler(msg, response => {
+ Astal.writeSock(conn, response, (_, res) =>
+ Astal.writeSockFinish(res),
+ )
+ })
+ } else {
+ // @ts-expect-error missing type
+ super.vfunc_response(msg, conn)
+ }
+ }
+
+ start(
+ { requestHandler, css, ...cfg }: Omit<Config, "hold"> = {},
+ callback?: (args: string[]) => any,
+ ) {
+ Object.assign(this, cfg)
+
+ this.requestHandler = requestHandler
+ this.on("activate", () => {
+ callback?.(process.argv)
+ })
+
+ if (!this.acquireSocket()) {
+ console.error(`Astal instance "${this.instanceName}" already running`)
+ process.exit()
+ }
+
+ if (css)
+ this.applyCss(css, false)
+
+ // FIXME: promises never resolve
+ // https://github.com/romgrk/node-gtk/issues/121
+ // https://gitlab.gnome.org/GNOME/gjs/-/issues/468
+ App.run([])
+ }
+}
+
+export const App = new AstalJS