Repository navigation
fix(mobile): update outdated servers and respect provider permissions #21402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
apps/mobile/src/features/settings/OutdatedServerUpdateSection.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import { useAtomValue } from "@effect/atom-react"; | ||
| import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; | ||
| import type { EnvironmentId } from "@t3tools/contracts"; | ||
| import { AsyncResult } from "effect/reactivity"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { View } from "react-native"; | ||
|
|
||
| import { AppText as Text } from "../../components/ui/AppText"; | ||
| import * as Dialog from "../../components/ui/Dialog"; | ||
| import { | ||
| describeOutdatedServer, | ||
| serverEnvironment, | ||
| updateOutdatedServer, | ||
| } from "../../state/server"; | ||
| import { useAtomCommand } from "../../state/use-atom-command"; | ||
| import { SettingsActionRow } from "./components/SettingsActionRow"; | ||
| import { SettingsSection } from "./components/SettingsSection"; | ||
| import { findEnvironmentUpdate } from "./environment-maintenance"; | ||
|
|
||
| export function OutdatedServerUpdateSection({ | ||
| environmentId, | ||
| label, | ||
| }: { | ||
| readonly environmentId: EnvironmentId; | ||
| readonly label: string; | ||
| }) { | ||
| const describe = useAtomCommand(describeOutdatedServer, { reportFailure: false }); | ||
| const update = useAtomCommand(updateOutdatedServer, { reportFailure: false }); | ||
| const state = useAtomValue(serverEnvironment.updateStateAtom(environmentId)); | ||
| const [release, setRelease] = useState<{ | ||
| fromVersion: string; | ||
| targetVersion: string | null; | ||
| } | null>(null); | ||
| const [checking, setChecking] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const controller = useRef<AbortController | null>(null); | ||
| useEffect(() => () => controller.current?.abort(), []); | ||
| const busy = checking || state.status === "running"; | ||
|
|
||
| async function check() { | ||
| if (busy || controller.current !== null) return; | ||
| const request = new AbortController(); | ||
| controller.current = request; | ||
| setChecking(true); | ||
| setError(null); | ||
| const timeout = setTimeout(() => request.abort(), 20_000); | ||
| const result = await settlePromise(async () => { | ||
| const description = await describe(environmentId); | ||
| if (AsyncResult.isFailure(description)) throw squashAtomCommandFailure(description); | ||
| const fromVersion = description.value.serverVersion; | ||
| const targetVersion = await findEnvironmentUpdate(fromVersion, request.signal); | ||
| if (!request.signal.aborted) setRelease({ fromVersion, targetVersion }); | ||
| }); | ||
| clearTimeout(timeout); | ||
| controller.current = null; | ||
| setChecking(false); | ||
| if (AsyncResult.isFailure(result)) { | ||
| const failure = squashAtomCommandFailure(result); | ||
| setError(failure instanceof Error ? failure.message : "Could not check for updates."); | ||
| } | ||
| } | ||
|
|
||
| function requestUpdate() { | ||
| const targetVersion = release?.targetVersion; | ||
| if (busy || !release || !targetVersion) return; | ||
| Dialog.alert( | ||
| `Update ${label}?`, | ||
| `Install T3 Code ${targetVersion}. T3 Code restarts on that machine and reconnects. Running threads may be interrupted.`, | ||
| [ | ||
| { text: "Cancel", style: "cancel" }, | ||
| { | ||
| text: "Update", | ||
| onPress: () => { | ||
| setError(null); | ||
| void update({ | ||
| environmentId, | ||
| input: { targetVersion }, | ||
| fromVersion: release.fromVersion, | ||
| }); | ||
| }, | ||
| }, | ||
| ], | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <SettingsSection title="T3 Code"> | ||
| <View className="gap-1 p-4"> | ||
| <Text className="text-base text-foreground"> | ||
| {release ? `Version ${release.fromVersion}` : "Update required"} | ||
| </Text> | ||
| <Text className="text-sm text-foreground-muted"> | ||
| {state.status === "running" | ||
| ? state.stage === "resuming" | ||
| ? "Restarting and reconnecting…" | ||
| : state.stage === "installing" | ||
| ? "Installing update…" | ||
| : "Downloading update…" | ||
| : release | ||
| ? release.targetVersion | ||
| ? `Version ${release.targetVersion} is available.` | ||
| : "No newer version is available yet." | ||
| : "This app needs a newer version of T3 Code on this machine."} | ||
| </Text> | ||
| {error || state.status === "failed" ? ( | ||
| <Text selectable accessibilityRole="alert" className="text-sm text-danger-foreground"> | ||
| {error ?? (state.status === "failed" ? state.message : null)} | ||
| </Text> | ||
| ) : null} | ||
| </View> | ||
| <SettingsActionRow | ||
| icon="arrow.clockwise" | ||
| label="Check for updates" | ||
| disabled={busy} | ||
| loading={checking} | ||
| onPress={() => void check()} | ||
| /> | ||
| {release?.targetVersion ? ( | ||
| <SettingsActionRow | ||
| icon="arrow.up.circle" | ||
| label={state.status === "failed" ? "Retry update" : `Update to ${release.targetVersion}`} | ||
| disabled={busy} | ||
| loading={state.status === "running"} | ||
| onPress={requestUpdate} | ||
| /> | ||
| ) : null} | ||
| </SettingsSection> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.