fix(app): hide unavailable titlebar update (#30642)

This commit is contained in:
Luke Parker
2026-06-04 09:51:40 +10:00
committed by GitHub
parent 04b38ce830
commit f62ba5eb86
4 changed files with 34 additions and 6 deletions

View File

@@ -707,7 +707,9 @@ type TitlebarV2RightState = {
function TitlebarV2Right(props: { state: TitlebarV2RightState }) { function TitlebarV2Right(props: { state: TitlebarV2RightState }) {
return ( return (
<div class="relative z-20 flex shrink-0 items-center justify-end gap-0 overflow-visible"> <div class="relative z-20 flex shrink-0 items-center justify-end gap-0 overflow-visible">
<TitlebarUpdateIconButton state={props.state.update} /> <Show when={props.state.update.visible}>
<TitlebarUpdateIconButton state={props.state.update} />
</Show>
<div id="opencode-titlebar-right" class="flex shrink-0 items-center justify-end gap-0" /> <div id="opencode-titlebar-right" class="flex shrink-0 items-center justify-end gap-0" />
</div> </div>
) )

View File

@@ -89,6 +89,7 @@ import {
} from "./layout/sidebar-workspace" } from "./layout/sidebar-workspace"
import { ProjectDragOverlay, SortableProject, type ProjectSidebarContext } from "./layout/sidebar-project" import { ProjectDragOverlay, SortableProject, type ProjectSidebarContext } from "./layout/sidebar-project"
import { SidebarContent } from "./layout/sidebar-shell" import { SidebarContent } from "./layout/sidebar-shell"
import { runUpdateAndRestart } from "./layout/update"
export default function Layout(props: ParentProps) { export default function Layout(props: ParentProps) {
const [store, setStore, , ready] = persisted( const [store, setStore, , ready] = persisted(
@@ -183,11 +184,7 @@ export default function Layout(props: ParentProps) {
return updateQuery.data.version ?? "" return updateQuery.data.version ?? ""
} }
const installUpdate = () => { const installUpdate = () => {
if (!platform.updateAndRestart) return runUpdateAndRestart(platform.updateAndRestart, (installing) => setUpdate("installing", installing))
setUpdate("installing", true)
void platform.updateAndRestart().catch(() => {
setUpdate("installing", false)
})
} }
const titlebarUpdate: TitlebarUpdate = { const titlebarUpdate: TitlebarUpdate = {
version: updateVersion, version: updateVersion,

View File

@@ -0,0 +1,19 @@
import { describe, expect, test } from "bun:test"
import { runUpdateAndRestart } from "./update"
describe("runUpdateAndRestart", () => {
test("clears the installing state when restart resolves without exiting", async () => {
const states: boolean[] = []
await new Promise<void>((resolve) => {
runUpdateAndRestart(
async () => {},
(installing) => {
states.push(installing)
if (states.length === 2) resolve()
},
)
})
expect(states).toEqual([true, false])
})
})

View File

@@ -0,0 +1,10 @@
export function runUpdateAndRestart(
updateAndRestart: (() => Promise<void>) | undefined,
setInstalling: (installing: boolean) => void,
) {
if (!updateAndRestart) return
setInstalling(true)
void updateAndRestart()
.catch(() => undefined)
.finally(() => setInstalling(false))
}