Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure additional async functions #140

Open
swsnr opened this issue Nov 25, 2023 · 2 comments
Open

Configure additional async functions #140

swsnr opened this issue Nov 25, 2023 · 2 comments
Labels
gjs-convention Marks issues for aligning with GJS coding standards and practices

Comments

@swsnr
Copy link
Contributor

swsnr commented Nov 25, 2023

Hello,

I'm using the new async FileDialog in Gtk. Unfortunately, the heuristic ts-for-gir employs to detect async functions doesn't catch Gtk.FileDialog.open and Gtk.FileDialog.select_folder (I guess it's because they're missing the _async suffix?). To work around this issue I have to cast to convince Typescript that I do indeed get a promise back, e.g.

 const file = await (Gtk.FileDialog.new().select_folder(
        this.root as Gtk.Window,
        null,
) as unknown as Promise<Gio.File>)

That's not nice, but I understand that the introspection metadata ts-for-gir relies on currently doesn't expose any markers for async functions, so it's hard or even impossible to detect all async functions.

As an alternative, I'd be cool if we could specify additional promisified functions explicitly in configuration, e.g. mapping type names to a list of promisified function names mapped to the corresponding start and finish functions.

{
  "promisifyFunctions": {
    "Gio.FileDialog": [
      "select_open": ["select_folder", "select_folder_finish"]
    ]
  }
}

Would that be a desirable change? If so I could look into making a pull request. As far as I can see it shouldn't be too hard; GirModule.overloadPromisifiedFunctions would just need to make an extra lookup into this new config map and generate the extra overload.

@JumpLink
Copy link
Collaborator

Hi @swsnr, yes, we could do it that way 👍

@JumpLink JumpLink added the gjs-convention Marks issues for aligning with GJS coding standards and practices label Nov 27, 2023
@swsnr
Copy link
Contributor Author

swsnr commented Nov 27, 2023

Cool, I'll look into making a pull request, but might take a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gjs-convention Marks issues for aligning with GJS coding standards and practices
Projects
None yet
Development

No branches or pull requests

2 participants