Skip to content

feat: add support for tauri::ipc::Channel<T> - #4

Merged
Dudude-bit merged 2 commits into
Dudude-bit:mainfrom
lukas-runge:feat/channel-support
Jun 11, 2026
Merged

Dudude-bit merged 2 commits into
Dudude-bit:mainfrom
lukas-runge:feat/channel-support

Conversation

@lukas-runge

@lukas-runge lukas-runge commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Hi @Dudude-bit,

thank you for your great work on tauri-ts-generator! 🙏

I just wanted to use Tauri Channels (see https://v2.tauri.app/develop/calling-frontend/#channels) for streaming data from the backend to the frontend and noticed that the generator does currently not support it. With @claude's help I was able to "prompt it into existence" and make it work for my application (see https://github.com/lukas-runge/luminaut). This is the resulting PR. If you want to support Channels going forward, this might be a good starting point, but keep in mind this is:

  • opinionated (as it generates a typescript API the way I would like to use it), which means it does not necessarily align with how people or you yourself would like to use it.
  • build by @claude as I am not that knowledgeable when it comes to Rust.

So please take this pr with the appropriate grain of salt. 😊

Kind regards,
@lukas-runge

Summary

Adds codegen support for tauri::ipc::Channel<T> command arguments so streaming-IPC commands can be invoked from generated TypeScript.

  • New RustType::Channel(Box<RustType>) variant; parser recognizes tauri::ipc::Channel<T> and Channel<T>; type-mapper emits Channel<T>.
  • Channel args stay in the TS signature (unlike injected types like State/Window) and are forwarded to invoke.
  • Per-command type aliases appended to types.ts:
    • single channel → <cmd>ChannelType
    • multiple channels → <cmd><Arg>ChannelType
  • Channel import added to commands.ts only when at least one command uses one.
  • New helpers.ts emitted next to commands.ts when channels are present, exporting getChannelFor<T>(onMessage?).

Test plan

  • cargo test — new tests/e2e/channels.rs covers:
    • channel import + parameter typing + forwarding to invoke
    • channel type alias in types.ts
    • helpers.ts generation when channels present, omission when absent
    • primitive inner type (Channel<String> → string)
    • mixed channel + regular args
    • multiple channels in one command (distinct alias names)
  • Manual smoke against a Tauri app using Channel<T> commands

🤖 Generated with Claude Code

@lukas-runge
lukas-runge marked this pull request as ready for review May 31, 2026 09:43
@Dudude-bit

Copy link
Copy Markdown
Owner

Hello, my friend!
I did not see your pull request, sorry!!!
Is it relevant? I will check soon
Sorry again

@lukas-runge

Copy link
Copy Markdown
Contributor Author

Hi @Dudude-bit,

no worries! 🙌

This is not relevant for the core functionality of the generator as of today but adds a feature for everyone who wants to use Tauri Channels (see https://v2.tauri.app/develop/calling-frontend/#channels) for streaming data from the backend to the frontend in their project. If you want to support Channels going forward, this might be a good starting point, but keep in mind this is generated by @claude. Also keep in mind that this is opinionated (as it generates a typescript API the way I would like to use it), which means it does not necessarily align with how people or you yourself would like to use it.

Feel free to try it out yourself or see it in action in my open source app lukas-runge/luminaut which uses this pr in production.

If you have any further questions, feel free to get back to me. 🙌

Best regards,
@lukas-runge

- alias is always <Command><Arg>ChannelType (stable when a command gains
  a second channel, follows TS naming convention)
- drop generated helpers.ts: new Channel<T>(cb) already covers it, and
  the file went stale / could clobber a user file
- fix rustfmt violation in rust_type.rs; README + CHANGELOG entries

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Dudude-bit
Dudude-bit force-pushed the feat/channel-support branch from 1ae1ed0 to fb798ff Compare June 11, 2026 13:37
@Dudude-bit

Copy link
Copy Markdown
Owner

Hi @lukas-runge, thanks a lot for the contribution — and for being upfront about how it was built. The core of the PR (the RustType::Channel variant, parsing, type mapping, signature/forwarding behavior, and the test coverage) was solid, so I took you up on the "starting point" framing and pushed a round of maintainer edits onto your branch before merging:

  • Channel type aliases are now always <Command><Arg>ChannelType (PascalCase, arg name always included) — names stay stable when a command gains a second channel, and type aliases follow the usual TS naming convention.
  • Dropped the generated helpers.ts: new Channel<T>(onMessage) from @tauri-apps/api/core already covers that use case, and a conditionally generated file came with edge cases — it would linger as a stale file after the last channel arg was removed, and could silently overwrite a user's own helpers.ts.
  • The @tauri-apps/api/core import line is now built from a list, so future conditional imports slot in cleanly.
  • rustfmt fix (CI runs cargo fmt --check), plus README and CHANGELOG entries.

Channel support will ship with the next release. Thanks again! 🙌

@Dudude-bit
Dudude-bit merged commit 05596a9 into Dudude-bit:main Jun 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants