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
13 changes: 10 additions & 3 deletions packages/desktop/electron-builder.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ test.each(channels)("channel identity for $channel", ({ channel, appId }) => {
const config = load(channel)
expect(config.appId).toBe(appId)
expect(config.extraMetadata?.desktopName).toBe(`${appId}.desktop`)
expect(config.linux?.executableName).toBe(appId)
// The executable must never end in `.desktop`: libappimage resolves the
// AppImage's desktop entry by globbing `*.desktop`, and an ELF matching
// that glob breaks integration (anomalyco/opencode#51867).
expect(config.linux?.executableName).toBe(appId.replace(/\.desktop$/, ""))
expect(config.linux?.executableName).not.toMatch(/\.desktop$/)
// The installed `.desktop` filename still derives from `desktopName` so
// window association (StartupWMClass/desktop file basename) is unchanged.
expect(config.linux?.syncDesktopName).toBe(true)
expect(config.linux?.desktop?.entry?.StartupWMClass).toBe(appId)

for (const fpm of [config.deb?.fpm, config.rpm?.fpm]) {
Expand All @@ -69,8 +76,8 @@ test.each(channels)("channel identity for $channel", ({ channel, appId }) => {

test("legacy Linux launcher stays hidden", async () => {
const desktop = await Bun.file(path.join(import.meta.dirname, "resources/linux/opencode-desktop.desktop")).text()
expect(desktop).toContain("Exec=/opt/OpenCode/ai.opencode.desktop %U")
expect(desktop).toContain("Icon=ai.opencode.desktop")
expect(desktop).toContain("Exec=/opt/OpenCode/ai.opencode %U")
expect(desktop).toContain("Icon=ai.opencode")
expect(desktop).toContain("StartupWMClass=ai.opencode.desktop")
expect(desktop).toContain("NoDisplay=true")
})
Expand Down
19 changes: 18 additions & 1 deletion packages/desktop/electron-builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ const APP_IDS = {
prod: "ai.opencode.desktop",
} as const

// libappimage (used by AppImageLauncher) resolves the .desktop entry inside an
// AppImage by globbing `*.desktop` at the squashfs root. If the main
// executable itself ends in `.desktop` (prod appId `ai.opencode.desktop`), the
// ELF binary matches the glob and is parsed as a desktop entry, so
// integration fails with `Malformed desktop entry: Unexpected char '\x7f' at 0`
// (0x7F is the first byte of the ELF magic).
// https://github.com/anomalyco/opencode/issues/51867
// Strip a trailing `.desktop` so the executable can never collide with the
// desktop-entry glob. Beta/dev appIds end in `.beta`/`.dev` and are unaffected.
function linuxExecutableName(appId: string): string {
return appId.replace(/\.desktop$/, "")
}

const getBase = (appId: string): Configuration => {
const target = getCurrentCli()

Expand Down Expand Up @@ -205,7 +218,11 @@ const getBase = (appId: string): Configuration => {
linux: {
icon: `resources/icons`,
category: "Development",
executableName: appId,
executableName: linuxExecutableName(appId),
// Derive the installed `.desktop` filename from `desktopName`
// (`ai.opencode.desktop.desktop` for prod) instead of `executableName`,
// so window association is unaffected by the executable rename above.
syncDesktopName: true,
desktop: {
entry: {
// Match the installed .desktop file and hicolor icon basename so
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/resources/linux/opencode-desktop.desktop
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[Desktop Entry]
Name=OpenCode
Exec=/opt/OpenCode/ai.opencode.desktop %U
Exec=/opt/OpenCode/ai.opencode %U
Terminal=false
Type=Application
Icon=ai.opencode.desktop
Icon=ai.opencode
StartupWMClass=ai.opencode.desktop
NoDisplay=true
Comment=Open source AI coding agent
Expand Down
Loading