Files
luminary/windows/launcher/Luminary.ps1
T
bhursey 7cad990c8e Call the local process the local engine, not a server
Windows users read "server" as a network service and asked whether the app
phones home, even though the bundle only ever talks to 127.0.0.1. The launcher
dialogs, the help text, the Stop shortcut and the bundle README now call it the
local engine and say plainly that it is a background process on this PC.
2026-12-01 12:14:31 +00:00

676 lines
25 KiB
PowerShell

<#
Luminary launcher (PowerShell).
This is the no-toolchain launcher: it ships in every bundle and is what
Luminary.exe replaces when a Go build is available. It owns the three things
Luminary's local engine deliberately does not do for itself:
1. Pick a free loopback port and pass it as PORT.
2. Start node.exe hidden with LUMINARY_DATA outside the bundle.
3. Wait for /api/health before opening the browser.
Usage:
Luminary.ps1 start (or reuse) the local engine and open the browser
Luminary.ps1 -Stop stop the local engine started from this folder
Luminary.ps1 -Status report what is running and where the data lives
Luminary.ps1 -Verify list the files the bundle must contain
Luminary.ps1 -Repair re-download node.exe and check it against version.txt
Luminary.ps1 -Browser open a normal browser tab instead of the app window
Runtime resolution: the bundled node.exe is always preferred. If an antivirus
removed it, a system Node 24+ is used instead so the app still starts, and the
launcher says so; -Repair restores the pinned runtime.
State is kept in runtime.json next to this script; logs go to logs\ (or to
%LOCALAPPDATA%\Luminary\data\logs when the bundle is on read-only media).
#>
[CmdletBinding()]
param(
[switch]$Stop,
[switch]$Status,
[switch]$Verify,
[switch]$Repair,
[switch]$Browser
)
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$appDir = Join-Path $root 'app'
$nodeExe = Join-Path $root 'node.exe'
$entry = Join-Path $appDir 'server\index.mjs'
$uiFile = Join-Path $appDir 'dist\index.html'
$versionFile = Join-Path $root 'version.txt'
$logDir = Join-Path $root 'logs'
$runtimeFile = $null # resolved below: it moves to the data folder on read-only media
$firstPort = 8787
$lastPort = 8887
$minNodeMajor = 24
function Show-Dialog([string]$text, [string]$icon) {
try {
Add-Type -AssemblyName System.Windows.Forms
$kind = [System.Windows.Forms.MessageBoxIcon]::Information
if ($icon -eq 'Error') { $kind = [System.Windows.Forms.MessageBoxIcon]::Error }
[void][System.Windows.Forms.MessageBox]::Show($text, 'Luminary', [System.Windows.Forms.MessageBoxButtons]::OK, $kind)
} catch {
Write-Host $text
}
}
function Show-ErrorDialog([string]$text) {
# The .vbs entry point runs PowerShell hidden, so a console-only failure would
# look like nothing happened.
Show-Dialog $text 'Error'
}
function Show-Question([string]$text) {
try {
Add-Type -AssemblyName System.Windows.Forms
$answer = [System.Windows.Forms.MessageBox]::Show($text, 'Luminary', [System.Windows.Forms.MessageBoxButtons]::YesNo, [System.Windows.Forms.MessageBoxIcon]::Question)
return ($answer -eq [System.Windows.Forms.DialogResult]::Yes)
} catch {
Write-Host $text
return $false
}
}
function Get-DataDir {
if ($env:LUMINARY_DATA) { return $env:LUMINARY_DATA }
$base = $env:LOCALAPPDATA
if (-not $base) {
if ($env:USERPROFILE) {
$base = Join-Path $env:USERPROFILE 'AppData\Local'
} else {
# Neither variable is set: a stripped environment (service account, CI)
# rather than a normal desktop login. Never Join-Path a null.
$base = [System.IO.Path]::GetTempPath()
}
}
return (Join-Path $base 'Luminary\data')
}
function Read-Runtime {
if (-not (Test-Path -LiteralPath $runtimeFile)) { return $null }
try { return Get-Content -Raw -LiteralPath $runtimeFile | ConvertFrom-Json } catch { return $null }
}
# Loopback liveness probe.
#
# Invoke-WebRequest goes through WinINET, which resolves the system proxy (a PAC
# script or WPAD) before it looks at the URL. On a machine with no network that
# lookup can block for far longer than -TimeoutSec, so every probe timed out and
# the launcher killed a healthy local engine: the app "would not start" offline.
# A raw request over TCP to 127.0.0.1 uses no proxy, DNS or certificate store, so
# start-up behaves the same with or without a connection.
function Test-Health([int]$port) {
$client = $null
try {
$client = New-Object System.Net.Sockets.TcpClient
$connect = $client.ConnectAsync([System.Net.IPAddress]::Loopback, $port)
if (-not $connect.Wait(2000)) { return $false }
$client.ReceiveTimeout = 3000
$stream = $client.GetStream()
$request = [System.Text.Encoding]::ASCII.GetBytes((
"GET /api/health HTTP/1.0`r`nHost: 127.0.0.1:{0}`r`nConnection: close`r`n`r`n" -f $port))
$stream.Write($request, 0, $request.Length)
$stream.Flush()
$reader = New-Object System.IO.StreamReader($stream, [System.Text.Encoding]::ASCII)
$status = $reader.ReadLine()
return ($status -match '^HTTP/1\.[01] 200\b')
} catch {
return $false
} finally {
if ($client) { $client.Close() }
}
}
function Test-Process([int]$processId) {
try { return $null -ne (Get-Process -Id $processId -ErrorAction Stop) } catch { return $false }
}
function Test-PortFree([int]$port) {
$listener = $null
try {
$listener = New-Object System.Net.Sockets.TcpListener([System.Net.IPAddress]::Loopback, $port)
$listener.Start()
return $true
} catch {
return $false
} finally {
if ($listener) { $listener.Stop() }
}
}
function Find-Port {
for ($port = $firstPort; $port -le $lastPort; $port++) {
if (Test-PortFree $port) { return $port }
}
throw ("No free TCP port between {0} and {1}." -f $firstPort, $lastPort)
}
function Open-Browser([string]$url) {
try { Start-Process $url | Out-Null } catch { Write-Host ("Open {0} in a browser." -f $url) }
}
# Edge is part of Windows 10/11, so a chromeless app window costs no extra
# runtime. Chrome is the second choice; anything else falls back to a tab.
function Find-AppWindowBrowser {
$candidates = @()
if (${env:ProgramFiles(x86)}) {
$candidates += (Join-Path ${env:ProgramFiles(x86)} 'Microsoft\Edge\Application\msedge.exe')
}
if ($env:ProgramFiles) {
$candidates += (Join-Path $env:ProgramFiles 'Microsoft\Edge\Application\msedge.exe')
}
if ($env:LOCALAPPDATA) {
$candidates += (Join-Path $env:LOCALAPPDATA 'Microsoft\Edge\Application\msedge.exe')
$candidates += (Join-Path $env:LOCALAPPDATA 'Google\Chrome\Application\chrome.exe')
}
if ($env:ProgramFiles) {
$candidates += (Join-Path $env:ProgramFiles 'Google\Chrome\Application\chrome.exe')
}
if (${env:ProgramFiles(x86)}) {
$candidates += (Join-Path ${env:ProgramFiles(x86)} 'Google\Chrome\Application\chrome.exe')
}
foreach ($candidate in $candidates) {
if ($candidate -and (Test-Path -LiteralPath $candidate)) { return $candidate }
}
return $null
}
# --app gives a window with no tabs and no address bar, in its own profile, so
# it reads as a desktop app rather than a web page. -Browser opts out.
function Open-App([string]$url) {
if ($Browser -or $env:LUMINARY_WINDOW -eq 'browser') {
Open-Browser $url
return
}
# A native WebView2 host, when the bundle ships one, is the real app window:
# its own icon, no browser branding at all.
$native = Join-Path $root 'LuminaryWindow.exe'
if (Test-Path -LiteralPath $native) {
try {
Start-Process -FilePath $native -ArgumentList @('--url', $url) | Out-Null
return
} catch {
# fall through to the browser window
}
}
$exe = Find-AppWindowBrowser
if (-not $exe) {
Open-Browser $url
return
}
$profile = Join-Path (Get-DataDir) 'window-profile'
try {
New-Item -ItemType Directory -Force -Path $profile | Out-Null
# --no-proxy-server: the window only ever loads 127.0.0.1. A proxy or PAC
# script set on the machine must not be able to intercept (or stall) it
# when the network is down.
Start-Process -FilePath $exe -ArgumentList @(
"--app=$url",
"--user-data-dir=$profile",
'--window-size=1500,950',
'--no-first-run',
'--no-default-browser-check',
'--no-proxy-server',
'--disable-features=Translate'
) | Out-Null
} catch {
Open-Browser $url
}
}
function Get-WindowsBuild {
try {
$current = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction Stop
return [int]$current.CurrentBuild
} catch { return 0 }
}
# What a customer machine actually needs. Everything else is in the bundle:
# node.exe ships with it (and -Repair re-downloads it), libvips needs only the
# Universal C Runtime that Windows 10/11 already has, and no admin rights are
# involved. Verified against the PE imports of node.exe and libvips-42.dll.
function Test-Platform {
$problems = @()
$notes = @()
$build = Get-WindowsBuild
if ($build -gt 0 -and $build -lt 10240) {
$problems += ("Luminary needs Windows 10 or 11. This PC reports build {0}." -f $build)
}
$arch = $env:PROCESSOR_ARCHITECTURE
if ($arch -and $arch -ne 'AMD64' -and $arch -ne 'ARM64') {
$problems += ("Luminary ships a 64-bit runtime; this PC reports '{0}'." -f $arch)
} elseif ($arch -eq 'ARM64') {
$notes += 'ARM64 Windows runs the x64 runtime under emulation, so RAW decoding is slower.'
}
if ($env:SystemRoot -and -not (Test-Path -LiteralPath (Join-Path $env:SystemRoot 'System32\ucrtbase.dll'))) {
$problems += 'The Universal C Runtime is missing (Windows 8.1 without KB2999226). Install it from support.microsoft.com/help/2999226, or use Windows 10/11.'
}
# ~130 MB unpacked, plus room for catalogs and previews that grow over time.
$dataDir = Get-DataDir
$qualifier = $null
try { $qualifier = Split-Path -Qualifier $dataDir -ErrorAction Stop } catch { }
if ($qualifier) {
try {
$drive = New-Object System.IO.DriveInfo -ArgumentList $qualifier
$freeGb = [math]::Round($drive.AvailableFreeSpace / 1GB, 1)
if ($drive.AvailableFreeSpace -lt 200MB) {
$problems += ("The data drive has only {0} GB free; Luminary needs about 0.25 GB to start." -f $freeGb)
} elseif ($drive.AvailableFreeSpace -lt 2GB) {
$notes += ("Only {0} GB free on the data drive; catalogs and previews grow from there." -f $freeGb)
}
} catch { }
}
return @{ ok = ($problems.Count -eq 0); problems = $problems; notes = $notes }
}
# --- runtime resolution -------------------------------------------------------
function Read-NodePin {
$pin = @{ version = $null; sha256 = $null; size = [int64]0 }
if (-not (Test-Path -LiteralPath $versionFile)) { return $pin }
$line = Get-Content -LiteralPath $versionFile |
Where-Object { $_ -match '^node\s+v?\d+\.\d+\.\d+\s+win-x64' } |
Select-Object -First 1
if (-not $line) { return $pin }
if ($line -match '^node\s+v?(\d+\.\d+\.\d+)') { $pin.version = $Matches[1] }
if ($line -match 'sha256\s+([0-9a-f]{64})') { $pin.sha256 = $Matches[1] }
if ($line -match 'size\s+(\d+)') { $pin.size = [int64]$Matches[1] }
return $pin
}
function Get-SystemNode([string]$exe) {
if (-not $exe) { return $null }
if (-not (Test-Path -LiteralPath $exe)) { return $null }
try { $raw = & $exe '--version' 2>$null } catch { return $null }
if (-not $raw) { return $null }
$raw = "$raw".Trim()
if ($raw -notmatch '^v?(\d+)\.') { return $null }
if ([int]$Matches[1] -lt $minNodeMajor) { return $null }
return $raw
}
# The bundled runtime wins; a system Node 24+ is a fallback, never a preference.
function Resolve-Node {
if (Test-Path -LiteralPath $nodeExe) {
$info = Get-Item -LiteralPath $nodeExe
$pin = Read-NodePin
$intact = $info.Length -gt 0
# A pinned size catches a truncated file that antivirus left behind; the
# hash itself is only checked by -Verify and -Repair.
if ($intact -and $pin.size -gt 0 -and $info.Length -ne $pin.size) { $intact = $false }
if ($intact) { return @{ path = $nodeExe; version = 'bundled'; system = $false } }
}
$candidates = @()
$onPath = Get-Command node.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
if ($onPath) { $candidates += $onPath.Source }
if ($env:ProgramFiles) { $candidates += (Join-Path $env:ProgramFiles 'nodejs\node.exe') }
if (${env:ProgramFiles(x86)}) { $candidates += (Join-Path ${env:ProgramFiles(x86)} 'nodejs\node.exe') }
if ($env:LOCALAPPDATA) { $candidates += (Join-Path $env:LOCALAPPDATA 'Programs\nodejs\node.exe') }
if ($env:NVM_SYMLINK) { $candidates += (Join-Path $env:NVM_SYMLINK 'node.exe') }
$seen = @{}
foreach ($candidate in $candidates) {
if (-not $candidate) { continue }
$key = $candidate.ToLowerInvariant()
if ($seen.ContainsKey($key)) { continue }
$seen[$key] = $true
$version = Get-SystemNode $candidate
if ($version) { return @{ path = $candidate; version = $version; system = $true } }
}
return $null
}
# --- repair -------------------------------------------------------------------
function Get-PublishedHash([string]$version) {
$uri = "https://nodejs.org/dist/v$version/SHASUMS256.txt"
$text = (Invoke-WebRequest -UseBasicParsing -TimeoutSec 30 -Uri $uri).Content
foreach ($line in ($text -split "`n")) {
$parts = $line.Trim() -split '\s+'
if ($parts.Count -ge 2 -and $parts[1] -eq 'win-x64/node.exe') { return $parts[0].ToLowerInvariant() }
}
return $null
}
function Repair-Node {
$pin = Read-NodePin
if (-not $pin.version) {
throw "version.txt does not record a node version, so there is nothing to re-download. Extract the zip again instead."
}
$expected = $pin.sha256
if (-not $expected) {
Write-Host ("Fetching the published checksum for node v{0}..." -f $pin.version)
$expected = Get-PublishedHash $pin.version
}
if (-not $expected) {
throw "No SHA-256 is available for node v$($pin.version), so the download cannot be verified. Refusing to install it."
}
$url = $env:LUMINARY_NODE_URL
if (-not $url) { $url = "https://nodejs.org/dist/v$($pin.version)/win-x64/node.exe" }
Write-Host ("Downloading {0}" -f $url)
$temp = Join-Path ([System.IO.Path]::GetTempPath()) ("luminary-node-{0}.exe" -f [guid]::NewGuid().ToString('N'))
try {
Invoke-WebRequest -UseBasicParsing -TimeoutSec 600 -Uri $url -OutFile $temp
$actual = (Get-FileHash -LiteralPath $temp -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actual -ne $expected.ToLowerInvariant()) {
throw ("The downloaded node.exe does not match the expected checksum (got {0}, want {1}). Nothing was changed." -f $actual, $expected)
}
if (Test-Path -LiteralPath $nodeExe) {
try { (Get-Item -LiteralPath $nodeExe).IsReadOnly = $false } catch { }
}
Move-Item -LiteralPath $temp -Destination $nodeExe -Force
Write-Host ("node.exe restored: v{0}, sha256 {1}" -f $pin.version, $actual)
} finally {
if (Test-Path -LiteralPath $temp) { Remove-Item -LiteralPath $temp -Force -ErrorAction SilentlyContinue }
}
}
# --- bundle checks ------------------------------------------------------------
# Prints a line for every file the bundle needs and returns $true when all are
# present and non-empty. A zero-byte file is what an antivirus or a half-done
# extraction leaves behind, so it is treated as missing.
function Test-Bundle {
$ok = $true
$required = @(
@{ Name = 'app\server\index.mjs'; Path = $entry },
@{ Name = 'app\dist\index.html'; Path = $uiFile }
)
foreach ($item in $required) {
if (-not (Test-Path -LiteralPath $item.Path)) {
Write-Host (" missing {0}" -f $item.Name)
$ok = $false
} elseif ((Get-Item -LiteralPath $item.Path).Length -eq 0) {
Write-Host (" empty {0} ({1})" -f $item.Name, $item.Path)
$ok = $false
}
}
return $ok
}
function Write-BundleHelp {
$pin = Read-NodePin
Write-Host ''
Write-Host 'This folder is not a complete Luminary bundle. The usual causes:'
Write-Host ''
Write-Host ' 1. The zip was opened, not extracted. Close it, right-click the zip,'
Write-Host ' choose "Extract All...", then run Luminary.cmd (or Luminary.vbs)'
Write-Host ' from the extracted Luminary folder. A file started from inside the'
Write-Host ' zip preview is copied out on its own, without node.exe or app\.'
Write-Host ''
Write-Host ' 2. Antivirus or SmartScreen removed node.exe after extraction.'
Write-Host ' Run "Luminary.cmd -Repair" to download it again and verify it'
Write-Host ' against the checksum in version.txt.'
if ($pin.sha256) { Write-Host (' expected sha256: {0}' -f $pin.sha256) }
Write-Host ''
Write-Host ' 3. This is the source checkout, not a bundle. In the repository run'
Write-Host ' "node windows/build.mjs" and use the zip it prints.'
Write-Host ''
Write-Host 'Run "Luminary.cmd -Verify" to list every file the launcher needs.'
}
function Get-LogDir([string]$dataDir) {
try {
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
return $logDir
} catch {
# Read-only media (USB stick with the write-protect switch, a network share
# the user cannot write): keep the logs with the data instead of failing.
$fallback = Join-Path $dataDir 'logs'
New-Item -ItemType Directory -Force -Path $fallback | Out-Null
Write-Host ("Logs go to {0} (the bundle folder is not writable)." -f $fallback)
return $fallback
}
}
# The state file lives in the bundle folder so a copied bundle is self-contained.
# On read-only media (write-protected USB, Program Files for a non-admin user) it
# moves next to the data, which is always writable.
$runtimeFile = Join-Path $root 'runtime.json'
try {
$probe = Join-Path $root ('.write-test-{0}' -f [guid]::NewGuid().ToString('N'))
[System.IO.File]::WriteAllText($probe, '')
Remove-Item -LiteralPath $probe -Force
} catch {
$runtimeFile = Join-Path (Get-DataDir) 'runtime.json'
}
# --- commands -----------------------------------------------------------------
if ($Verify) {
Write-Host ("Bundle: {0}" -f $root)
$complete = Test-Bundle
$pin = Read-NodePin
if (-not (Test-Path -LiteralPath $nodeExe)) {
Write-Host ' missing node.exe'
$complete = $false
} else {
$nodeInfo = Get-Item -LiteralPath $nodeExe
if ($nodeInfo.Length -eq 0) {
Write-Host ' empty node.exe'
$complete = $false
} elseif ($pin.size -gt 0 -and $nodeInfo.Length -ne $pin.size) {
Write-Host (" damaged node.exe ({0:N0} bytes, expected {1:N0})" -f $nodeInfo.Length, $pin.size)
$complete = $false
}
}
if ($complete) {
foreach ($file in @($nodeExe, $entry, $uiFile)) {
$shown = $file.Replace($root + '\', '')
Write-Host (" ok {0} ({1:N0} bytes)" -f $shown, (Get-Item -LiteralPath $file).Length)
}
if ($pin.version) { Write-Host ("Node: v{0} (pinned)" -f $pin.version) }
Write-Host 'The bundle is complete.'
exit 0
}
Write-BundleHelp
exit 3
}
$runtime = Read-Runtime
$running = $runtime -and (Test-Process ([int]$runtime.pid))
if ($Repair) {
if ($running) {
Write-Host 'Luminary is running. Stop it first: "Luminary.cmd -Stop".'
exit 1
}
try {
Repair-Node
} catch {
Write-Host ''
Write-Host ("Repair failed: {0}" -f $_.Exception.Message)
Show-ErrorDialog ("node.exe could not be restored.`n`n" + $_.Exception.Message)
exit 1
}
Write-Host ''
if (Test-Bundle) {
Write-Host 'The bundle is complete and ready to run.'
exit 0
}
Write-BundleHelp
exit 3
}
if ($Status) {
if ($running) {
$reachable = Test-Health ([int]$runtime.port)
$state = 'not answering yet'
if ($reachable) { $state = 'ok' }
Write-Host ("Luminary is running (pid {0}) at {1}; health {2}." -f $runtime.pid, $runtime.url, $state)
} else {
Write-Host 'Luminary is not running.'
}
$platform = Test-Platform
Write-Host ("System: Windows build {0}, {1}" -f (Get-WindowsBuild), $env:PROCESSOR_ARCHITECTURE)
foreach ($note in $platform.notes) { Write-Host ("Note: {0}" -f $note) }
foreach ($problem in $platform.problems) { Write-Host ("Problem: {0}" -f $problem) }
$node = Resolve-Node
if ($node) {
if ($node.system) {
Write-Host ("Node: {0} ({1}) - bundled node.exe is missing; run -Repair" -f $node.path, $node.version)
} else {
Write-Host 'Node: bundled node.exe'
}
} else {
Write-Host 'Node: missing (run -Repair)'
}
Write-Host ("Data: {0}" -f (Get-DataDir))
exit 0
}
if ($Stop) {
if (-not $running) {
Write-Host 'Luminary is not running.'
Remove-Item -LiteralPath $runtimeFile -Force -ErrorAction SilentlyContinue
exit 0
}
& taskkill.exe /PID ([int]$runtime.pid) /T /F | Out-Null
Remove-Item -LiteralPath $runtimeFile -Force -ErrorAction SilentlyContinue
Write-Host 'Luminary stopped.'
exit 0
}
# A second double-click while the first server is still booting must wait for it,
# not start a second server on the same catalog.
if ($running) {
Write-Host 'Luminary is already starting; waiting for it to answer...'
$deadline = (Get-Date).AddSeconds(120)
while ((Get-Date) -lt $deadline) {
if (Test-Health ([int]$runtime.port)) {
Write-Host ("Luminary is running at {0}" -f $runtime.url)
Open-App ([string]$runtime.url)
exit 0
}
if (-not (Test-Process ([int]$runtime.pid))) { break }
Start-Sleep -Milliseconds 700
}
if (Test-Process ([int]$runtime.pid)) {
$logNote = Join-Path (Get-DataDir) 'logs'
Show-ErrorDialog ("Luminary has been starting for over two minutes and is not answering on its local port {0}.`n`nSee {1} for the log." -f $runtime.port, $logNote)
exit 1
}
}
if ($runtime -and (Test-Health ([int]$runtime.port))) {
Write-Host ("Luminary is already running at {0}" -f $runtime.url)
Open-App ([string]$runtime.url)
exit 0
}
if (-not (Test-Bundle)) {
Write-Host ''
Write-Host 'Luminary cannot start: this folder is incomplete.'
Write-BundleHelp
Show-ErrorDialog 'This folder is not a complete Luminary bundle. See the console for the three usual causes.'
exit 3
}
$platform = Test-Platform
foreach ($note in $platform.notes) { Write-Host ("Note: {0}" -f $note) }
if (-not $platform.ok) {
$message = ($platform.problems -join "`n`n") + "`n`nLuminary runs on Windows 10/11 (64-bit) with a current browser (Edge, Chrome or Firefox) for the Develop module. Nothing else needs to be installed."
Write-Host $message
Show-ErrorDialog $message
exit 4
}
$node = Resolve-Node
if (-not $node) {
# The only download Luminary can need is its own runtime. Offer it here so a
# customer who never reads the README still gets a working install.
if (Show-Question "Luminary needs its Node.js 24 runtime, but node.exe is missing from this folder.`n`nDownload it now from nodejs.org (about 90 MB)?") {
try {
Repair-Node
$node = Resolve-Node
} catch {
Write-Host ("Download failed: {0}" -f $_.Exception.Message)
Show-ErrorDialog ("The runtime download failed.`n`n" + $_.Exception.Message)
exit 3
}
}
if (-not $node) {
$message = "Luminary cannot start without node.exe.`n`nRun ""Luminary.cmd -Repair"" to download it, or install Node.js 24 from nodejs.org."
Write-Host $message
Show-ErrorDialog $message
exit 3
}
}
if ($node.system) {
$warning = ("The bundled node.exe is missing; Luminary is using the system Node {0} at {1}.`n`n" +
"Run ""Luminary.cmd -Repair"" to restore the pinned runtime." -f $node.version, $node.path)
Write-Host $warning
Show-Dialog $warning 'Information'
}
$dataDir = Get-DataDir
New-Item -ItemType Directory -Force -Path $dataDir | Out-Null
$logsOut = Get-LogDir $dataDir
$port = Find-Port
$url = "http://127.0.0.1:$port"
# The local engine reads these from the environment; nothing is written into app\.
$env:PORT = "$port"
$env:HOST = '127.0.0.1'
$env:NODE_ENV = 'production'
$env:LUMINARY_DATA = $dataDir
# Desktop mode: one local admin, no signup, no sign-in. Loopback only, so this
# never exposes a passwordless account to the network.
$env:LUMINARY_LOCAL = '1'
$outLog = Join-Path $logsOut 'server.out.log'
$errLog = Join-Path $logsOut 'server.err.log'
$process = Start-Process -FilePath $node.path `
-ArgumentList ('"' + $entry + '"') `
-WorkingDirectory $appDir `
-WindowStyle Hidden `
-PassThru `
-RedirectStandardOutput $outLog `
-RedirectStandardError $errLog
@{
pid = $process.Id
port = $port
url = $url
data = $dataDir
node = $node.path
started = (Get-Date).ToString('o')
} | ConvertTo-Json | Set-Content -LiteralPath $runtimeFile -Encoding UTF8
$deadline = (Get-Date).AddSeconds(120)
while ((Get-Date) -lt $deadline) {
if ($process.HasExited) { break }
if (Test-Health $port) {
Write-Host ("Luminary is running at {0}" -f $url)
Write-Host ("Data: {0}" -f $dataDir)
Open-App $url
exit 0
}
Start-Sleep -Milliseconds 700
}
$tail = ''
if (Test-Path -LiteralPath $errLog) { $tail = (Get-Content -LiteralPath $errLog -Tail 20) -join "`n" }
Write-Host "Luminary's local engine did not answer."
if ($tail) { Write-Host $tail }
if (-not $process.HasExited) { & taskkill.exe /PID $process.Id /T /F | Out-Null }
Remove-Item -LiteralPath $runtimeFile -Force -ErrorAction SilentlyContinue
Show-ErrorDialog ("Luminary did not start.`n`n" + $tail)
exit 1