mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix: terminal flicker when waiting for login
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Box, Text, useInput } from 'ink';
|
import { Box, Text, useInput, Static } from 'ink';
|
||||||
import Spinner from 'ink-spinner';
|
import Spinner from 'ink-spinner';
|
||||||
import Link from 'ink-link';
|
import Link from 'ink-link';
|
||||||
import qrcode from 'qrcode-terminal';
|
import qrcode from 'qrcode-terminal';
|
||||||
@@ -26,6 +26,13 @@ interface QwenOAuthProgressProps {
|
|||||||
authMessage?: string | null;
|
authMessage?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface StaticItem {
|
||||||
|
key: string;
|
||||||
|
type: 'title' | 'instructions' | 'url' | 'qr-instructions' | 'qr-code' | 'auth-content';
|
||||||
|
url?: string;
|
||||||
|
qrCode?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export function QwenOAuthProgress({
|
export function QwenOAuthProgress({
|
||||||
onTimeout,
|
onTimeout,
|
||||||
onCancel,
|
onCancel,
|
||||||
@@ -54,7 +61,8 @@ export function QwenOAuthProgress({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate QR code string
|
// Only generate QR code if we don't have one yet for this URL
|
||||||
|
if (qrCodeData === null) {
|
||||||
const generateQR = () => {
|
const generateQR = () => {
|
||||||
try {
|
try {
|
||||||
qrcode.generate(
|
qrcode.generate(
|
||||||
@@ -71,7 +79,8 @@ export function QwenOAuthProgress({
|
|||||||
};
|
};
|
||||||
|
|
||||||
generateQR();
|
generateQR();
|
||||||
}, [deviceAuth]);
|
}
|
||||||
|
}, [deviceAuth, qrCodeData]);
|
||||||
|
|
||||||
// Countdown timer
|
// Countdown timer
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -161,12 +170,23 @@ export function QwenOAuthProgress({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{qrCodeData && (
|
||||||
|
<Static items={[
|
||||||
|
{ key: 'auth-content', type: 'auth-content' as const, url: deviceAuth.verification_uri_complete, qrCode: qrCodeData }
|
||||||
|
] as StaticItem[]}
|
||||||
|
style={{
|
||||||
|
width: "100%"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(item: StaticItem) => (
|
||||||
<Box
|
<Box
|
||||||
borderStyle="round"
|
borderStyle="round"
|
||||||
borderColor={Colors.AccentBlue}
|
borderColor={Colors.AccentBlue}
|
||||||
flexDirection="column"
|
flexDirection="column"
|
||||||
padding={1}
|
padding={1}
|
||||||
width="100%"
|
width="100%"
|
||||||
|
key={item.key}
|
||||||
>
|
>
|
||||||
<Text bold color={Colors.AccentBlue}>
|
<Text bold color={Colors.AccentBlue}>
|
||||||
Qwen OAuth Authentication
|
Qwen OAuth Authentication
|
||||||
@@ -175,21 +195,31 @@ export function QwenOAuthProgress({
|
|||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>Please visit this URL to authorize:</Text>
|
<Text>Please visit this URL to authorize:</Text>
|
||||||
</Box>
|
</Box>
|
||||||
<Link url={deviceAuth.verification_uri_complete} fallback={false}>
|
|
||||||
|
<Link url={item.url || ''} fallback={false}>
|
||||||
<Text color={Colors.AccentGreen} bold>
|
<Text color={Colors.AccentGreen} bold>
|
||||||
{deviceAuth.verification_uri_complete}
|
{item.url || ''}
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
{qrCodeData && (
|
|
||||||
<>
|
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>Or scan the QR code below:</Text>
|
<Text>Or scan the QR code below:</Text>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>{qrCodeData}</Text>
|
<Text>{item.qrCode || ''}</Text>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
|
</Static>
|
||||||
|
)}
|
||||||
|
<Box
|
||||||
|
borderStyle="round"
|
||||||
|
borderColor={Colors.AccentBlue}
|
||||||
|
flexDirection="column"
|
||||||
|
padding={1}
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>
|
<Text>
|
||||||
@@ -204,5 +234,6 @@ export function QwenOAuthProgress({
|
|||||||
<Text color={Colors.AccentPurple}>(Press ESC to cancel)</Text>
|
<Text color={Colors.AccentPurple}>(Press ESC to cancel)</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user