diff --git a/packages/app/src/components/dialog-select-server.tsx b/packages/app/src/components/dialog-select-server.tsx index 8708fb8c84..e8eed170c9 100644 --- a/packages/app/src/components/dialog-select-server.tsx +++ b/packages/app/src/components/dialog-select-server.tsx @@ -59,7 +59,6 @@ interface ServerFormProps { placeholder: string busy: boolean error: string - status: boolean | undefined onChange: (value: string) => void onNameChange: (value: string) => void onUsernameChange: (value: string) => void @@ -80,38 +79,6 @@ function isWslSidecar(conn: ServerConnection.Any): conn is ServerConnection.Side return conn.type === "sidecar" && conn.variant === "wsl" } -function useServerPreview() { - const checkServerHealth = useCheckServerHealth() - - const looksComplete = (value: string) => { - const normalized = normalizeServerUrl(value) - if (!normalized) return false - const host = normalized.replace(/^https?:\/\//, "").split("/")[0] - if (!host) return false - if (host.includes("localhost") || host.startsWith("127.0.0.1")) return true - return host.includes(".") || host.includes(":") - } - - const previewStatus = async ( - value: string, - username: string, - password: string, - setStatus: (value: boolean | undefined) => void, - ) => { - setStatus(undefined) - if (!looksComplete(value)) return - const normalized = normalizeServerUrl(value) - if (!normalized) return - const http: ServerConnection.HttpBase = { url: normalized } - if (username) http.username = username - if (password) http.password = password - const result = await checkServerHealth(http) - setStatus(result.healthy) - } - - return { previewStatus } -} - function ServerForm(props: ServerFormProps) { const language = useLanguage() const keyDown = (event: KeyboardEvent) => { @@ -184,7 +151,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { const language = useLanguage() const { defaultKey, canDefault, setDefault } = useDefaultServer() const wslServers = useWslServers() - const { previewStatus } = useServerPreview() const checkServerHealth = useCheckServerHealth() let disposed = false onCleanup(() => { @@ -199,7 +165,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { password: "", error: "", showForm: false, - status: undefined as boolean | undefined, }, addWsl: { showWizard: props.initialView === "add-wsl", @@ -212,7 +177,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { username: "", password: "", error: "", - status: undefined as boolean | undefined, }, }) @@ -224,7 +188,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { password: "", error: "", showForm: false, - status: undefined, }) } const resetEdit = () => { @@ -235,7 +198,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { username: "", password: "", error: "", - status: undefined, }) } @@ -417,10 +379,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { return wslState()?.opencodeChecks[conn.distro] ?? null } - const displayVersion = (conn: ServerConnection.Any) => { - return wslCheck(conn)?.version ?? undefined - } - async function select(conn: ServerConnection.Any, persist?: boolean) { if (!isSelectable(conn)) return if (!persist && health(ServerConnection.key(conn))?.healthy === false) return @@ -470,9 +428,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { const handleAddChange = (value: string) => { if (addMutation.isPending) return setStore("addServer", { url: value, error: "" }) - void previewStatus(value, store.addServer.username, store.addServer.password, (next) => - setStore("addServer", { status: next }), - ) } const handleAddNameChange = (value: string) => { @@ -483,25 +438,16 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { const handleAddUsernameChange = (value: string) => { if (addMutation.isPending) return setStore("addServer", { username: value, error: "" }) - void previewStatus(store.addServer.url, value, store.addServer.password, (next) => - setStore("addServer", { status: next }), - ) } const handleAddPasswordChange = (value: string) => { if (addMutation.isPending) return setStore("addServer", { password: value, error: "" }) - void previewStatus(store.addServer.url, store.addServer.username, value, (next) => - setStore("addServer", { status: next }), - ) } const handleEditChange = (value: string) => { if (editMutation.isPending) return setStore("editServer", { value, error: "" }) - void previewStatus(value, store.editServer.username, store.editServer.password, (next) => - setStore("editServer", { status: next }), - ) } const handleEditNameChange = (value: string) => { @@ -512,17 +458,11 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { const handleEditUsernameChange = (value: string) => { if (editMutation.isPending) return setStore("editServer", { username: value, error: "" }) - void previewStatus(store.editServer.value, value, store.editServer.password, (next) => - setStore("editServer", { status: next }), - ) } const handleEditPasswordChange = (value: string) => { if (editMutation.isPending) return setStore("editServer", { password: value, error: "" }) - void previewStatus(store.editServer.value, store.editServer.username, value, (next) => - setStore("editServer", { status: next }), - ) } const mode = createMemo<"list" | "add-wsl" | "add" | "edit">(() => { @@ -554,7 +494,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { username: DEFAULT_USERNAME, password: "", error: "", - status: undefined, }) } @@ -568,7 +507,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { username: conn.http.username ?? "", password: conn.http.password ?? "", error: "", - status: health(ServerConnection.key(conn))?.healthy, }) } @@ -674,7 +612,6 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { placeholder={language.t("dialog.server.add.placeholder")} busy={formBusy()} error={isAddMode() ? store.addServer.error : store.editServer.error} - status={isAddMode() ? store.addServer.status : store.editServer.status} onChange={isAddMode() ? handleAddChange : handleEditChange} onNameChange={isAddMode() ? handleAddNameChange : handleEditNameChange} onUsernameChange={isAddMode() ? handleAddUsernameChange : handleEditUsernameChange} @@ -735,7 +672,7 @@ export function DialogSelectServer(props: DialogSelectServerProps = {}) { conn={i} dimmed={blocked()} status={health(key)} - version={displayVersion(i)} + version={wslCheck(i)?.version ?? undefined} class="flex items-center gap-3 min-w-0 flex-1" badge={ diff --git a/packages/app/src/components/dialog-wsl-server.tsx b/packages/app/src/components/dialog-wsl-server.tsx index ddc68cf999..8f79955403 100644 --- a/packages/app/src/components/dialog-wsl-server.tsx +++ b/packages/app/src/components/dialog-wsl-server.tsx @@ -51,14 +51,13 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { disposed = true }) const busy = createMemo(() => !!current()?.job || store.adding) - const selectedDistro = () => store.selectedDistro const selectedProbe = createMemo(() => { - const distro = selectedDistro() + const distro = store.selectedDistro if (!distro) return null return current()?.distroProbes[distro] ?? null }) const selectedInstalled = createMemo(() => { - const distro = selectedDistro() + const distro = store.selectedDistro if (!distro) return null return (current()?.installed ?? []).find((item) => item.name === distro) ?? null }) @@ -68,7 +67,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { const visibleOnlineDistros = createMemo(() => (current()?.online ?? []).filter((item) => !isHiddenDistro(item.name))) const defaultInstalledDistro = createMemo(() => visibleInstalledDistros().find((item) => item.isDefault) ?? null) const opencodeCheck = createMemo(() => { - const distro = selectedDistro() + const distro = store.selectedDistro if (!distro) return null return current()?.opencodeChecks[distro] ?? null }) @@ -80,7 +79,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { }) const distroUnavailableMessage = createMemo(() => { const probe = distroWarningProbe() - const distro = selectedDistro() + const distro = store.selectedDistro if (!probe || probe.canExecute || !distro) return null if (!selectedInstalled()) return `${distro} is not installed yet.` return `Open ${distro} once to finish setup.` @@ -91,10 +90,6 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { if (probe.hasBash && probe.hasCurl) return null return probe }) - const opencodeMismatchCheck = createMemo(() => { - const check = opencodeCheck() - return check?.matchesDesktop === false ? check : null - }) const existingServerDistros = createMemo(() => new Set((current()?.servers ?? []).map((item) => item.config.distro))) const addableInstalledDistros = createMemo(() => { return visibleInstalledDistros().filter((item) => !existingServerDistros().has(item.name)) @@ -121,7 +116,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { const wslReady = createMemo(() => !!current()?.runtime?.available && !current()?.pendingRestart) const distroReady = createMemo(() => { const probe = selectedProbe() - if (!probe || !selectedDistro()) return false + if (!probe || !store.selectedDistro) return false if (selectedInstalled()?.version === 1) return false return probe.canExecute && probe.hasBash && probe.hasCurl }) @@ -185,7 +180,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { if (!state.installed.length && !state.online.length) { return { key: "distros", run: () => refreshDistrosMutation.mutateAsync() } } - const distro = selectedDistro() + const distro = store.selectedDistro if (distro && !state.distroProbes[distro]) { return { key: `probe-distro:${distro}`, run: () => probeDistroMutation.mutateAsync(distro) } } @@ -220,7 +215,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { const state = current() const distro = defaultInstalledDistro() if (!state || !distro || busy()) return - if (selectedDistro()) return + if (store.selectedDistro) return if (existingServerDistros().has(distro.name)) return setStore("selectedDistro", distro.name) }) @@ -246,7 +241,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { const distroMessage = createMemo(() => { const state = current() if (!state) return "Checking distros..." - const distro = selectedDistro() + const distro = store.selectedDistro if (state.job?.kind === "install-distro") return `Installing ${state.job.distro}...` if (state.job?.kind === "probe-distro") return `Checking ${state.job.distro}...` if (state.job?.kind === "distros") return "Listing distros..." @@ -259,7 +254,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { const opencodeMessage = createMemo(() => { const state = current() if (!state) return "Checking OpenCode..." - const distro = selectedDistro() + const distro = store.selectedDistro if (state.job?.kind === "probe-opencode" || state.job?.kind === "install-opencode") { return distro ? `Checking OpenCode in ${distro}...` : "Checking OpenCode..." } @@ -292,7 +287,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { } const runSelectedDistro = (action: (distro: string) => Promise) => { - const distro = selectedDistro() + const distro = store.selectedDistro if (!distro) return void run(() => action(distro)) } @@ -303,7 +298,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) { } const finish = async () => { - const distro = selectedDistro() + const distro = store.selectedDistro if (!distro) return setStore("adding", true) try { @@ -402,7 +397,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) {
Choose a distro
- +
{opencodeMessage()}
- + {(check) => (
Path: {check().resolvedPath ?? "not found"}
@@ -652,7 +647,7 @@ export function DialogWslServer(props: DialogWslServerProps = {}) {
- +