From 73a1510de459a3128c4444d0803c8b09e3bd7afd Mon Sep 17 00:00:00 2001 From: Roe-xin Date: Wed, 14 Jan 2026 18:32:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension.ts | 8 ++----- src/panels/ICHelperPanel.ts | 4 ++++ src/views/userInfoComponent.ts | 42 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index e6c5f74..ec7ae25 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -157,12 +157,8 @@ export function activate(context: vscode.ExtensionContext) { try { const session = await vscode.authentication.getSession("iccoder", [], { createIfNone: false }); if (session) { - // 通过创建新会话并清除偏好来实现登出 - await vscode.authentication.getSession("iccoder", [], { - clearSessionPreference: true, - forceNewSession: true - }); - vscode.window.showInformationMessage("已退出登录"); + // 调用 authProvider 的 removeSession 方法 + await authProvider.removeSession(session.id); } else { vscode.window.showInformationMessage("当前未登录"); } diff --git a/src/panels/ICHelperPanel.ts b/src/panels/ICHelperPanel.ts index a31e328..03285f8 100644 --- a/src/panels/ICHelperPanel.ts +++ b/src/panels/ICHelperPanel.ts @@ -340,6 +340,10 @@ export async function showICHelperPanel( }); } break; + case "logout": + // 退出登录 + vscode.commands.executeCommand("ic-coder.logout"); + break; // 处理计划操作(只做模式切换,响应已通过 submitAnswer 发送) case "planAction": if (message.action === "confirm") { diff --git a/src/views/userInfoComponent.ts b/src/views/userInfoComponent.ts index 95bb043..1943b52 100644 --- a/src/views/userInfoComponent.ts +++ b/src/views/userInfoComponent.ts @@ -30,6 +30,9 @@ export function getUserInfoComponentContent(): string { 剩余 Credits - +
+ +
@@ -180,6 +183,31 @@ export function getUserInfoComponentStyles(): string { object-fit: contain; border-radius: 4px; } + + .logout { + margin-top: 8px; + } + + .logout-btn { + width: 100%; + padding: 8px 12px; + background: var(--vscode-button-background); + color: var(--vscode-button-foreground); + border: none; + border-radius: 6px; + cursor: pointer; + font-size: 12px; + font-weight: 500; + transition: all 0.2s ease; + } + + .logout-btn:hover { + background: var(--vscode-button-hoverBackground); + } + + .logout-btn:active { + transform: scale(0.98); + } `; } @@ -214,6 +242,12 @@ export function getUserInfoComponentScript(): string { } } + // 退出登录 + function logout() { + console.log("退出登录"); + vscode.postMessage({ command: 'logout' }); + } + // 关闭用户详情下拉面板 function closeUserDetailModal() { const dropdown = document.getElementById('userDetailDropdown'); @@ -275,6 +309,14 @@ export function getUserInfoComponentScript(): string { // 绑定下拉面板事件 document.addEventListener('DOMContentLoaded', () => { + // 绑定退出登录按钮 + const logoutBtn = document.getElementById('logoutBtn'); + if (logoutBtn) { + logoutBtn.addEventListener('click', () => { + logout(); + }); + } + // 点击页面其他地方关闭下拉面板 document.addEventListener('click', (e) => { const dropdown = document.getElementById('userDetailDropdown');