qwen-code/packages/cli/src/ui/components/AuthInProgress.tsx

63 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-06-20 10:46:41 -07:00
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import React, { useState, useEffect } from 'react';
import { Box, Text } from 'ink';
2025-06-20 10:46:41 -07:00
import Spinner from 'ink-spinner';
import { theme } from '../semantic-colors.js';
import { useKeypress } from '../hooks/useKeypress.js';
2025-06-20 10:46:41 -07:00
interface AuthInProgressProps {
onTimeout: () => void;
}
export function AuthInProgress({
onTimeout,
}: AuthInProgressProps): React.JSX.Element {
const [timedOut, setTimedOut] = useState(false);
useKeypress(
(key) => {
if (key.name === 'escape' || (key.ctrl && key.name === 'c')) {
onTimeout();
}
},
{ isActive: true },
);
2025-06-20 11:33:31 -07:00
2025-06-20 10:46:41 -07:00
useEffect(() => {
const timer = setTimeout(() => {
setTimedOut(true);
onTimeout();
2025-06-20 11:33:31 -07:00
}, 180000);
2025-06-20 10:46:41 -07:00
return () => clearTimeout(timer);
}, [onTimeout]);
return (
<Box
borderStyle="round"
borderColor={theme.border.default}
2025-06-20 10:46:41 -07:00
flexDirection="column"
padding={1}
width="100%"
>
{timedOut ? (
<Text color={theme.status.error}>
2025-06-20 10:46:41 -07:00
Authentication timed out. Please try again.
</Text>
) : (
<Box>
<Text color={theme.text.primary}>
<Spinner type="dots" /> Waiting for auth... (Press ESC or CTRL+C to
cancel)
2025-06-20 10:46:41 -07:00
</Text>
</Box>
)}
</Box>
);
}