Skip to content

feat(napi): Win32 calls, native callbacks and message windows - #50

Merged
triniwiz merged 1 commit into
mainfrom
feat/napi-win32
Nov 9, 2026
Merged

triniwiz merged 1 commit into
mainfrom
feat/napi-win32

Conversation

@triniwiz

@triniwiz triniwiz commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

The napi engines (@nativescript/windows-napi and the standalone engine runtimes) only reached WinRT. This adds NSWinRT.win32 to them (exported as win32 from windows-napi), built on the classic engine's libffi Win32 core in runtime/src/win32.rs, which now compiles for both engines.

Calls — call, bind, define and import, as in the classic runtime:

  • pointer arguments also take an ArrayBuffer, typed array or DataView (its memory, for structs and out-parameters), a pointer object, or a BigInt.
  • null for a wstr/str parameter is a null pointer.
  • 64-bit results beyond 2^53 come back as BigInt; define also accepts { args, ret } per function.

Callbacks — win32.callback(retType, argTypes, fn) returns { pointer, release() }: a libffi closure that calls fn synchronously on the JS thread (calls from another thread are run there and waited on, as for WinRT delegates). For APIs that take a function pointer: EnumWindows, a WNDPROC, hooks.

Window messages — win32.messageWindow(listener) returns { hwnd, close() }, a hidden top-level window whose messages are delivered to listener(msg, wParam, lParam) through the UI dispatcher, so JS never runs inside the window procedure. It is the window for a tray icon's callback message, RegisterHotKey (WM_HOTKEY) and popup menus (WM_COMMAND). Being top-level rather than message-only, it also receives broadcasts such as TaskbarCreated. While open, it keeps a standalone runtime's event loop running.

The README has a tray icon + global hotkey example; test/win32-test.js covers calls, buffers, BigInt, null strings, callbacks (including a throwing one) and message delivery.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ae4adfaa-ecbf-412a-a1e8-0931a366febd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Adds NSWinRT.win32 to the napi engines (windows-napi and the standalone
runtimes), on the classic engine's libffi Win32 core:

- call/bind/define/import; pointer arguments also take buffers, pointer
  objects and BigInts, and 64-bit results beyond 2^53 are BigInts.
- callback(retType, argTypes, fn): a native function pointer calling fn.
- messageWindow(listener): a hidden window whose messages go to
  listener(msg, wParam, lParam), for tray icons, hotkeys and menus. An
  open window keeps a standalone runtime's event loop running.
@triniwiz
triniwiz merged commit 4037a89 into main Nov 9, 2026
3 checks passed
@triniwiz
triniwiz deleted the feat/napi-win32 branch November 9, 2026 03:11
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.

1 participant