fix: add apt lock timeout and official portable scrcpy fallback across Linux and Windows

- Handle Debian/Ubuntu apt-get lock contention with DPkg::Lock::Timeout
- Decouple apt update from apt install so locks on update do not block installation
- Add official portable scrcpy v4.1 fallback download for Linux (x64/arm64) and Windows (win64)
- Add scrcpy user directories to standard PATH discovery
This commit is contained in:
somew1nd committed 2026-09-04 17:07:54 -07:00
1 parent 29622bae52
commit afbc402225
4 files changed
+149 -4

No files matched your search

+39 -1
View File
@@ -41,8 +41,10 @@ function Update-EnvironmentPath {
"${env:ProgramFiles(x86)}\nodejs",
"$env:APPDATA\npm",
"$env:LOCALAPPDATA\Programs\platform-tools",
"$env:LOCALAPPDATA\Programs\scrcpy",
"$env:LOCALAPPDATA\Programs\node",
"$env:USERPROFILE\.local\share\platform-tools",
"$env:USERPROFILE\.local\share\scrcpy",
"$env:USERPROFILE\.local\share\node",
"$env:LOCALAPPDATA\nvm",
"$env:ProgramData\nvm",
@@ -102,6 +104,39 @@ function Install-PortablePlatformTools {
return $false
}
function Install-PortableScrcpy {
$scrcpyDir = "$env:LOCALAPPDATA\Programs\scrcpy"
if (Test-Path "$scrcpyDir\scrcpy.exe") {
$env:PATH = "$scrcpyDir;$env:PATH"
return $true
}
Write-Host " [INFO] Installing portable scrcpy in user space..." -ForegroundColor Cyan
try {
$zipPath = "$env:TEMP\scrcpy-win64.zip"
Invoke-WebRequest -Uri "https://github.com/Genymobile/scrcpy/releases/download/v4.1/scrcpy-win64-v4.1.zip" -OutFile $zipPath -UseBasicParsing
$extractDir = "$env:TEMP\scrcpy_extract"
if (Test-Path $extractDir) { Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue }
New-Item -ItemType Directory -Path $extractDir -Force | Out-Null
Expand-Archive -Path $zipPath -DestinationPath $extractDir -Force
$extractedFolder = Get-ChildItem -Path $extractDir -Directory | Select-Object -First 1
if ($extractedFolder) {
New-Item -ItemType Directory -Path "$env:LOCALAPPDATA\Programs" -Force | Out-Null
if (Test-Path $scrcpyDir) { Remove-Item $scrcpyDir -Recurse -Force -ErrorAction SilentlyContinue }
Move-Item -Path $extractedFolder.FullName -Destination $scrcpyDir -Force
}
Remove-Item $zipPath -Force -ErrorAction SilentlyContinue
Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue
if (Test-Path "$scrcpyDir\scrcpy.exe") {
$env:PATH = "$scrcpyDir;$env:PATH"
Write-Host " ✔ Portable scrcpy installed in user space." -ForegroundColor Green
return $true
}
} catch {
Write-Host " ⚠ Failed to install portable scrcpy: $_" -ForegroundColor DarkYellow
}
return $false
}
function Test-NodeCompatible {
if (-not (Test-CommandExists "node") -or -not (Test-CommandExists "npm")) { return $false }
try {
@@ -205,10 +240,13 @@ if ($missingCore.Count -gt 0) {
Update-EnvironmentPath
}
# Zero-admin user-space fallback for adb if still missing
# Zero-admin user-space fallback for adb and scrcpy if still missing
if (-not (Test-CommandExists "adb")) {
Install-PortablePlatformTools
}
if (-not (Test-CommandExists "scrcpy")) {
Install-PortableScrcpy
}
}
# Ensure local ADB daemon is warm & listening so probes do not hit 'Connection refused'