Fix tray health detection and harden backend service startup
All checks were successful
CI / test (push) Successful in 7s
All checks were successful
CI / test (push) Successful in 7s
This commit is contained in:
@@ -15,24 +15,75 @@ function Test-EnvVarLine {
|
||||
return [bool](Select-String -Path $FilePath -Pattern ("^\s*" + [regex]::Escape($Name) + "=") -Quiet)
|
||||
}
|
||||
|
||||
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
|
||||
function Resolve-PythonExecutable {
|
||||
$venvPython = Join-Path $scriptDir ".venv\Scripts\python.exe"
|
||||
if (-not (Test-Path -LiteralPath $venvPython)) {
|
||||
throw "Python was not found in PATH and .venv\\Scripts\\python.exe is missing. Install Python 3.11+ or create .venv first."
|
||||
if (Test-Path -LiteralPath $venvPython) {
|
||||
return $venvPython
|
||||
}
|
||||
|
||||
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||
if ($null -ne $pythonCmd -and (Test-Path -LiteralPath $pythonCmd.Source)) {
|
||||
return $pythonCmd.Source
|
||||
}
|
||||
|
||||
$candidatePyLaunchers = @()
|
||||
$pyFromPath = Get-Command py -ErrorAction SilentlyContinue
|
||||
if ($null -ne $pyFromPath -and (Test-Path -LiteralPath $pyFromPath.Source)) {
|
||||
$candidatePyLaunchers += $pyFromPath.Source
|
||||
}
|
||||
$candidatePyLaunchers += "C:\Windows\py.exe"
|
||||
|
||||
if ($scriptDir -match "^[A-Za-z]:\\Users\\[^\\]+") {
|
||||
$repoUserHome = $Matches[0]
|
||||
$candidatePyLaunchers += (Join-Path $repoUserHome "AppData\Local\Programs\Python\Launcher\py.exe")
|
||||
}
|
||||
|
||||
foreach ($pyLauncher in ($candidatePyLaunchers | Select-Object -Unique)) {
|
||||
if (-not (Test-Path -LiteralPath $pyLauncher)) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
$resolved = (& $pyLauncher -3 -c "import sys; print(sys.executable)" 2>$null | Select-Object -Last 1).Trim()
|
||||
if ($resolved -and (Test-Path -LiteralPath $resolved)) {
|
||||
return $resolved
|
||||
}
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
$candidatePythonPaths = @()
|
||||
if ($scriptDir -match "^[A-Za-z]:\\Users\\[^\\]+") {
|
||||
$repoUserHome = $Matches[0]
|
||||
$pythonBase = Join-Path $repoUserHome "AppData\Local\Programs\Python"
|
||||
if (Test-Path -LiteralPath $pythonBase) {
|
||||
$candidatePythonPaths += (Get-ChildItem -LiteralPath $pythonBase -Directory -ErrorAction SilentlyContinue |
|
||||
Sort-Object Name -Descending |
|
||||
ForEach-Object { Join-Path $_.FullName "python.exe" })
|
||||
}
|
||||
}
|
||||
|
||||
$candidatePythonPaths += @(
|
||||
"C:\Python314\python.exe",
|
||||
"C:\Python313\python.exe",
|
||||
"C:\Python312\python.exe",
|
||||
"C:\Python311\python.exe",
|
||||
"C:\Program Files\Python314\python.exe",
|
||||
"C:\Program Files\Python313\python.exe",
|
||||
"C:\Program Files\Python312\python.exe",
|
||||
"C:\Program Files\Python311\python.exe"
|
||||
)
|
||||
|
||||
foreach ($candidate in ($candidatePythonPaths | Select-Object -Unique)) {
|
||||
if (Test-Path -LiteralPath $candidate) {
|
||||
return $candidate
|
||||
}
|
||||
}
|
||||
|
||||
throw "Python was not found. Install Python 3.11+ system-wide, or create .venv in the repo root."
|
||||
}
|
||||
|
||||
$pythonExe = $null
|
||||
$venvPython = Join-Path $scriptDir ".venv\Scripts\python.exe"
|
||||
if (Test-Path -LiteralPath $venvPython) {
|
||||
$pythonExe = $venvPython
|
||||
} else {
|
||||
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||
if ($null -eq $pythonCmd) {
|
||||
throw "Python was not found in PATH. Install Python 3.11+ or create .venv first."
|
||||
}
|
||||
$pythonExe = $pythonCmd.Source
|
||||
}
|
||||
$pythonExe = Resolve-PythonExecutable
|
||||
|
||||
$envFile = Join-Path $scriptDir ".env"
|
||||
if (-not (Test-Path -LiteralPath $envFile)) {
|
||||
@@ -46,5 +97,5 @@ if (-not (Test-Path -LiteralPath $envFile)) {
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Starting ScreenJob backend on configured host/port..." -ForegroundColor Cyan
|
||||
Write-Host "Starting ScreenJob backend with Python: $pythonExe" -ForegroundColor Cyan
|
||||
& $pythonExe main.py server
|
||||
|
||||
Reference in New Issue
Block a user