[gnome-builder/ebassi/js-template] templates: Refresh the GNOME JavaScript project




commit 43f4cbe6c5a9d31d90fbde4dca44365c0d8c0d25
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Mar 1 11:28:12 2022 +0000

    templates: Refresh the GNOME JavaScript project
    
    The JavaScript template is completely different from the templates for
    other languages, which makes it harder to document.
    
    Let's make it easier to transfer knowledge by having templates with a
    similar structure.

 .../resources/src/main-gtk4.js.tmpl                | 70 ++++++++++++----------
 1 file changed, 37 insertions(+), 33 deletions(-)
---
diff --git a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl 
b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
index d1a3feeb6..87e640b5f 100644
--- a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
@@ -11,43 +11,47 @@ import { {{PreFix}}Window } from './window.js';
 pkg.initGettext();
 pkg.initFormat();
 
-export function main(argv) {
-    const application = new {{if is_adwaita}}Adw{{else}}Gtk{{end}}.Application({
-        application_id: '{{appid}}',
-        flags: Gio.ApplicationFlags.FLAGS_NONE,
-    });
-
-    const quit_action = new Gio.SimpleAction({name: 'quit'});
-    quit_action.connect('activate', action => {
-      application.quit();
-    });
-    application.add_action(quit_action);
-    application.set_accels_for_action('app.quit', ["<primary>q"]);
-
-    const show_about_action = new Gio.SimpleAction({name: 'about'});
-    show_about_action.connect('activate', action => {
-      let aboutParams = {
-        authors: [
-          '{{author}}'
-        ],
-        version: '{{project_version}}',
-        program_name: '{{name}}',
-        transient_for: application.activeWindow,
-        modal: true
-      };
-      const aboutDialog = new Gtk.AboutDialog(aboutParams);
-      aboutDialog.show();
-    });
-    application.add_action(show_about_action);
-
-    application.connect('activate', app => {
-        let activeWindow = app.activeWindow;
+export const {{PreFix}}Application = GObject.registerClass({
+    GTypeName: '{{PreFix}}Application',
+}, class {{PreFix}}Application extends {{if is_adwaita}}Adw{{else}}Gtk{{end}.Application {
+    _init() {
+        super._init({application_id: '{{appid}}', flags: Gio.ApplicationFlags.FLAGS_NONE});
+
+        const quit_action = new Gio.SimpleAction({name: 'quit'});
+        quit_action.connect('activate', action => {
+            this.quit();
+        });
+        this.add_action(quit_action);
+        this.set_accels_for_action('app.quit', ["<primary>q"]);
+
+        const show_about_action = new Gio.SimpleAction({name: 'about'});
+        show_about_action.connect('activate', action => {
+            let aboutParams = {
+                authors: [
+                    '{{author}}'
+                ],
+                version: '{{project_version}}',
+                program_name: '{{name}}',
+                transient_for: this.activeWindow,
+                modal: true,
+            };
+            const aboutDialog = new Gtk.AboutDialog(aboutParams);
+            aboutDialog.show();
+        });
+        this.add_action(show_about_action);
+    }
+
+    vfunc_activate() {
+        let activeWindow = this.activeWindow
 
         if (!activeWindow)
-            activeWindow = new {{PreFix}}Window(app);
+            activeWindow = new {{Prefix}}Window(this);
 
         activeWindow.present();
-    });
+    }
+});
 
+export function main(argv) {
+    const application = new {{prefix}}Application()
     return application.run(argv);
 }


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