From ca74fb7ad016f9ceee3756a973baa2d87a8aa1d6 Mon Sep 17 00:00:00 2001 From: Aylur Date: Tue, 4 Jun 2024 23:05:41 +0200 Subject: small fixes * export Gdk * flatten jsx children --- gjs/src/application.ts | 2 +- gjs/src/astalify.ts | 27 ++++++++++++++++++++------- gjs/src/imports.ts | 1 + gjs/src/jsx/jsx-runtime.ts | 7 ++----- 4 files changed, 24 insertions(+), 13 deletions(-) (limited to 'gjs/src') diff --git a/gjs/src/application.ts b/gjs/src/application.ts index 42bbb72..b42492f 100644 --- a/gjs/src/application.ts +++ b/gjs/src/application.ts @@ -1,7 +1,7 @@ import { Astal, GObject, Gio } from "./imports.js" type RequestHandler = { - (request: string, res: (response: string) => void): void + (request: string, res: (response: any) => void): void } type Config = Partial<{ diff --git a/gjs/src/astalify.ts b/gjs/src/astalify.ts index 3a613a5..4b4145c 100644 --- a/gjs/src/astalify.ts +++ b/gjs/src/astalify.ts @@ -1,5 +1,6 @@ import Binding, { kebabify, type Connectable, type Subscribable } from "./binding.js" import { Astal, Gtk } from "./imports.js" +import { execAsync } from "./process.js" export type Widget = InstanceType & { className: string @@ -97,8 +98,15 @@ function ctor(self: any, config: any, ...children: Gtk.Widget[]) { self.add(child) } - for (const [signal, callback] of onHandlers) - self.connect(signal, callback) + for (const [signal, callback] of onHandlers) { + if (typeof callback === "function") { + self.connect(signal, callback) + } + else { + self.connect(signal, () => execAsync(callback) + .then(print).catch(console.error)) + } + } if (self instanceof Gtk.Container) { if (pchildren) { @@ -172,14 +180,19 @@ type BindableProps = { [K in keyof T]: Binding> | T[K]; } +type SigHandler< + W extends { new(...args: any): Gtk.Widget }, + Args extends Array, +> = ((self: Widget, ...args: Args) => unknown) | string | string[] + export type ConstructProps< Self extends { new(...args: any[]): any }, Props = unknown, - Signals extends Record> = Record -> = { - [Key in `on${string}`]: (self: Widget) => unknown -} & Partial<{ - [sig in keyof Signals]: (self: Widget, ...args: Signals[sig]) => unknown + Signals extends Record<`on${string}`, Array> = Record<`on${string}`, any[]> +> = Partial<{ + [S in keyof Signals]: SigHandler +}> & Partial<{ + [Key in `on${string}`]: SigHandler }> & BindableProps