chore(vscode-ide-companion): wip

This commit is contained in:
yiliang114
2025-12-13 17:50:15 +08:00
parent 9e392b3035
commit 0ac191e2db
9 changed files with 393 additions and 294 deletions

View File

@@ -7,6 +7,9 @@
import * as vscode from 'vscode';
import type { AuthenticateUpdateNotification } from '../types/acpTypes.js';
// Store reference to the authentication notification to allow auto-closing
let authNotificationDisposable: { dispose: () => void } | null = null;
/**
* Handle authentication update notifications by showing a VS Code notification
* with the authentication URI and a copy button.
@@ -18,23 +21,49 @@ export function handleAuthenticateUpdate(
): void {
const authUri = data._meta.authUri;
// Dismiss any existing authentication notification
if (authNotificationDisposable) {
authNotificationDisposable.dispose();
authNotificationDisposable = null;
}
// Show an information message with the auth URI and copy button
vscode.window
.showInformationMessage(
`Qwen Code needs authentication. Click the button below to open the authentication page or copy the link to your browser.`,
'Open in Browser',
'Copy Link',
)
.then((selection) => {
if (selection === 'Open in Browser') {
// Open the authentication URI in the default browser
vscode.env.openExternal(vscode.Uri.parse(authUri));
} else if (selection === 'Copy Link') {
// Copy the authentication URI to clipboard
vscode.env.clipboard.writeText(authUri);
vscode.window.showInformationMessage(
'Authentication link copied to clipboard!',
);
}
});
const notificationPromise = vscode.window.showInformationMessage(
`Qwen Code needs authentication. Click the button below to open the authentication page or copy the link to your browser.`,
'Open in Browser',
'Copy Link',
);
// Create a simple disposable object
authNotificationDisposable = {
dispose: () => {
// We can't actually cancel the promise, but we can clear our reference
},
};
notificationPromise.then((selection) => {
if (selection === 'Open in Browser') {
// Open the authentication URI in the default browser
vscode.env.openExternal(vscode.Uri.parse(authUri));
} else if (selection === 'Copy Link') {
// Copy the authentication URI to clipboard
vscode.env.clipboard.writeText(authUri);
vscode.window.showInformationMessage(
'Authentication link copied to clipboard!',
);
}
// Clear the notification reference after user interaction
authNotificationDisposable = null;
});
}
/**
* Dismiss the authentication notification if it's currently shown
*/
export function dismissAuthenticateUpdate(): void {
if (authNotificationDisposable) {
authNotificationDisposable.dispose();
authNotificationDisposable = null;
}
}