From f9c9fa1840c0654cac95f69e36ae4a258c8e9910 Mon Sep 17 00:00:00 2001 From: Roe-xin Date: Mon, 29 Dec 2025 18:52:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E6=B7=BB=E5=8A=A0=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=8A=B6=E6=80=81=E6=A3=80=E6=9F=A5=EF=BC=8C=20-=20?= =?UTF-8?q?=E6=9C=AA=E7=99=BB=E5=BD=95=E6=97=B6=E4=B8=8D=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=89=93=E5=BC=80=E9=9D=A2=E6=9D=BF=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=89=93=E5=BC=80=E4=B9=9F=E4=BC=9A=E6=98=BE=E7=A4=BA=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=99=BB=E5=BD=95=20-=20=E7=99=BB=E5=BD=95=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E5=B0=B1=E5=9B=9E=E8=87=AA=E5=8A=A8=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension.ts | 11 +++++++++-- src/panels/ICHelperPanel.ts | 20 ++++++++++++++++++++ src/services/icCoderAuthProvider.ts | 4 ++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a4079ba..9abe301 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -18,8 +18,15 @@ export function activate(context: vscode.ExtensionContext) { ) ); - // 自动打开聊天面板 - vscode.commands.executeCommand("ic-coder.openChat"); + // 检查登录状态,如果已登录则自动打开聊天面板 + vscode.authentication.getSession("iccoder", [], { createIfNone: false }) + .then((session) => { + if (session) { + vscode.commands.executeCommand("ic-coder.openChat"); + } + }, () => { + // 未登录,不做任何操作 + }); // 注册命令:打开助手面板 const openPanelCommand = vscode.commands.registerCommand( diff --git a/src/panels/ICHelperPanel.ts b/src/panels/ICHelperPanel.ts index e85198c..f9d227e 100644 --- a/src/panels/ICHelperPanel.ts +++ b/src/panels/ICHelperPanel.ts @@ -21,6 +21,26 @@ export async function showICHelperPanel( context: vscode.ExtensionContext, viewColumn?: vscode.ViewColumn ) { + // 检查用户是否已登录 + try { + const session = await vscode.authentication.getSession("iccoder", [], { createIfNone: false }); + if (!session) { + vscode.window.showWarningMessage("请先登录后再使用 IC Coder", "立即登录").then((selection) => { + if (selection === "立即登录") { + vscode.commands.executeCommand("ic-coder.login"); + } + }); + return; + } + } catch (error) { + vscode.window.showWarningMessage("请先登录后再使用 IC Coder", "立即登录").then((selection) => { + if (selection === "立即登录") { + vscode.commands.executeCommand("ic-coder.login"); + } + }); + return; + } + // 创建WebView面板 const panel = vscode.window.createWebviewPanel( "icCoder", // 面板ID diff --git a/src/services/icCoderAuthProvider.ts b/src/services/icCoderAuthProvider.ts index 02d56b0..05c8a3c 100644 --- a/src/services/icCoderAuthProvider.ts +++ b/src/services/icCoderAuthProvider.ts @@ -49,8 +49,8 @@ export class ICCoderAuthenticationProvider */ async getSessions( scopes?: readonly string[] - ): Promise { - return this._sessions; + ): Promise { + return [...this._sessions]; } /**