Skip to content

Commit

Permalink
Examples: Add new runAsync example
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpLink committed Nov 27, 2023
1 parent 02d8c17 commit 71548d6
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .ts-for-gir.gtk4.rc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
environments: ['gjs', 'node'],
modules: ['Gtk-4.0'],
modules: ['Gtk-4.0', 'Adw-1.0'],
girDirectories: ['./vala-girs/gir-1.0'],
ignore: [],
ignoreVersionConflicts: true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-alias/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-packages/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ await build({
// target: firefox102 // Since GJS 1.73.2
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*', 'gettext', 'system', 'cairo'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-promisify/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ await build({
// target: firefox102 // Since GJS 1.73.2
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-types-only/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-dbus/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-list-model/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/glib-2-variant/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-3-application/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-3-calc/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-3-gettext/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-3-hello-2/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-3-template/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-3-webkit/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-4-custom-widget/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-4-list-store/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/gtk-4-template/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
18 changes: 18 additions & 0 deletions examples/gjs/run-async/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Yarn https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

!@types/
@types/gio-2.0/*
!@types/gio-2.0/package.json
@types/gjs/*
!@types/gjs/package.json
@types/glib-2.0/*
!@types/glib-2.0/package.json
@types/gobject-2.0/*
!@types/gobject-2.0/package.json
15 changes: 15 additions & 0 deletions examples/gjs/run-async/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { build } from "esbuild";

await build({
entryPoints: ['main.ts'],
outdir: 'dist',
bundle: true,
// target: "firefox60", // Since GJS 1.53.90
// target: "firefox68", // Since GJS 1.63.90
// target: "firefox78", // Since GJS 1.65.90
target: "firefox91", // Since GJS 1.71.1
// target: firefox102 // Since GJS 1.73.2
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
55 changes: 55 additions & 0 deletions examples/gjs/run-async/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2009 Red Hat, Inc.
// Based on https://gitlab.gnome.org/GNOME/gjs/-/blob/master/examples/gio-cat.js

/*
* Make sure you have a non english locale installed, for example fr_FR and run
* LANGUAGE=fr_FR gjs gettext.js
* the label should show a translation of 'Print help'
*/

import '@girs/gjs';
import '@girs/gjs/dom';
import '@girs/gio-2.0';
import '@girs/gtk-4.0';
import '@girs/adw-1';

// import Adw from "gi://Adw";
// import GLib from "gi://GLib";
import Gio from "gi://Gio";
// import Gtk from "gi://Gtk?version=4.0";

// const mainLoop = new GLib.MainLoop(null, false);
// mainLoop.runAsync().then(() => {
// log(`Exited main loop`);
// }).catch((error) => {
// logError(error);
// });

const gioApp = new Gio.Application();
gioApp.runAsync(ARGV).then((exitStatus: number) => {
log(`Exited with status: ${exitStatus}`);
}).catch((error) => {
logError(error);
});

// const gtkApp = new Gtk.Application();
// gtkApp.runAsync(ARGV).then((exitStatus: number) => {
// log(`Exited with status: ${exitStatus}`);
// }).catch((error) => {
// logError(error);
// });

// const adwApp = new Adw.Application();
// adwApp.runAsync(ARGV).then((exitStatus: number) => {
// log(`Exited with status: ${exitStatus}`);
// }).catch((error) => {
// logError(error);
// });

setTimeout(() => {
// mainLoop.quit();
gioApp.quit();
// gtkApp.quit();
// adwApp.quit();
}, 1000);
25 changes: 25 additions & 0 deletions examples/gjs/run-async/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ts-for-gir-run-async-example",
"version": "3.2.5",
"description": "Simple GJS Gtk 3 example app that shows how you can translate strings with gettext",
"main": "index.js",
"type": "module",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:app": "yarn node esbuild.js",
"build": "yarn build:app",
"start:app": "gjs -m dist/main.js main.ts",
"debug:app": "GTK_DEBUG=interactive yarn start:app",
"start": "yarn clear && yarn build && yarn start:app",
"validate": "yarn validate:app",
"validate:app": "tsc --noEmit",
"clear": "rm -rf dist @types"
},
"author": "Pascal Garber <[email protected]>",
"license": "MIT",
"devDependencies": {
"esbuild": "^0.19.5",
"typescript": "^5.2.2"
}
}
14 changes: 14 additions & 0 deletions examples/gjs/run-async/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"baseUrl": ".",
"lib": ["ESNext"],
"types": [],
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node"
},
"include": ["@girs/gjs", "@girs/gjs/ambient"],
"files": [
"main.ts",
]
}
6 changes: 6 additions & 0 deletions examples/gjs/run-async/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true
}
}
2 changes: 1 addition & 1 deletion examples/gjs/soup-3-http/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/soup-3-websocket/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/gjs/timers/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ await build({
// target: "firefox91", // Since GJS 1.71.1
format: 'esm',
// platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
2 changes: 1 addition & 1 deletion examples/node-gtk/gio-2-cat-packages/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ await build({
// target: firefox102 // Since GJS 1.73.2
format: 'cjs',
platform: 'node',
external: ['node-gtk', 'gi://*'],
external: ['node-gtk', 'gi://*', 'resource://*', 'gettext', 'system', 'cairo'],
})
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21304,6 +21304,15 @@ __metadata:
languageName: unknown
linkType: soft

"ts-for-gir-run-async-example@workspace:examples/gjs/run-async":
version: 0.0.0-use.local
resolution: "ts-for-gir-run-async-example@workspace:examples/gjs/run-async"
dependencies:
esbuild: "npm:^0.19.5"
typescript: "npm:^5.2.2"
languageName: unknown
linkType: soft

"ts-for-gir-soup-3-http-example@workspace:examples/gjs/soup-3-http":
version: 0.0.0-use.local
resolution: "ts-for-gir-soup-3-http-example@workspace:examples/gjs/soup-3-http"
Expand Down

0 comments on commit 71548d6

Please sign in to comment.