fix(app): hide unavailable titlebar update (#30642)
This commit is contained in:
@@ -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>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
19
packages/app/src/pages/layout/update.test.ts
Normal file
19
packages/app/src/pages/layout/update.test.ts
Normal 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])
|
||||||
|
})
|
||||||
|
})
|
||||||
10
packages/app/src/pages/layout/update.ts
Normal file
10
packages/app/src/pages/layout/update.ts
Normal 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))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user