mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-15 12:41:37 +03:00
feat(desktop): preserve Drive-managed development state (#57112)
This commit is contained in:
committed by
GitHub
Unverified
parent
52a10f573f
commit
cb07c555d4
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user