[gnome-builder] templates: Add GTK4 JS template
- From: Günther Wagner <gwagner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] templates: Add GTK4 JS template
- Date: Sun, 30 Jan 2022 23:03:33 +0000 (UTC)
commit e3289c3b4aded0c5d693f9a6663464dd19b44c90
Author: Florian Müllner <fmuellner gnome org>
Date: Sun Jan 30 19:03:52 2022 +0100
templates: Add GTK4 JS template
Other than the GtkBuilder template, it's identical with the GTK3
version except for the imported GTK version :-)
.../meson-templates/meson-templates.gresource.xml | 1 +
src/plugins/meson-templates/meson_templates.py | 4 ++--
.../resources/src/main-gtk4.js.tmpl | 27 ++++++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/meson-templates/meson-templates.gresource.xml
b/src/plugins/meson-templates/meson-templates.gresource.xml
index adac6ef63..12a2d27b3 100644
--- a/src/plugins/meson-templates/meson-templates.gresource.xml
+++ b/src/plugins/meson-templates/meson-templates.gresource.xml
@@ -25,6 +25,7 @@
<file compressed="true">resources/src/meson-c-vala.build</file>
<file compressed="true">resources/src/meson-empty.build</file>
<file compressed="true">resources/src/main.js.tmpl</file>
+ <file compressed="true">resources/src/main-gtk4.js.tmpl</file>
<file compressed="true">resources/src/main.c</file>
<file compressed="true">resources/src/main-gtk4.c</file>
<file compressed="true">resources/src/main-cli.c</file>
diff --git a/src/plugins/meson-templates/meson_templates.py b/src/plugins/meson-templates/meson_templates.py
index 4d5483578..794408f4d 100644
--- a/src/plugins/meson-templates/meson_templates.py
+++ b/src/plugins/meson-templates/meson_templates.py
@@ -330,7 +330,7 @@ class GnomeGTK4ProjectTemplate(MesonTemplate):
_('GNOME Application'),
'pattern-gnome',
_('Create a GNOME application with GTK 4'),
- ['C', 'Rust', 'Python', 'Vala'],
+ ['C', 'JavaScript', 'Rust', 'Python', 'Vala'],
0
)
@@ -377,7 +377,7 @@ class GnomeGTK4ProjectTemplate(MesonTemplate):
files['resources/src/window-gtk4.vala'] = 'src/window.vala'
files['resources/src/application-gtk4.vala'] = 'src/application.vala'
elif self.language == 'javascript':
- files['resources/src/main.js.tmpl'] = 'src/main.js'
+ files['resources/src/main-gtk4.js.tmpl'] = 'src/main.js'
files['resources/src/hello.js.in'] = 'src/%(appid)s.in'
files['resources/src/window.js.tmpl'] = 'src/window.js'
files['resources/src/hello.src.gresource.xml'] = 'src/%(appid)s.src.gresource.xml'
diff --git a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
new file mode 100644
index 000000000..c246ec3f6
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
@@ -0,0 +1,27 @@
+{{include "license.js"}}
+
+import Gio from 'gi://Gio';
+import Gtk from 'gi://Gtk?version=4.0';
+
+import { {{PreFix}}Window } from './window.js';
+
+pkg.initGettext();
+pkg.initFormat();
+
+export function main(argv) {
+ const application = new Gtk.Application({
+ application_id: '{{appid}}',
+ flags: Gio.ApplicationFlags.FLAGS_NONE,
+ });
+
+ application.connect('activate', app => {
+ let activeWindow = app.activeWindow;
+
+ if (!activeWindow)
+ activeWindow = new {{PreFix}}Window(app);
+
+ activeWindow.present();
+ });
+
+ return application.run(argv);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]