Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Add Windows cmd installer and path handling
Richie McIlroy97fd6837c533
diff --git a/apps/cli/README.md b/apps/cli/README.mdindex 217c7208f..02fa97474 100644--- a/apps/cli/README.md+++ b/apps/cli/README.md@@ -7,7 +7,7 @@ machine-readable, and recordings have an explicit start/stop lifecycle.## Install- **From Cap Desktop:** Settings → Command Line → Install CLI (links the bundled binary onto your PATH).-- **Script:** `curl -fsSL https://cap.so/install-cli.sh | sh` (Windows PowerShell: `irm https://cap.so/install-cli.ps1 | iex`). If Cap Desktop is missing, the script downloads and installs it first.+- **Script:** `curl -fsSL https://cap.so/install-cli.sh | sh` (Windows PowerShell: `irm https://cap.so/install-cli.ps1 | iex`; Command Prompt: `curl.exe -fsSL https://cap.so/install-cli.cmd -o "%TEMP%\cap-install-cli.cmd" && "%TEMP%\cap-install-cli.cmd"`). If Cap Desktop is missing, the script downloads and installs it first.The desktop app and the CLI share the same binary, so the CLI is always in sync with the installed app.diff --git a/apps/web/app/install-cli.cmd/route.ts b/apps/web/app/install-cli.cmd/route.tsnew file mode 100644index 000000000..662710f2c--- /dev/null+++ b/apps/web/app/install-cli.cmd/route.ts@@ -0,0 +1,14 @@+const script = `@echo off+setlocal+powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Invoke-RestMethod https://cap.so/install-cli.ps1 | Invoke-Expression"+exit /b %ERRORLEVEL%+`;++export async function GET() {+ return new Response(script, {+ headers: {+ "Content-Type": "text/plain; charset=utf-8",+ "Cache-Control": "public, max-age=3600",+ },+ });+}diff --git a/crates/cli-install/src/lib.rs b/crates/cli-install/src/lib.rsindex 62bcf25fc..3ab7e0002 100644--- a/crates/cli-install/src/lib.rs+++ b/crates/cli-install/src/lib.rs@@ -88,20 +88,30 @@ fn target_path() -> Result<PathBuf, String> {// symlink path; resolve it to the real binary so the sibling `cap-cli` resolves to the bundled// one rather than a non-existent path next to the shim (which made status() report installed:false// for every `cap desktop` subcommand). Mirrors doctor.rs's VersionInfo::collect().- let exe = fs::canonicalize(&exe).unwrap_or(exe);+ let exe = resolve_path_for_target_lookup(exe);let dir = exe.parent().ok_or_else(|| "Could not locate Cap executable directory".to_string())?;for candidate in cli_binary_candidates(dir) {if candidate.exists() {- return Ok(fs::canonicalize(&candidate).unwrap_or(candidate));+ return Ok(resolve_path_for_target_lookup(candidate));}}Ok(dir.join(CLI_BINARY_NAME))}+#[cfg(windows)]+fn resolve_path_for_target_lookup(path: PathBuf) -> PathBuf {+ path+}++#[cfg(not(windows))]+fn resolve_path_for_target_lookup(path: PathBuf) -> PathBuf {+ fs::canonicalize(&path).unwrap_or(path)+}+fn cli_binary_candidates(dir: &Path) -> Vec<PathBuf> {cli_binary_candidates_for_triple(dir, current_target_triple())}@@ -234,7 +244,7 @@ fn shim_points_to(shim_path: &Path, target_path: &Path) -> Result<bool, String>Err(err) => return Err(format!("Could not read CLI shim: {err}")),};- let target = display_path(target_path);+ let target = windows_command_path(target_path);Ok(windows_shim_target(&contents).is_some_and(|shim_target| {windows_shim_target_matches(shim_target, &target, |name| env::var(name).ok())}))@@ -290,6 +300,21 @@ fn windows_cli_binary_file_name_is_cap_managed(name: &[u8]) -> bool {|| name.eq_ignore_ascii_case(b"cap-cli-aarch64-pc-windows-msvc.exe")}+#[cfg(any(windows, test))]+fn windows_command_path(path: &Path) -> String {+ let path = display_path(path);++ if let Some(rest) = path.strip_prefix("\\\\?\\UNC\\") {+ return format!("\\\\{rest}");+ }++ if let Some(rest) = path.strip_prefix("\\\\?\\") {+ return rest.to_string();+ }++ path+}+#[cfg(any(windows, test))]fn windows_shim_target_matches<F>(shim_target: &[u8], target: &str, env_value: F) -> boolwhere@@ -418,7 +443,7 @@ fn write_shim(shim_path: &Path, target_path: &Path) -> Result<(), String> {#[cfg(windows)]fn write_shim(shim_path: &Path, target_path: &Path) -> Result<(), String> {- let target = display_path(target_path);+ let target = windows_command_path(target_path);let target = windows_env_prefixed_path(&target, |name| env::var(name).ok()).unwrap_or(target);let contents = format!(r#"@echo off@@ -725,6 +750,20 @@ mod tests {));}+ #[test]+ fn windows_command_path_strips_verbatim_prefixes() {+ assert_eq!(+ windows_command_path(Path::new(+ "\\\\?\\C:\\Users\\Renee\\AppData\\Local\\Programs\\Cap\\cap-cli.exe"+ )),+ "C:\\Users\\Renee\\AppData\\Local\\Programs\\Cap\\cap-cli.exe"+ );+ assert_eq!(+ windows_command_path(Path::new("\\\\?\\UNC\\server\\share\\Cap\\cap-cli.exe")),+ "\\\\server\\share\\Cap\\cap-cli.exe"+ );+ }+#[test]fn windows_cap_cmd_detection_handles_web_installer_targets() {let target = b"%LOCALAPPDATA%\\Programs\\Cap\\cap-cli.exe";