Skip to content

Commit d732b47

Browse files
committed
Smarter wait to Open Browser
1 parent 0e9fea8 commit d732b47

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

start.ps1

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,40 @@ $streamlitAppPath = "$PSScriptRoot\src\libinspector\dashboard.py"
8888
# The entire argument list is passed to uv.
8989
$StreamlitArgs = @("run", "streamlit", "run", "`"$streamlitAppPath`"")
9090

91-
Start-Process -FilePath "uv" `
91+
$streamlitProcess = Start-Process -FilePath "uv" `
9292
-ArgumentList $StreamlitArgs `
9393
-PassThru `
9494
-NoNewWindow
95-
# Wait for a few seconds to let the server start
96-
Start-Sleep -Seconds 3
9795

96+
97+
$isReady = $false
98+
$pollingDelaySeconds = 3
99+
$appUrl = "http://localhost:33721/"
100+
# Loop indefinitely until $isReady becomes $true
101+
while (-not $isReady) {
102+
try {
103+
# Use Invoke-WebRequest to check for a successful connection (Status Code 200).
104+
# We set a short TimeoutSec on the request itself to prevent hanging.
105+
$request = Invoke-WebRequest -Uri $appUrl -TimeoutSec 5 -ErrorAction Stop
106+
if ($request.StatusCode -eq 200) {
107+
$isReady = $true
108+
Write-Host "✅ Server is ready. Launching browser."
109+
}
110+
} catch {
111+
# Server is not ready yet, or connection failed. Ignore the error.
112+
Write-Host "Still waiting for Streamlit server..."
113+
}
114+
115+
if (-not $isReady) {
116+
Start-Sleep -Seconds $pollingDelaySeconds
117+
}
118+
}
98119
# Open the browser to the application URL
99-
Start-Process -FilePath "http://localhost:33721/"
120+
Start-Process -FilePath $appUrl
100121

101122
# Wait for the Streamlit process to finish or for the user to close this window
102123
Write-Host "IoT Inspector is running. Close this window to stop the application."
124+
if ($streamlitProcess) {
125+
$streamlitProcess.WaitForExit()
126+
}
127+
Write-Host "IoT Inspector has been closed. Exiting setup script."

0 commit comments

Comments
 (0)