Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/desktop/scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ type DevOptions = { server: ServerSource; electron: string[] }

async function main() {
process.env.OPENCODE_CHANNEL = "local"
process.env.OPENCODE_VERSION = `2.0.0-local-${Date.now()}`
process.env.OPENCODE_VERSION ??= `2.0.0-local-${Date.now()}`
process.env.OPENCODE_DISABLE_CHANNEL_DB = "0"
const options = selectOptions()

if (options.server.type === "build") process.env.OPENCODE_DESKTOP_SERVER_CHANNEL = "local"
process.env.OPENCODE_DESKTOP_ISOLATED_SERVER = "1"
process.env.OPENCODE_DESKTOP_ISOLATED_SERVER ??= "1"
await prepareDesktop()
await prepareServer(options.server)
await startDesktop(options.electron)
Expand Down
13 changes: 8 additions & 5 deletions packages/desktop/src/main/lifecycle/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function acquireApplicationLock() {
function createTestRoot() {
const root = testOnboarding
? path.join(tmpdir(), `opencode-onboarding-${randomUUID()}`)
: app.isPackaged
: app.isPackaged && process.env.OPENCODE_DRIVE_GUI !== "1"
? undefined
: process.env.OPENCODE_DESKTOP_TEST_ROOT

Expand All @@ -64,10 +64,13 @@ function createTestRoot() {
mkdirSync(path.join(root, dir), { recursive: true })

if (testOnboarding) process.env.OPENCODE_DB = ":memory:"
process.env.XDG_DATA_HOME = path.join(root, "data")
process.env.XDG_CONFIG_HOME = path.join(root, "config")
process.env.XDG_CACHE_HOME = path.join(root, "cache")
process.env.XDG_STATE_HOME = path.join(root, "state")

if (process.env.OPENCODE_DESKTOP_ISOLATED_SERVER !== "0") {
process.env.XDG_DATA_HOME = path.join(root, "data")
process.env.XDG_CONFIG_HOME = path.join(root, "config")
process.env.XDG_CACHE_HOME = path.join(root, "cache")
process.env.XDG_STATE_HOME = path.join(root, "state")
}

return root
}
21 changes: 15 additions & 6 deletions packages/desktop/src/main/service/background-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,27 @@ const connect = Effect.fn("BackgroundService.connect")(function* (mode: "initial
const desktopCli = yield* DesktopCli.Service
const runFork = Effect.runForkWith(yield* Effect.context<FileSystem.FileSystem | Path.Path>())
const isolated = !app.isPackaged && process.env.OPENCODE_DESKTOP_ISOLATED_SERVER === "1"
const drive = process.env.OPENCODE_DRIVE_GUI === "1"
const cli = yield* desktopCli.resolve
const version = mode === "initial" ? cli.version : undefined
const version = mode === "initial" && !drive ? cli.version : undefined

if (isolated) process.env.XDG_STATE_HOME = app.getPath("userData")
const client = yield* Effect.promise(() => import("@opencode/client/service"))

const file =
isolated && process.env.OPENCODE_DESKTOP_SERVER_CHANNEL === "local"
? path.join(app.getPath("userData"), "opencode", "service-local.json")
: drive && process.env.XDG_STATE_HOME
? path.join(
process.env.XDG_STATE_HOME,
"opencode",
process.env.OPENCODE_CHANNEL === "local" ? "service-local.json" : "service.json",
)
: undefined

const ensure = () =>
client.Service.ensure({
file:
isolated && process.env.OPENCODE_DESKTOP_SERVER_CHANNEL === "local"
? path.join(app.getPath("userData"), "opencode", "service-local.json")
: undefined,
file,
version,
// A fixed port makes a second contender fail to bind and back off; port 0 never collides, so two
// services could boot against the same database.
Expand All @@ -62,7 +71,7 @@ const connect = Effect.fn("BackgroundService.connect")(function* (mode: "initial

// A compatible service the entry module already found is adopted at once; ensure() still runs
// afterwards for its side effects (terminal handoff completion), off the renderer's path.
const early = mode === "initial" && !isolated ? yield* Effect.promise(sidecarProbe) : undefined
const early = mode === "initial" && !isolated && !drive ? yield* Effect.promise(sidecarProbe) : undefined

if (early) yield* Effect.sync(() => void ensure().catch(() => undefined))
const service = early ?? (yield* Effect.tryPromise(ensure))
Expand Down
Loading