Skip to content

Commit

Permalink
Promisify: Fix #211 and bump version 4.0.0-beta.18
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpLink committed Nov 5, 2024
1 parent 8de2706 commit d3644fd
Show file tree
Hide file tree
Showing 39 changed files with 58 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/adw-1-hello/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/adw-1-hello-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Typescript hello-world example using Libadwaita",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/cairo-surfaces-tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/cairo-surfaces-tsc",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple cairo-surfaces GJS example",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/console-tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/console-tsc",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple console example",
"type": "module",
"private": true,
Expand Down
15 changes: 14 additions & 1 deletion examples/gio-2-async/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ import Gio from 'gi://Gio'

// Example demonstrating promisified async file operations

// Promisify Gio.File.enumerate_children_async and Gio.FileEnumerator.next_files_async
// Promisify Gio.File operations
Gio._promisify(Gio.File.prototype, 'enumerate_children_async', 'enumerate_children_finish')
Gio._promisify(Gio.FileEnumerator.prototype, 'next_files_async', 'next_files_finish')
Gio._promisify(Gio.File.prototype, 'load_contents_async', 'load_contents_finish')

async function main() {
try {
const dir = Gio.File.new_for_path('.')

// Test load_contents_async behavior
console.log('\nTesting load_contents_async:')
const thisFile = Gio.File.new_for_path('main.ts')
const contents = await thisFile.load_contents_async(null)
// contents is [Uint8Array, string], not [boolean, Uint8Array, string]
console.log('Number of returned items:', contents.length)
console.log(
'Types of returned items:',
contents.map((item) => typeof item),
)
console.log('Content preview:', new TextDecoder().decode(contents[0]).slice(0, 50))

// List directory contents asynchronously
const enumerator = await dir.enumerate_children_async(
'standard::*',
Expand Down
2 changes: 1 addition & 1 deletion examples/gio-2-async/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gio-2-async",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Example demonstrating promisified GIO async operations",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gio-2-cat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gio-2-cat-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 3 example app that shows how to use Gio-2.0 to read a file from the local file system",
"main": "index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion examples/gio-2-dbus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gio-2-dbus-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "GJS example showing how to build a DBus server/client",
"main": "index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion examples/gio-2-list-model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gio-2-list-model-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "An example of implementing the GListModel interface in GJS",
"main": "index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion examples/glib-2-spawn-command/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/glib-2-spawn-command-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/glib-2-variant/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/glib-2-variant-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "ts-for-gir GVariant example based on https://gjs.guide/guides/glib/gvariant.html",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-browser-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"type": "module",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-builder-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"type": "module",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-calc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-calc-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 3 calculator example app",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-clutter-tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-clutter-tsc",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS GTK+3 Clutter example app",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-editor-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"type": "module",
"targets": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-hello-2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-hello-2-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 3 example app to demonstrate how you can connect to Gtk signals",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-hello/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-hello-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"type": "module",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-template/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-template-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 3 example app to demonstrate how you can use .ui template XML files",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-3-webkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-3-webkit-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 3 example app to demonstrate how you can use WebKit2",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-4-application/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-4-application-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 4 example app to demonstrate how you can use and extend Gtk.Application",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-4-custom-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gjs-gtk-4-custom-widget-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "This example shows the usage of custom widgets and virtual functions in GJS",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-4-gettext/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-4-gettext-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 3 example app that shows how you can translate strings with gettext",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-4-list-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-4-list-store-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "It takes the hassle away from building Gtk4 application in Python So you can create a cool application, without all the boilerplate code",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-4-template-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-4-template-esbuild",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files over GJS itself",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-4-template-tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-4-template-tsc",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files over GJS itself",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gtk-4-template-vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/gtk-4-template-vite",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files over the Vite bundler",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/pkg-tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/pkg-tsc",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple pkg GJS example",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/run-async/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/run-async-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 3 example app that shows how you can translate strings with gettext",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/soup-3-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/soup-3-http-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "GJS example showing how to build a http server/client using Soap 3",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/soup-3-websocket/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/soup-3-websocket-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Soup 3 example app to demonstrate how you can use WebSockets",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/timers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir-example/timers-example",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-for-gir",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Typescript .d.ts generator from GIR for gjs",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir/cli",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "TypeScript type definition generator for GObject introspection GIR files",
"module": "lib/index.js",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir/generator-base",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Base generator for ts-for-gir",
"module": "lib/index.js",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-html-doc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir/generator-html-doc",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "HTML Documentation generator for ts-for-gir",
"module": "lib/index.js",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir/generator-typescript",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "TypeScript type definition generator for ts-for-gir",
"module": "lib/index.js",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ts-for-gir/lib",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Typescript .d.ts generator from GIR for gjs",
"module": "lib/index.js",
"main": "lib/index.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/lib/src/gir/promisify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ function createAsyncReturn(async_res: IntrospectedClassFunction | IntrospectedCo
return new PromiseType(output_parameters[0].type);
}

// Special case: If return type is boolean and we have multiple output parameters,
// GJS drops the boolean from the tuple (as it's used for error handling)
if (return_type.equals(BooleanType) && output_parameters.length > 0) {
const [firstParam, ...restParams] = output_parameters;
return new PromiseType(new TupleType(firstParam.type, ...restParams.map(p => p.type)));
}

// Otherwise, return a tuple of [return_value, ...output_parameters]
return new PromiseType(new TupleType(return_type, ...output_parameters.map(p => p.type)));
}
Expand Down
2 changes: 1 addition & 1 deletion types
Submodule types updated 1198 files

0 comments on commit d3644fd

Please sign in to comment.