@echo off
REM Chrome/Edge launch this as the native-messaging host "path". It runs the Node stdio<->bridge pump.
REM
REM Node resolution order (Chrome does NOT inherit Bridge's managed-runtime PATH, so we must NOT
REM assume `node` is on PATH on a machine with no system Node install):
REM   1. node-path.txt published by the ab-spawned bridge = the EXACT Node Bridge provisioned
REM      (system, or its portable no-UAC copy). Self-healing: the bridge rewrites it on every respawn,
REM      so a Bridge runtime upgrade never leaves us pointing at a dead node.exe.
REM   2. `node` from PATH (a system install), as a fallback.
set "NODE_EXE="
set "NPFILE=%USERPROFILE%\.adom\bridges\native-browser\node-path.txt"
if exist "%NPFILE%" set /p NODE_EXE=<"%NPFILE%"
if defined NODE_EXE if exist "%NODE_EXE%" (
  "%NODE_EXE%" "%~dp0native-host.js"
  exit /b
)
node "%~dp0native-host.js"
