From 3ce60d559269b3727fe8e5c4447ad789ffbdf36d Mon Sep 17 00:00:00 2001 From: Oleksander Konstantinov <89133079+alexkonstant@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:25:06 +0200 Subject: [PATCH] Install and find cloudflared on Windows Without Homebrew God Mode downloaded the macOS .tgz and unpacked it with /usr/bin/tar, so Address -> Connect failed on Windows with "Unpacking cloudflared-darwin-amd64.tgz failed". On Windows it now downloads cloudflared-windows-amd64.exe straight into bin/ and looks for it as cloudflared.exe. macOS behaves as before. --- docs/configuration.md | 6 +++--- server/tunnel/cloudflared.ts | 28 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 87ad336..37ba587 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -21,8 +21,8 @@ button on its screen does, what it needs, and what God Mode keeps on the Mac. **Address → Connect** on God Mode's screen: 1. God Mode looks for `cloudflared` (Homebrew's, or its own copy in `~/.paseo/god-mode/bin/`). If it - is missing, it installs it with `brew install cloudflared`, or without Homebrew downloads - Cloudflare's release build. + is missing, it installs it with `brew install cloudflared`, or without Homebrew (and always on + Windows) downloads Cloudflare's release build. 2. Cloudflare's sign-in page opens on the device where you pressed the button. Sign in, pick the domain, press **Authorize**. The link is good for about ten minutes; press Connect again for a new one. 3. God Mode creates a tunnel named `god-mode`, points `gm.` at it, deletes the sign-in @@ -76,7 +76,7 @@ you: | `tunnel/config.yml`, `tunnel/credentials.json` | The tunnel's configuration and credentials (`cloudflared` runs with them). | | `tunnel/cloudflared.log` | What `cloudflared` printed. | | `voice-button.json` | The voice button's settings. | -| `bin/cloudflared` | Only when God Mode downloaded `cloudflared` itself. | +| `bin/cloudflared` (`cloudflared.exe` on Windows) | Only when God Mode downloaded `cloudflared` itself. | God Mode reads Paseo's own `paseo.pid` and `local-credential` in `~/.paseo/` to reach the daemon, and never copies them. diff --git a/server/tunnel/cloudflared.ts b/server/tunnel/cloudflared.ts index 3ee5189..c8824ff 100644 --- a/server/tunnel/cloudflared.ts +++ b/server/tunnel/cloudflared.ts @@ -33,6 +33,7 @@ export interface TunnelStatus { } const LOGIN_WAIT_MS = 10 * 60_000; +const WINDOWS = process.platform === "win32"; const BREW = ["/opt/homebrew/bin/brew", "/usr/local/bin/brew"]; const tunnelDir = () => join(dataDir(), "tunnel"); const recordFile = () => join(dataDir(), "tunnel.json"); @@ -41,7 +42,7 @@ const credentialsFile = () => join(tunnelDir(), "credentials.json"); const logFile = () => join(tunnelDir(), "cloudflared.log"); const pidFile = () => join(tunnelDir(), "cloudflared.pid"); const originCert = () => join(homedir(), ".cloudflared", "cert.pem"); -const ownBinary = () => join(dataDir(), "bin", "cloudflared"); +const ownBinary = () => join(dataDir(), "bin", WINDOWS ? "cloudflared.exe" : "cloudflared"); /** Where cloudflared is: Homebrew's, or the copy God Mode downloaded. */ export function findCloudflared(): string | null { @@ -54,18 +55,24 @@ async function install(): Promise { const result = await run(brew, ["install", "cloudflared"], { timeoutMs: 10 * 60_000 }); if (!result.ok) throw new Error(`brew install cloudflared failed:\n${tail(result)}`); } else { - // Without Homebrew: Cloudflare's own release build, unpacked into God Mode's data directory. - const asset = `cloudflared-darwin-${arch() === "arm64" ? "arm64" : "amd64"}.tgz`; + // Without Homebrew: Cloudflare's own release build, in God Mode's data directory. On Windows it is + // the .exe itself; there is no arm64 build, and the amd64 one runs under emulation. + const asset = WINDOWS ? "cloudflared-windows-amd64.exe" : `cloudflared-darwin-${arch() === "arm64" ? "arm64" : "amd64"}.tgz`; const response = await fetch(`https://github.com/cloudflare/cloudflared/releases/latest/download/${asset}`); if (!response.ok) throw new Error(`Downloading ${asset} failed: HTTP ${response.status}`); const dir = join(dataDir(), "bin"); await mkdir(dir, { recursive: true, mode: 0o700 }); - const archive = join(dir, asset); - await writeFile(archive, Buffer.from(await response.arrayBuffer()), { mode: 0o600 }); - const unpacked = await run("/usr/bin/tar", ["-xzf", archive, "-C", dir]); - await rm(archive, { force: true }); - if (!unpacked.ok) throw new Error(`Unpacking ${asset} failed:\n${tail(unpacked)}`); - await chmod(ownBinary(), 0o755); + const body = Buffer.from(await response.arrayBuffer()); + if (WINDOWS) { + await writeFile(ownBinary(), body); + } else { + const archive = join(dir, asset); + await writeFile(archive, body, { mode: 0o600 }); + const unpacked = await run("/usr/bin/tar", ["-xzf", archive, "-C", dir]); + await rm(archive, { force: true }); + if (!unpacked.ok) throw new Error(`Unpacking ${asset} failed:\n${tail(unpacked)}`); + await chmod(ownBinary(), 0o755); + } } const found = findCloudflared(); if (!found) throw new Error("cloudflared was installed but is not where God Mode looks for it."); @@ -159,7 +166,8 @@ export class Tunnel { private signIn(binary: string): Promise<{ loginUrl: string; done: Promise }> { return new Promise((resolveLink, rejectLink) => { // A PATH without /usr/bin keeps cloudflared from opening a browser here: the link goes to the - // device the user pressed the button on. + // device the user pressed the button on. Windows ignores the case of variable names: Node keeps + // this PATH and drops the inherited Path, so cloudflared does not find cmd to open one either. const login = spawn(binary, ["tunnel", "login"], { env: { ...process.env, PATH: "/opt/homebrew/bin" }, stdio: ["ignore", "pipe", "pipe"] }); this.login = login; let output = "";