Skip to content

Commit 4ab35d2

Browse files
HonaBrendonovich
andauthored
fix(electron): hide Windows background consoles (anomalyco#16842)
Co-authored-by: Brendan Allan <git@brendonovich.dev>
1 parent b4ae030 commit 4ab35d2

File tree

7 files changed

+16
-4
lines changed

7 files changed

+16
-4
lines changed

packages/desktop-electron/src/main/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function syncCli() {
107107

108108
let version = ""
109109
try {
110-
version = execFileSync(installPath, ["--version"]).toString().trim()
110+
version = execFileSync(installPath, ["--version"], { windowsHide: true }).toString().trim()
111111
} catch {
112112
return
113113
}
@@ -147,7 +147,7 @@ export function spawnCommand(args: string, extraEnv: Record<string, string>) {
147147
console.log(`[cli] Executing: ${cmd} ${cmdArgs.join(" ")}`)
148148
const child = spawn(cmd, cmdArgs, {
149149
env: envs,
150-
detached: true,
150+
detached: process.platform !== "win32",
151151
windowsHide: true,
152152
stdio: ["ignore", "pipe", "pipe"],
153153
})

packages/opencode/src/lsp/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export namespace LSP {
114114
return {
115115
process: spawn(item.command[0], item.command.slice(1), {
116116
cwd: root,
117+
windowsHide: true,
117118
env: {
118119
...process.env,
119120
...item.env,

packages/opencode/src/lsp/server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn, type ChildProcessWithoutNullStreams } from "child_process"
1+
import { spawn as launch, type ChildProcessWithoutNullStreams } from "child_process"
22
import path from "path"
33
import os from "os"
44
import { Global } from "../global"
@@ -14,6 +14,11 @@ import { Process } from "../util/process"
1414
import { which } from "../util/which"
1515
import { Module } from "@opencode-ai/util/module"
1616

17+
const spawn = ((cmd, args, opts) => {
18+
if (Array.isArray(args)) return launch(cmd, [...args], { ...(opts ?? {}), windowsHide: true });
19+
return launch(cmd, { ...(args ?? {}), windowsHide: true });
20+
}) as typeof launch
21+
1722
export namespace LSPServer {
1823
const log = Log.create({ service: "lsp.server" })
1924
const pathExists = async (p: string) =>

packages/opencode/src/session/prompt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
16291629
const proc = spawn(shell, args, {
16301630
cwd,
16311631
detached: process.platform !== "win32",
1632+
windowsHide: process.platform === "win32",
16321633
stdio: ["ignore", "pipe", "pipe"],
16331634
env: {
16341635
...process.env,

packages/opencode/src/shell/shell.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export namespace Shell {
1515

1616
if (process.platform === "win32") {
1717
await new Promise<void>((resolve) => {
18-
const killer = spawn("taskkill", ["/pid", String(pid), "/f", "/t"], { stdio: "ignore" })
18+
const killer = spawn("taskkill", ["/pid", String(pid), "/f", "/t"], {
19+
stdio: "ignore",
20+
windowsHide: true,
21+
})
1922
killer.once("exit", () => resolve())
2023
killer.once("error", () => resolve())
2124
})

packages/opencode/src/tool/bash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export const BashTool = Tool.define("bash", async () => {
173173
},
174174
stdio: ["ignore", "pipe", "pipe"],
175175
detached: process.platform !== "win32",
176+
windowsHide: process.platform === "win32",
176177
})
177178

178179
let output = ""

packages/opencode/src/util/process.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export namespace Process {
6060
cwd: opts.cwd,
6161
env: opts.env === null ? {} : opts.env ? { ...process.env, ...opts.env } : undefined,
6262
stdio: [opts.stdin ?? "ignore", opts.stdout ?? "ignore", opts.stderr ?? "ignore"],
63+
windowsHide: process.platform === "win32",
6364
})
6465

6566
let closed = false

0 commit comments

Comments
 (0)