@echo off
set "BL_SCRIPT_DIR=%~dp0"
set "BL_PS=%TEMP%\bl-launch-%RANDOM%.ps1"
more +7 "%~f0" > "%BL_PS%"
powershell -NoProfile -ExecutionPolicy Bypass -File "%BL_PS%" %*
del "%BL_PS%" 2>nul
exit /b
#Requires -Version 5.1
$ErrorActionPreference = "Stop"
$ScriptDir = if ($env:BL_SCRIPT_DIR) { $env:BL_SCRIPT_DIR } else { $PSScriptRoot }

# Read PORT from webadmin.conf (verbatim from service-start.ps1 lines 9-15)
$ConfFile = Join-Path $ScriptDir "webadmin.conf"
$Port = 3000
if (Test-Path -LiteralPath $ConfFile) {
    Get-Content $ConfFile | ForEach-Object {
        if ($_ -match '^PORT=(\d+)\s*$') { $Port = [int]$Matches[1] }
    }
}

# Check if port is already listening; open browser or delegate to start-https.bat
$Listening = Test-NetConnection -ComputerName localhost -Port $Port -InformationLevel Quiet
if ($Listening) {
    Start-Process "https://localhost:$Port"
} else {
    Start-Process "$ScriptDir\start-https.bat"
}
