Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): auto-install Cap Desktop in install-cli.ps1 when missing

Richie McIlroy8db7f78db603
diff --git a/apps/web/app/install-cli.ps1/route.ts b/apps/web/app/install-cli.ps1/route.ts
index 067f18dc7..2fdde52c8 100644
--- a/apps/web/app/install-cli.ps1/route.ts
+++ b/apps/web/app/install-cli.ps1/route.ts
@@ -2,9 +2,7 @@ const programFilesX86 = "$" + "{env:ProgramFiles(x86)}";
const script = String.raw`$ErrorActionPreference = "Stop"
-$appPath = $env:CAP_APP_PATH
-
-if (-not $appPath) {
+function Find-CapAppPath {
$candidates = @(
"$env:LOCALAPPDATA\Programs\Cap\Cap.exe",
"$env:LOCALAPPDATA\Cap\Cap.exe",
@@ -14,17 +12,62 @@ if (-not $appPath) {
foreach ($candidate in $candidates) {
if (Test-Path $candidate) {
- $appPath = $candidate
- break
+ return $candidate
}
}
+
+ return $null
}
+function Install-CapDesktop {
+ $downloadUrl = "https://cap.so/download/windows"
+ $installerPath = Join-Path ([System.IO.Path]::GetTempPath()) ("Cap-" + [System.Guid]::NewGuid().ToString("N") + ".exe")
+
+ try {
+ Write-Host "Downloading Cap Desktop..."
+ Invoke-WebRequest -UseBasicParsing -Uri $downloadUrl -OutFile $installerPath
+ Write-Host "Installing Cap Desktop..."
+ $process = Start-Process -FilePath $installerPath -ArgumentList "/S" -Wait -PassThru
+
+ if ($process.ExitCode -ne 0) {
+ Write-Error "Cap Desktop installer failed with exit code $($process.ExitCode)."
+ exit 1
+ }
+ } finally {
+ Remove-Item -Force $installerPath -ErrorAction SilentlyContinue
+ }
+}
+
+$appPath = $env:CAP_APP_PATH
+$forceDesktopInstall = $env:CAP_DESKTOP_FORCE_INSTALL
+
if (-not $appPath) {
- Write-Error "Cap Desktop was not found. Install Cap from https://cap.so/download, then run this script again."
+ $appPath = Find-CapAppPath
+} elseif (-not (Test-Path $appPath)) {
+ Write-Error "Cap Desktop was not found at $appPath."
exit 1
}
+if (-not $appPath) {
+ Install-CapDesktop
+ $appPath = Find-CapAppPath
+
+ if (-not $appPath) {
+ Write-Error "Cap Desktop was installed, but Cap.exe was not found. Open Cap Desktop once, then run this script again."
+ exit 1
+ }
+}
+
+if ($forceDesktopInstall) {
+ Install-CapDesktop
+ $appPath = Find-CapAppPath
+
+ if (-not $appPath) {
+ Write-Error "Cap Desktop was installed, but Cap.exe was not found. Open Cap Desktop once, then run this script again."
+ exit 1
+ }
+}
+
if ((Get-Item $appPath).PSIsContainer) {
$appDir = $appPath
} else {
@@ -34,8 +77,27 @@ if ((Get-Item $appPath).PSIsContainer) {
$cliTarget = Join-Path $appDir "cap-cli.exe"
if (-not (Test-Path $cliTarget)) {
- Write-Error "This Cap Desktop install does not include the CLI. Update Cap, then run this script again."
- exit 1
+ Write-Host "This Cap Desktop install does not include the CLI. Reinstalling Cap Desktop..."
+ Install-CapDesktop
+ $appPath = Find-CapAppPath
+
+ if (-not $appPath) {
+ Write-Error "Cap Desktop was installed, but Cap.exe was not found. Open Cap Desktop once, then run this script again."
+ exit 1
+ }
+
+ if ((Get-Item $appPath).PSIsContainer) {
+ $appDir = $appPath
+ } else {
+ $appDir = Split-Path -Parent $appPath
+ }
+
+ $cliTarget = Join-Path $appDir "cap-cli.exe"
+
+ if (-not (Test-Path $cliTarget)) {
+ Write-Error "This Cap Desktop install does not include the CLI."
+ exit 1
+ }
}
$shimTarget = $cliTarget