GeezerVison is showing github.com — fix(app): startup efficiency (#18854) · msis/opencode@546748a
File treeExpand file treeCollapse file tree Open diff view settings desktop-electron/src/renderer
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/src/app.tsx +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,7 +6,7 @@ import { MarkedProvider } from "@opencode-ai/ui/context/marked" | 6 | 6 | import { File } from "@opencode-ai/ui/file" | 7 | 7 | import { Font } from "@opencode-ai/ui/font" | 8 | 8 | import { Splash } from "@opencode-ai/ui/logo" | 9 | | -import { ThemeProvider } from "@opencode-ai/ui/theme" | | 9 | +import { ThemeProvider } from "@opencode-ai/ui/theme/context" | 10 | 10 | import { MetaProvider } from "@solidjs/meta" | 11 | 11 | import { type BaseRouterProps, Navigate, Route, Router } from "@solidjs/router" | 12 | 12 | import { QueryClient, QueryClientProvider } from "@tanstack/solid-query" | @@ -32,7 +32,7 @@ import { FileProvider } from "@/context/file" | 32 | 32 | import { GlobalSDKProvider } from "@/context/global-sdk" | 33 | 33 | import { GlobalSyncProvider } from "@/context/global-sync" | 34 | 34 | import { HighlightsProvider } from "@/context/highlights" | 35 | | -import { LanguageProvider, useLanguage } from "@/context/language" | | 35 | +import { LanguageProvider, type Locale, useLanguage } from "@/context/language" | 36 | 36 | import { LayoutProvider } from "@/context/layout" | 37 | 37 | import { ModelsProvider } from "@/context/models" | 38 | 38 | import { NotificationProvider } from "@/context/notification" | @@ -130,7 +130,7 @@ function RouterRoot(props: ParentProps<{ appChildren?: JSX.Element }>) { | 130 | 130 | ) | 131 | 131 | } | 132 | 132 |
| 133 | | -export function AppBaseProviders(props: ParentProps) { | | 133 | +export function AppBaseProviders(props: ParentProps<{ locale?: Locale }>) { | 134 | 134 | return ( | 135 | 135 | <MetaProvider> | 136 | 136 | <Font /> | @@ -139,7 +139,7 @@ export function AppBaseProviders(props: ParentProps) { | 139 | 139 | void window.api?.setTitlebar?.({ mode }) | 140 | 140 | }} | 141 | 141 | > | 142 | | - <LanguageProvider> | | 142 | + <LanguageProvider locale={props.locale}> | 143 | 143 | <UiI18nBridge> | 144 | 144 | <ErrorBoundary fallback={(error) => <ErrorPage error={error} />}> | 145 | 145 | <QueryProvider> | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/dialog-connect-provider.tsx +38-12Lines changed: 38 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import type { ProviderAuthAuthorization } from "@opencode-ai/sdk/v2/client" | | 1 | +import type { ProviderAuthAuthorization, ProviderAuthMethod } from "@opencode-ai/sdk/v2/client" | 2 | 2 | import { Button } from "@opencode-ai/ui/button" | 3 | 3 | import { useDialog } from "@opencode-ai/ui/context/dialog" | 4 | 4 | import { Dialog } from "@opencode-ai/ui/dialog" | @@ -9,7 +9,7 @@ import { ProviderIcon } from "@opencode-ai/ui/provider-icon" | 9 | 9 | import { Spinner } from "@opencode-ai/ui/spinner" | 10 | 10 | import { TextField } from "@opencode-ai/ui/text-field" | 11 | 11 | import { showToast } from "@opencode-ai/ui/toast" | 12 | | -import { createMemo, Match, onCleanup, onMount, Switch } from "solid-js" | | 12 | +import { createEffect, createMemo, createResource, Match, onCleanup, onMount, Switch } from "solid-js" | 13 | 13 | import { createStore, produce } from "solid-js/store" | 14 | 14 | import { Link } from "@/components/link" | 15 | 15 | import { useGlobalSDK } from "@/context/global-sdk" | @@ -34,15 +34,25 @@ export function DialogConnectProvider(props: { provider: string }) { | 34 | 34 | }) | 35 | 35 |
| 36 | 36 | const provider = createMemo(() => globalSync.data.provider.all.find((x) => x.id === props.provider)!) | 37 | | - const methods = createMemo( | 38 | | - () => | 39 | | - globalSync.data.provider_auth[props.provider] ?? [ | 40 | | - { | 41 | | - type: "api", | 42 | | - label: language.t("provider.connect.method.apiKey"), | 43 | | - }, | 44 | | - ], | | 37 | + const fallback = createMemo<ProviderAuthMethod[]>(() => [ | | 38 | + { | | 39 | + type: "api" as const, | | 40 | + label: language.t("provider.connect.method.apiKey"), | | 41 | + }, | | 42 | + ]) | | 43 | + const [auth] = createResource( | | 44 | + () => props.provider, | | 45 | + async () => { | | 46 | + const cached = globalSync.data.provider_auth[props.provider] | | 47 | + if (cached) return cached | | 48 | + const res = await globalSDK.client.provider.auth() | | 49 | + if (!alive.value) return fallback() | | 50 | + globalSync.set("provider_auth", res.data ?? {}) | | 51 | + return res.data?.[props.provider] ?? fallback() | | 52 | + }, | 45 | 53 | ) | | 54 | + const loading = createMemo(() => auth.loading && !globalSync.data.provider_auth[props.provider]) | | 55 | + const methods = createMemo(() => auth.latest ?? globalSync.data.provider_auth[props.provider] ?? fallback()) | 46 | 56 | const [store, setStore] = createStore({ | 47 | 57 | methodIndex: undefined as undefined | number, | 48 | 58 | authorization: undefined as undefined | ProviderAuthAuthorization, | @@ -177,7 +187,11 @@ export function DialogConnectProvider(props: { provider: string }) { | 177 | 187 | index: 0, | 178 | 188 | }) | 179 | 189 |
| 180 | | - const prompts = createMemo(() => method()?.prompts ?? []) | | 190 | + const prompts = createMemo<NonNullable<ProviderAuthMethod["prompts"]>>(() => { | | 191 | + const value = method() | | 192 | + if (value?.type !== "oauth") return [] | | 193 | + return value.prompts ?? [] | | 194 | + }) | 181 | 195 | const matches = (prompt: NonNullable<ReturnType<typeof prompts>[number]>, value: Record<string, string>) => { | 182 | 196 | if (!prompt.when) return true | 183 | 197 | const actual = value[prompt.when.key] | @@ -296,8 +310,12 @@ export function DialogConnectProvider(props: { provider: string }) { | 296 | 310 | listRef?.onKeyDown(e) | 297 | 311 | } | 298 | 312 |
| 299 | | - onMount(() => { | | 313 | + let auto = false | | 314 | + createEffect(() => { | | 315 | + if (auto) return | | 316 | + if (loading()) return | 300 | 317 | if (methods().length === 1) { | | 318 | + auto = true | 301 | 319 | selectMethod(0) | 302 | 320 | } | 303 | 321 | }) | @@ -573,6 +591,14 @@ export function DialogConnectProvider(props: { provider: string }) { | 573 | 591 | <div class="px-2.5 pb-10 flex flex-col gap-6"> | 574 | 592 | <div onKeyDown={handleKey} tabIndex={0} autofocus={store.methodIndex === undefined ? true : undefined}> | 575 | 593 | <Switch> | | 594 | + <Match when={loading()}> | | 595 | + <div class="text-14-regular text-text-base"> | | 596 | + <div class="flex items-center gap-x-2"> | | 597 | + <Spinner /> | | 598 | + <span>{language.t("provider.connect.status.inProgress")}</span> | | 599 | + </div> | | 600 | + </div> | | 601 | + </Match> | 576 | 602 | <Match when={store.methodIndex === undefined}> | 577 | 603 | <MethodSelection /> | 578 | 604 | </Match> | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/settings-general.tsx +38-12Lines changed: 38 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { Component, Show, createMemo, createResource, type JSX } from "solid-js" | | 1 | +import { Component, Show, createMemo, createResource, onMount, type JSX } from "solid-js" | 2 | 2 | import { createStore } from "solid-js/store" | 3 | 3 | import { Button } from "@opencode-ai/ui/button" | 4 | 4 | import { Icon } from "@opencode-ai/ui/icon" | 5 | 5 | import { Select } from "@opencode-ai/ui/select" | 6 | 6 | import { Switch } from "@opencode-ai/ui/switch" | 7 | 7 | import { Tooltip } from "@opencode-ai/ui/tooltip" | 8 | | -import { useTheme, type ColorScheme } from "@opencode-ai/ui/theme" | | 8 | +import { useTheme, type ColorScheme } from "@opencode-ai/ui/theme/context" | 9 | 9 | import { showToast } from "@opencode-ai/ui/toast" | 10 | 10 | import { useLanguage } from "@/context/language" | 11 | 11 | import { usePlatform } from "@/context/platform" | 12 | 12 | import { useSettings, monoFontFamily } from "@/context/settings" | 13 | | -import { playSound, SOUND_OPTIONS } from "@/utils/sound" | | 13 | +import { playSoundById, SOUND_OPTIONS } from "@/utils/sound" | 14 | 14 | import { Link } from "./link" | 15 | 15 | import { SettingsList } from "./settings-list" | 16 | 16 |
| 17 | 17 | let demoSoundState = { | 18 | 18 | cleanup: undefined as (() => void) | undefined, | 19 | 19 | timeout: undefined as NodeJS.Timeout | undefined, | | 20 | + run: 0, | | 21 | +} | | 22 | + | | 23 | +type ThemeOption = { | | 24 | + id: string | | 25 | + name: string | | 26 | +} | | 27 | + | | 28 | +let font: Promise<typeof import("@opencode-ai/ui/font-loader")> | undefined | | 29 | + | | 30 | +function loadFont() { | | 31 | + font ??= import("@opencode-ai/ui/font-loader") | | 32 | + return font | 20 | 33 | } | 21 | 34 |
| 22 | 35 | // To prevent audio from overlapping/playing very quickly when navigating the settings menus, | 23 | 36 | // delay the playback by 100ms during quick selection changes and pause existing sounds. | 24 | 37 | const stopDemoSound = () => { | | 38 | + demoSoundState.run += 1 | 25 | 39 | if (demoSoundState.cleanup) { | 26 | 40 | demoSoundState.cleanup() | 27 | 41 | } | 28 | 42 | clearTimeout(demoSoundState.timeout) | 29 | 43 | demoSoundState.cleanup = undefined | 30 | 44 | } | 31 | 45 |
| 32 | | -const playDemoSound = (src: string | undefined) => { | | 46 | +const playDemoSound = (id: string | undefined) => { | 33 | 47 | stopDemoSound() | 34 | | - if (!src) return | | 48 | + if (!id) return | 35 | 49 |
| | 50 | + const run = ++demoSoundState.run | 36 | 51 | demoSoundState.timeout = setTimeout(() => { | 37 | | - demoSoundState.cleanup = playSound(src) | | 52 | + void playSoundById(id).then((cleanup) => { | | 53 | + if (demoSoundState.run !== run) { | | 54 | + cleanup?.() | | 55 | + return | | 56 | + } | | 57 | + demoSoundState.cleanup = cleanup | | 58 | + }) | 38 | 59 | }, 100) | 39 | 60 | } | 40 | 61 |
| @@ -44,6 +65,10 @@ export const SettingsGeneral: Component = () => { | 44 | 65 | const platform = usePlatform() | 45 | 66 | const settings = useSettings() | 46 | 67 |
| | 68 | + onMount(() => { | | 69 | + void theme.loadThemes() | | 70 | + }) | | 71 | + | 47 | 72 | const [store, setStore] = createStore({ | 48 | 73 | checking: false, | 49 | 74 | }) | @@ -104,9 +129,7 @@ export const SettingsGeneral: Component = () => { | 104 | 129 | .finally(() => setStore("checking", false)) | 105 | 130 | } | 106 | 131 |
| 107 | | - const themeOptions = createMemo(() => | 108 | | - Object.entries(theme.themes()).map(([id, def]) => ({ id, name: def.name ?? id })), | 109 | | - ) | | 132 | + const themeOptions = createMemo<ThemeOption[]>(() => theme.ids().map((id) => ({ id, name: theme.name(id) }))) | 110 | 133 |
| 111 | 134 | const colorSchemeOptions = createMemo((): { value: ColorScheme; label: string }[] => [ | 112 | 135 | { value: "system", label: language.t("theme.scheme.system") }, | @@ -143,7 +166,7 @@ export const SettingsGeneral: Component = () => { | 143 | 166 | ] as const | 144 | 167 | const fontOptionsList = [...fontOptions] | 145 | 168 |
| 146 | | - const noneSound = { id: "none", label: "sound.option.none", src: undefined } as const | | 169 | + const noneSound = { id: "none", label: "sound.option.none" } as const | 147 | 170 | const soundOptions = [noneSound, ...SOUND_OPTIONS] | 148 | 171 |
| 149 | 172 | const soundSelectProps = ( | @@ -158,7 +181,7 @@ export const SettingsGeneral: Component = () => { | 158 | 181 | label: (o: (typeof soundOptions)[number]) => language.t(o.label), | 159 | 182 | onHighlight: (option: (typeof soundOptions)[number] | undefined) => { | 160 | 183 | if (!option) return | 161 | | - playDemoSound(option.src) | | 184 | + playDemoSound(option.id === "none" ? undefined : option.id) | 162 | 185 | }, | 163 | 186 | onSelect: (option: (typeof soundOptions)[number] | undefined) => { | 164 | 187 | if (!option) return | @@ -169,7 +192,7 @@ export const SettingsGeneral: Component = () => { | 169 | 192 | } | 170 | 193 | setEnabled(true) | 171 | 194 | set(option.id) | 172 | | - playDemoSound(option.src) | | 195 | + playDemoSound(option.id) | 173 | 196 | }, | 174 | 197 | variant: "secondary" as const, | 175 | 198 | size: "small" as const, | @@ -321,6 +344,9 @@ export const SettingsGeneral: Component = () => { | 321 | 344 | current={fontOptionsList.find((o) => o.value === settings.appearance.font())} | 322 | 345 | value={(o) => o.value} | 323 | 346 | label={(o) => language.t(o.label)} | | 347 | + onHighlight={(option) => { | | 348 | + void loadFont().then((x) => x.ensureMonoFont(option?.value)) | | 349 | + }} | 324 | 350 | onSelect={(option) => option && settings.appearance.setFont(option.value)} | 325 | 351 | variant="secondary" | 326 | 352 | size="small" | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/status-popover.tsx +19-4Lines changed: 19 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,6 @@ import { useSDK } from "@/context/sdk" | 16 | 16 | import { normalizeServerUrl, ServerConnection, useServer } from "@/context/server" | 17 | 17 | import { useSync } from "@/context/sync" | 18 | 18 | import { useCheckServerHealth, type ServerHealth } from "@/utils/server-health" | 19 | | -import { DialogSelectServer } from "./dialog-select-server" | 20 | 19 |
| 21 | 20 | const pollMs = 10_000 | 22 | 21 |
| @@ -54,11 +53,15 @@ const listServersByHealth = ( | 54 | 53 | }) | 55 | 54 | } | 56 | 55 |
| 57 | | -const useServerHealth = (servers: Accessor<ServerConnection.Any[]>) => { | | 56 | +const useServerHealth = (servers: Accessor<ServerConnection.Any[]>, enabled: Accessor<boolean>) => { | 58 | 57 | const checkServerHealth = useCheckServerHealth() | 59 | 58 | const [status, setStatus] = createStore({} as Record<ServerConnection.Key, ServerHealth | undefined>) | 60 | 59 |
| 61 | 60 | createEffect(() => { | | 61 | + if (!enabled()) { | | 62 | + setStatus(reconcile({})) | | 63 | + return | | 64 | + } | 62 | 65 | const list = servers() | 63 | 66 | let dead = false | 64 | 67 |
| @@ -162,14 +165,20 @@ export function StatusPopover() { | 162 | 165 | const navigate = useNavigate() | 163 | 166 |
| 164 | 167 | const [shown, setShown] = createSignal(false) | | 168 | + let dialogRun = 0 | | 169 | + let dialogDead = false | | 170 | + onCleanup(() => { | | 171 | + dialogDead = true | | 172 | + dialogRun += 1 | | 173 | + }) | 165 | 174 | const servers = createMemo(() => { | 166 | 175 | const current = server.current | 167 | 176 | const list = server.list | 168 | 177 | if (!current) return list | 169 | 178 | if (list.every((item) => ServerConnection.key(item) !== ServerConnection.key(current))) return [current, ...list] | 170 | 179 | return [current, ...list.filter((item) => ServerConnection.key(item) !== ServerConnection.key(current))] | 171 | 180 | }) | 172 | | - const health = useServerHealth(servers) | | 181 | + const health = useServerHealth(servers, shown) | 173 | 182 | const sortedServers = createMemo(() => listServersByHealth(servers(), server.key, health)) | 174 | 183 | const toggleMcp = useMcpToggleMutation() | 175 | 184 | const defaultServer = useDefaultServerKey(platform.getDefaultServer) | @@ -300,7 +309,13 @@ export function StatusPopover() { | 300 | 309 | <Button | 301 | 310 | variant="secondary" | 302 | 311 | class="mt-3 self-start h-8 px-3 py-1.5" | 303 | | - onClick={() => dialog.show(() => <DialogSelectServer />, defaultServer.refresh)} | | 312 | + onClick={() => { | | 313 | + const run = ++dialogRun | | 314 | + void import("./dialog-select-server").then((x) => { | | 315 | + if (dialogDead || dialogRun !== run) return | | 316 | + dialog.show(() => <x.DialogSelectServer />, defaultServer.refresh) | | 317 | + }) | | 318 | + }} | 304 | 319 | > | 305 | 320 | {language.t("status.popover.action.manageServers")} | 306 | 321 | </Button> | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/terminal.tsx +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { type HexColor, resolveThemeVariant, useTheme, withAlpha } from "@opencode-ai/ui/theme" | | 1 | +import { withAlpha } from "@opencode-ai/ui/theme/color" | | 2 | +import { useTheme } from "@opencode-ai/ui/theme/context" | | 3 | +import { resolveThemeVariant } from "@opencode-ai/ui/theme/resolve" | | 4 | +import type { HexColor } from "@opencode-ai/ui/theme/types" | 2 | 5 | import { showToast } from "@opencode-ai/ui/toast" | 3 | 6 | import type { FitAddon, Ghostty, Terminal as Term } from "ghostty-web" | 4 | 7 | import { type ComponentProps, createEffect, createMemo, onCleanup, onMount, splitProps } from "solid-js" | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/titlebar.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,7 @@ import { IconButton } from "@opencode-ai/ui/icon-button" | 5 | 5 | import { Icon } from "@opencode-ai/ui/icon" | 6 | 6 | import { Button } from "@opencode-ai/ui/button" | 7 | 7 | import { Tooltip, TooltipKeybind } from "@opencode-ai/ui/tooltip" | 8 | | -import { useTheme } from "@opencode-ai/ui/theme" | | 8 | +import { useTheme } from "@opencode-ai/ui/theme/context" | 9 | 9 |
| 10 | 10 | import { useLayout } from "@/context/layout" | 11 | 11 | import { usePlatform } from "@/context/platform" | |
|