Skip to content

Commit

Permalink
fix: Prevent redirect to new DevPod Pro experience if support for it …
Browse files Browse the repository at this point in the history
…is not present
  • Loading branch information
PRTTMPRPHT authored and pascalbreuninger committed Nov 23, 2024
1 parent d46e7f5 commit 78059e5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion desktop/src/contexts/DevPodContext/DevPodProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { usePollWorkspaces } from "./workspaces"
export type TDevpodContext = Readonly<{
providers: TQueryResult<TProviders>
}>
export const DevPodContext = createContext<TDevpodContext>(null!)
export const DevPodContext = createContext<TDevpodContext | null>(null)

export function DevPodProvider({ children }: Readonly<{ children?: ReactNode }>) {
usePollWorkspaces()
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/contexts/DevPodContext/useProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { TProviderManager } from "../../types"
import { DevPodContext, TDevpodContext } from "./DevPodProvider"
import { useProviderManager } from "./useProviderManager"

export function useProviders(): [TDevpodContext["providers"], TProviderManager] {
const providers = useContext(DevPodContext).providers
export function useProviders(): [TDevpodContext["providers"] | [undefined], TProviderManager] {
const providers = useContext(DevPodContext)?.providers ?? [undefined]
const manager = useProviderManager()

return [providers, manager]
Expand Down
23 changes: 15 additions & 8 deletions desktop/src/lib/modals/useLoginProModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BottomActionBar, BottomActionBarError, Form, useStreamingTerminal } from "@/components"
import { useProInstanceManager, useProInstances } from "@/contexts"
import { exists, useFormErrors } from "@/lib"
import { useProInstanceManager, useProInstances, useProviders } from "@/contexts"
import { canHealthCheck, exists, useFormErrors } from "@/lib"
import { Routes } from "@/routes"
import {
Box,
Expand Down Expand Up @@ -52,6 +52,7 @@ export function useLoginProModal() {
>({})
const { terminal, connectStream, clear: clearTerminal } = useStreamingTerminal({ fontSize: "sm" })
const [[proInstances], { login, disconnect }] = useProInstances()
const [[providers]] = useProviders()
const { isOpen, onClose, onOpen } = useDisclosure()
const { handleSubmit, formState, register, reset, setValue } = useForm<TFormValues>({
mode: "onBlur",
Expand Down Expand Up @@ -140,13 +141,19 @@ export function useLoginProModal() {
resetModal()

const proInstanceID = proInstances?.find((pro) => pro.provider === state.providerID)?.host
if (!proInstanceID) return
if (!proInstanceID || !state.providerID) return

// workaround for layout shift after closing modal, no clue why
setTimeout(() => {
navigate(Routes.toProInstance(proInstanceID))
}, 0)
}, [completeConfigureProvider, navigate, proInstances, resetModal, state.providerID])
const provider = providers?.[state.providerID]

// We only redirect to the new experience if the provider supports it.
// Support can be determined via canHealthCheck.
if (provider && canHealthCheck(provider.config)) {
// workaround for layout shift after closing modal, no clue why
setTimeout(() => {
navigate(Routes.toProInstance(proInstanceID))
}, 0)
}
}, [completeConfigureProvider, navigate, providers, proInstances, resetModal, state.providerID])

const modal = useMemo(() => {
return (
Expand Down
5 changes: 5 additions & 0 deletions hack/rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [[ $BUILD_PLATFORMS == *"linux"* ]]; then
cp test/devpod-cli-linux-amd64 desktop/src-tauri/bin/devpod-cli-x86_64-unknown-linux-gnu
cp test/devpod-cli-linux-arm64 desktop/src-tauri/bin/devpod-cli-aarch64-unknown-linux-gnu
fi

if [[ $BUILD_PLATFORMS == *"windows"* ]]; then
cp test/devpod-cli-windows-amd64 desktop/src-tauri/bin/devpod-cli-x86_64-pc-windows-msvc.exe
fi

# only copy if darwin is in BUILD_PLATFORMS
if [[ $BUILD_PLATFORMS == *"darwin"* ]]; then
cp test/devpod-cli-darwin-amd64 desktop/src-tauri/bin/devpod-cli-x86_64-apple-darwin
Expand Down

0 comments on commit 78059e5

Please sign in to comment.