Skip to content

Commit 04ad06e

Browse files
authored
fix(desktop): align local development identity (#41889)
1 parent 93965df commit 04ad06e

11 files changed

Lines changed: 28 additions & 12 deletions

File tree

packages/app/src/components/titlebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ function ChannelIndicator(props: { debugTools?: { visible: boolean; toggle: () =
658658

659659
return (
660660
<>
661-
{["beta", "dev"].includes(channel) && (
661+
{["local", "beta", "dev"].includes(channel) && (
662662
<div class="bg-icon-interactive-base text-[#FFF] font-medium px-2 rounded-sm uppercase font-mono">
663663
{channel.toUpperCase()}
664664
</div>

packages/app/src/env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface ImportMetaEnv {
22
readonly VITE_OPENCODE_SERVER_HOST: string
33
readonly VITE_OPENCODE_SERVER_PORT: string
4-
readonly VITE_OPENCODE_CHANNEL?: "dev" | "beta" | "prod"
4+
readonly VITE_OPENCODE_CHANNEL?: "local" | "dev" | "beta" | "prod"
55

66
readonly VITE_SENTRY_DSN?: string
77
readonly VITE_SENTRY_ENVIRONMENT?: string

packages/desktop/electron.vite.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import appPlugin from "@opencode-ai/app/vite"
44

55
const channel = (() => {
66
const raw = process.env.OPENCODE_CHANNEL
7-
if (raw === "dev" || raw === "beta" || raw === "prod") return raw
7+
if (raw === "local" || raw === "dev" || raw === "beta" || raw === "prod") return raw
88
if (process.env.OPENCODE_CHANNEL === "latest") return "prod"
99
return "dev"
1010
})()
@@ -72,6 +72,10 @@ const require = __cjs_mod__.createRequire(import.meta.url);
7272
},
7373
},
7474
renderer: {
75+
define: {
76+
"import.meta.env.OPENCODE_VERSION": JSON.stringify(process.env.OPENCODE_VERSION),
77+
"import.meta.env.VITE_OPENCODE_CHANNEL": JSON.stringify(channel),
78+
},
7579
plugins: [appPlugin, sentry],
7680
publicDir: "../../../app/public",
7781
root: "src/renderer",

packages/desktop/scripts/dev.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ type ServerSource = { type: "build" } | { type: "download"; version: string }
77
type DevOptions = { server: ServerSource; electron: string[] }
88

99
async function main() {
10+
process.env.OPENCODE_CHANNEL = "local"
11+
process.env.OPENCODE_VERSION = `2.0.0-local-${Date.now()}`
12+
process.env.OPENCODE_DISABLE_CHANNEL_DB = "0"
1013
const options = selectOptions()
14+
if (options.server.type === "build") process.env.OPENCODE_DESKTOP_SERVER_CHANNEL = "local"
1115
await prepareDesktop()
1216
await prepareServer(options.server)
1317
await startDesktop(options.electron)

packages/desktop/scripts/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function buildCliToResources(dest = windowsify("resources/opencode-
9393
await $`bun ${join(import.meta.dirname, "../../cli/script/build.ts")} --single --skip-install --skip-web-ui --outdir=${directory}`.env(
9494
{
9595
...process.env,
96-
OPENCODE_VERSION: `0.0.0-local-${Date.now()}`,
96+
OPENCODE_VERSION: process.env.OPENCODE_VERSION,
9797
},
9898
)
9999
if (stateHome && (await Bun.file(dest).exists())) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export async function startBackgroundCli(logger: Logger) {
2525
const binary = app.isPackaged || isolated ? await installCli(bundled, version, logger) : bundled
2626
if (isolated) process.env.XDG_STATE_HOME = app.getPath("userData")
2727
const service = await Service.ensure({
28+
file:
29+
isolated && process.env.OPENCODE_DESKTOP_SERVER_CHANNEL === "local"
30+
? join(app.getPath("userData"), "opencode", "service-local.json")
31+
: undefined,
2832
version,
2933
command: [binary, "serve", "--service"],
3034
onStart: (reason, previousVersion) => logger.log("v2 CLI background service starting", { reason, previousVersion }),
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { app } from "electron"
22

3-
type Channel = "dev" | "beta" | "prod"
3+
type Channel = "local" | "dev" | "beta" | "prod"
44
const raw = import.meta.env.OPENCODE_CHANNEL
5-
export const CHANNEL: Channel = raw === "dev" || raw === "beta" || raw === "prod" ? raw : "dev"
5+
export const CHANNEL: Channel = raw === "local" || raw === "dev" || raw === "beta" || raw === "prod" ? raw : "dev"
6+
export const VERSION = app.isPackaged ? app.getVersion() : (process.env.OPENCODE_VERSION ?? app.getVersion())
67

78
export const UPDATER_ENABLED = app.isPackaged && CHANNEL !== "dev"

packages/desktop/src/main/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
interface ImportMetaEnv {
22
readonly OPENCODE_CHANNEL: string
3+
readonly OPENCODE_VERSION?: string
34
}
45

56
interface ImportMeta {

packages/desktop/src/main/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import contextMenu from "electron-context-menu"
1212

1313
import type { ServerReadyData } from "../preload/types"
1414
import { checkAppExists, resolveAppPath } from "./apps"
15-
import { CHANNEL } from "./constants"
15+
import { CHANNEL, VERSION } from "./constants"
1616
import { registerIpcHandlers, sendDeepLinks, sendMenuCommand } from "./ipc"
1717
import { forwardInitializationFailure } from "./initialization"
1818
import { exportDebugLogs, initCrashReporter, initLogging, startNetLog, write as writeLog } from "./logging"
@@ -135,7 +135,7 @@ const main = Effect.gen(function* () {
135135
initCrashReporter()
136136

137137
const wslServers = createWslServersController(
138-
app.getVersion(),
138+
VERSION,
139139
async (distro) => {
140140
logger.log("spawning wsl sidecar", { distro })
141141
return spawnWslSidecar(distro, {
@@ -165,7 +165,7 @@ const main = Effect.gen(function* () {
165165
}
166166

167167
logger.log("app starting", {
168-
version: app.getVersion(),
168+
version: VERSION,
169169
packaged: app.isPackaged,
170170
onboardingTest: Boolean(onboardingTestRoot),
171171
})

packages/desktop/src/main/logging.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, wri
55
import { ZipWriter, BlobWriter, BlobReader } from "@zip.js/zip.js"
66
import { dirname, join } from "node:path"
77
import { homedir } from "node:os"
8+
import { VERSION } from "./constants"
89

910
const MAX_LOG_AGE_DAYS = 7
1011
const TAIL_LINES = 1000
@@ -133,7 +134,7 @@ function cleanup() {
133134
function manifest() {
134135
return {
135136
generated: new Date().toISOString(),
136-
version: app.getVersion(),
137+
version: VERSION,
137138
name: app.getName(),
138139
packaged: app.isPackaged,
139140
platform: process.platform,

0 commit comments

Comments
 (0)