Skip to content

Commit d04e00f

Browse files
feat: 调整预先检查的代码
1 parent c252294 commit d04e00f

1 file changed

Lines changed: 54 additions & 70 deletions

File tree

src/utils/preflightChecks.tsx

Lines changed: 54 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { c as _c } from "react/compiler-runtime";
21
import axios from 'axios';
32
import React, { useEffect, useState } from 'react';
43
import { logEvent } from 'src/services/analytics/index.js';
@@ -75,76 +74,61 @@ async function checkEndpoints(): Promise<PreflightCheckResult> {
7574
interface PreflightStepProps {
7675
onSuccess: () => void;
7776
}
78-
export function PreflightStep(t0) {
79-
const $ = _c(12);
80-
const {
81-
onSuccess
82-
} = t0;
83-
const [result, setResult] = useState(null);
77+
export function PreflightStep({ onSuccess }: PreflightStepProps) {
78+
const [result, setResult] = useState<PreflightCheckResult | null>(null);
8479
const [isChecking, setIsChecking] = useState(true);
8580
const showSpinner = useTimeout(1000) && isChecking;
86-
let t1;
87-
let t2;
88-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
89-
t1 = () => {
90-
const run = async function run() {
91-
const checkResult = await checkEndpoints();
92-
setResult(checkResult);
93-
setIsChecking(false);
94-
};
95-
run();
96-
};
97-
t2 = [];
98-
$[0] = t1;
99-
$[1] = t2;
100-
} else {
101-
t1 = $[0];
102-
t2 = $[1];
103-
}
104-
useEffect(t1, t2);
105-
let t3;
106-
let t4;
107-
if ($[2] !== onSuccess || $[3] !== result) {
108-
t3 = () => {
109-
if (result?.success) {
110-
onSuccess();
111-
} else {
112-
if (result && !result.success) {
113-
const timer = setTimeout(_temp, 100);
114-
return () => clearTimeout(timer);
115-
}
116-
}
117-
};
118-
t4 = [result, onSuccess];
119-
$[2] = onSuccess;
120-
$[3] = result;
121-
$[4] = t3;
122-
$[5] = t4;
123-
} else {
124-
t3 = $[4];
125-
t4 = $[5];
126-
}
127-
useEffect(t3, t4);
128-
let t5;
129-
if ($[6] !== isChecking || $[7] !== result || $[8] !== showSpinner) {
130-
t5 = isChecking && showSpinner ? <Box paddingLeft={1}><Spinner /><Text>Checking connectivity...</Text></Box> : !result?.success && !isChecking && <Box flexDirection="column" gap={1}><Text color="error">Unable to connect to Anthropic services</Text><Text color="error">{result?.error}</Text>{result?.sslHint ? <Box flexDirection="column" gap={1}><Text>{result.sslHint}</Text><Text color="suggestion">See https://code.claude.com/docs/en/network-config</Text></Box> : <Box flexDirection="column" gap={1}><Text>Please check your internet connection and network settings.</Text><Text>Note: Claude Code might not be available in your country. Check supported countries at{" "}<Text color="suggestion">https://anthropic.com/supported-countries</Text></Text></Box>}</Box>;
131-
$[6] = isChecking;
132-
$[7] = result;
133-
$[8] = showSpinner;
134-
$[9] = t5;
135-
} else {
136-
t5 = $[9];
137-
}
138-
let t6;
139-
if ($[10] !== t5) {
140-
t6 = <Box flexDirection="column" gap={1} paddingLeft={1}>{t5}</Box>;
141-
$[10] = t5;
142-
$[11] = t6;
143-
} else {
144-
t6 = $[11];
81+
82+
useEffect(() => {
83+
checkEndpoints().then((checkResult) => {
84+
setResult(checkResult);
85+
setIsChecking(false);
86+
});
87+
}, []);
88+
89+
useEffect(() => {
90+
if (result?.success) {
91+
onSuccess();
92+
} else if (result && !result.success) {
93+
logError(result.error ?? 'Preflight connectivity check failed');
94+
onSuccess();
95+
}
96+
}, [result, onSuccess]);
97+
98+
let content = null;
99+
if (isChecking && showSpinner) {
100+
content = (
101+
<Box paddingLeft={1}>
102+
<Spinner />
103+
<Text>Checking connectivity...</Text>
104+
</Box>
105+
);
106+
} else if (!result?.success && !isChecking) {
107+
content = (
108+
<Box flexDirection="column" gap={1}>
109+
<Text color="error">Unable to connect to Anthropic services</Text>
110+
<Text color="error">{result?.error}</Text>
111+
{result?.sslHint ? (
112+
<Box flexDirection="column" gap={1}>
113+
<Text>{result.sslHint}</Text>
114+
<Text color="suggestion">See https://code.claude.com/docs/en/network-config</Text>
115+
</Box>
116+
) : (
117+
<Box flexDirection="column" gap={1}>
118+
<Text>Please check your internet connection and network settings.</Text>
119+
<Text>
120+
Note: Claude Code might not be available in your country. Check supported countries at{" "}
121+
<Text color="suggestion">https://anthropic.com/supported-countries</Text>
122+
</Text>
123+
</Box>
124+
)}
125+
</Box>
126+
);
145127
}
146-
return t6;
147-
}
148-
function _temp() {
149-
return process.exit(1);
128+
129+
return (
130+
<Box flexDirection="column" gap={1} paddingLeft={1}>
131+
{content}
132+
</Box>
133+
);
150134
}

0 commit comments

Comments
 (0)