Skip to content

Commit f62ba5e

Browse files
authored
fix(app): hide unavailable titlebar update (anomalyco#30642)
1 parent 04b38ce commit f62ba5e

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

packages/app/src/components/titlebar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,9 @@ type TitlebarV2RightState = {
707707
function TitlebarV2Right(props: { state: TitlebarV2RightState }) {
708708
return (
709709
<div class="relative z-20 flex shrink-0 items-center justify-end gap-0 overflow-visible">
710-
<TitlebarUpdateIconButton state={props.state.update} />
710+
<Show when={props.state.update.visible}>
711+
<TitlebarUpdateIconButton state={props.state.update} />
712+
</Show>
711713
<div id="opencode-titlebar-right" class="flex shrink-0 items-center justify-end gap-0" />
712714
</div>
713715
)

packages/app/src/pages/layout.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
} from "./layout/sidebar-workspace"
9090
import { ProjectDragOverlay, SortableProject, type ProjectSidebarContext } from "./layout/sidebar-project"
9191
import { SidebarContent } from "./layout/sidebar-shell"
92+
import { runUpdateAndRestart } from "./layout/update"
9293

9394
export default function Layout(props: ParentProps) {
9495
const [store, setStore, , ready] = persisted(
@@ -183,11 +184,7 @@ export default function Layout(props: ParentProps) {
183184
return updateQuery.data.version ?? ""
184185
}
185186
const installUpdate = () => {
186-
if (!platform.updateAndRestart) return
187-
setUpdate("installing", true)
188-
void platform.updateAndRestart().catch(() => {
189-
setUpdate("installing", false)
190-
})
187+
runUpdateAndRestart(platform.updateAndRestart, (installing) => setUpdate("installing", installing))
191188
}
192189
const titlebarUpdate: TitlebarUpdate = {
193190
version: updateVersion,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { runUpdateAndRestart } from "./update"
3+
4+
describe("runUpdateAndRestart", () => {
5+
test("clears the installing state when restart resolves without exiting", async () => {
6+
const states: boolean[] = []
7+
await new Promise<void>((resolve) => {
8+
runUpdateAndRestart(
9+
async () => {},
10+
(installing) => {
11+
states.push(installing)
12+
if (states.length === 2) resolve()
13+
},
14+
)
15+
})
16+
17+
expect(states).toEqual([true, false])
18+
})
19+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function runUpdateAndRestart(
2+
updateAndRestart: (() => Promise<void>) | undefined,
3+
setInstalling: (installing: boolean) => void,
4+
) {
5+
if (!updateAndRestart) return
6+
setInstalling(true)
7+
void updateAndRestart()
8+
.catch(() => undefined)
9+
.finally(() => setInstalling(false))
10+
}

0 commit comments

Comments
 (0)