mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 13:22:35 -07:00
Fix terminal hang when user exits browser without logging in (#15748)
This commit is contained in:
committed by
GitHub
parent
b4b49e7029
commit
3997c7ff80
@@ -325,7 +325,41 @@ async function initOauthClient(
|
||||
}, authTimeout);
|
||||
});
|
||||
|
||||
await Promise.race([webLogin.loginCompletePromise, timeoutPromise]);
|
||||
// Listen for SIGINT to stop waiting for auth so the terminal doesn't hang
|
||||
// if the user chooses not to auth.
|
||||
let sigIntHandler: (() => void) | undefined;
|
||||
let stdinHandler: ((data: Buffer) => void) | undefined;
|
||||
const cancellationPromise = new Promise<never>((_, reject) => {
|
||||
sigIntHandler = () =>
|
||||
reject(new FatalCancellationError('Authentication cancelled by user.'));
|
||||
process.on('SIGINT', sigIntHandler);
|
||||
|
||||
// Note that SIGINT might not get raised on Ctrl+C in raw mode
|
||||
// so we also need to look for Ctrl+C directly in stdin.
|
||||
stdinHandler = (data) => {
|
||||
if (data.includes(0x03)) {
|
||||
reject(
|
||||
new FatalCancellationError('Authentication cancelled by user.'),
|
||||
);
|
||||
}
|
||||
};
|
||||
process.stdin.on('data', stdinHandler);
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.race([
|
||||
webLogin.loginCompletePromise,
|
||||
timeoutPromise,
|
||||
cancellationPromise,
|
||||
]);
|
||||
} finally {
|
||||
if (sigIntHandler) {
|
||||
process.removeListener('SIGINT', sigIntHandler);
|
||||
}
|
||||
if (stdinHandler) {
|
||||
process.stdin.removeListener('data', stdinHandler);
|
||||
}
|
||||
}
|
||||
|
||||
coreEvents.emit(CoreEvent.UserFeedback, {
|
||||
severity: 'info',
|
||||
|
||||
Reference in New Issue
Block a user