[gnome-builder/gnome-builder-43] templates: Allow using promises in GJS template
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-43] templates: Allow using promises in GJS template
- Date: Tue, 20 Sep 2022 05:53:48 +0000 (UTC)
commit 3e7ac5af7b56f39418d0da2fae0d51e9ad843502
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]