[gnome-builder] templates: Allow using promises in GJS template



commit c511847cbb39806e879b2461e21c860d55606d8e
Author: Sonny Piers <sonny fastmail net>
Date:   Sun Sep 18 14:48:47 2022 +0200

    templates: Allow using promises in GJS template
    
    Promises and by extension async/await is unsuable without this.
    
    See https://gitlab.gnome.org/GNOME/gjs/-/issues/468

 src/plugins/meson-templates/resources/src/hello.js.in | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/meson-templates/resources/src/hello.js.in 
b/src/plugins/meson-templates/resources/src/hello.js.in
index d9baf492e..d30dfb837 100755
--- a/src/plugins/meson-templates/resources/src/hello.js.in
+++ b/src/plugins/meson-templates/resources/src/hello.js.in
@@ -1,4 +1,8 @@
-#!@GJS@
+#!@GJS@ -m
+
+import GLib from "gi://GLib";
+import { exit } from "system";
+
 imports.package.init({
   name: "@PACKAGE_NAME@",
   version: "@PACKAGE_VERSION@",
@@ -6,6 +10,16 @@ imports.package.init({
   libdir: "@libdir@",
   datadir: "@datadir@",
 });
+
+const loop = new GLib.MainLoop(null, false);
 import("resource://@resource_path@/js/main.js")
-  .then((main) => imports.package.run(main))
+  .then((main) => {
+    GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
+      loop.quit();
+      const exitCode = imports.package.run(main);
+      exit(exitCode);
+      return GLib.SOURCE_REMOVE;
+    });
+  })
   .catch(logError);
+loop.run();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]