Add account button to top nav bar

This commit is contained in:
pashpashpash 2025-01-21 19:39:40 -08:00
parent a88d45d8b4
commit 7e3a770a4c
6 changed files with 50 additions and 1 deletions

View File

@ -90,6 +90,11 @@
"title": "Settings", "title": "Settings",
"icon": "$(settings-gear)" "icon": "$(settings-gear)"
}, },
{
"command": "cline.accountButtonClicked",
"title": "Account",
"icon": "$(account)"
},
{ {
"command": "cline.openInNewTab", "command": "cline.openInNewTab",
"title": "Open In New Tab", "title": "Open In New Tab",
@ -122,6 +127,11 @@
"command": "cline.settingsButtonClicked", "command": "cline.settingsButtonClicked",
"group": "navigation@5", "group": "navigation@5",
"when": "view == claude-dev.SidebarProvider" "when": "view == claude-dev.SidebarProvider"
},
{
"command": "cline.accountButtonClicked",
"group": "navigation@6",
"when": "view == claude-dev.SidebarProvider"
} }
] ]
}, },

View File

@ -43,6 +43,7 @@ type SecretKey =
| "openAiNativeApiKey" | "openAiNativeApiKey"
| "deepSeekApiKey" | "deepSeekApiKey"
| "mistralApiKey" | "mistralApiKey"
| "authToken"
type GlobalStateKey = type GlobalStateKey =
| "apiProvider" | "apiProvider"
| "apiModelId" | "apiModelId"
@ -594,6 +595,12 @@ export class ClineProvider implements vscode.WebviewViewProvider {
case "getLatestState": case "getLatestState":
await this.postStateToWebview() await this.postStateToWebview()
break break
case "accountButtonClicked":
// Open browser for authentication
console.log("Account button clicked in top nav bar")
console.log("Opening auth page: https://cline.bot/auth")
vscode.env.openExternal(vscode.Uri.parse('https://cline.bot/auth'))
break
case "openMcpSettings": { case "openMcpSettings": {
const mcpSettingsFilePath = await this.mcpHub?.getMcpSettingsFilePath() const mcpSettingsFilePath = await this.mcpHub?.getMcpSettingsFilePath()
if (mcpSettingsFilePath) { if (mcpSettingsFilePath) {
@ -740,6 +747,15 @@ export class ClineProvider implements vscode.WebviewViewProvider {
} }
} }
// Auth
async handleAuthCallback(token: string) {
// Store the auth token securely
await this.storeSecret("authToken", token)
await this.postStateToWebview()
vscode.window.showInformationMessage("Successfully logged in to Cline")
}
// OpenRouter // OpenRouter
async handleOpenRouterCallback(code: string) { async handleOpenRouterCallback(code: string) {
@ -1014,6 +1030,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
browserSettings, browserSettings,
chatSettings, chatSettings,
} = await this.getState() } = await this.getState()
const authToken = await this.getSecret("authToken")
return { return {
version: this.context.extension?.packageJSON?.version ?? "", version: this.context.extension?.packageJSON?.version ?? "",
apiConfiguration, apiConfiguration,
@ -1027,6 +1045,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
autoApprovalSettings, autoApprovalSettings,
browserSettings, browserSettings,
chatSettings, chatSettings,
isLoggedIn: !!authToken,
} }
} }
@ -1279,6 +1298,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
"openAiNativeApiKey", "openAiNativeApiKey",
"deepSeekApiKey", "deepSeekApiKey",
"mistralApiKey", "mistralApiKey",
"authToken",
] ]
for (const key of secretKeys) { for (const key of secretKeys) {
await this.storeSecret(key, undefined) await this.storeSecret(key, undefined)

View File

@ -110,6 +110,15 @@ export function activate(context: vscode.ExtensionContext) {
}), }),
) )
context.subscriptions.push(
vscode.commands.registerCommand("cline.accountButtonClicked", () => {
sidebarProvider.postMessageToWebview({
type: "action",
action: "accountButtonClicked",
})
}),
)
/* /*
We use the text document content provider API to show the left side for diff view by creating a virtual document for the original content. This makes it readonly so users know to edit the right side if they want to keep their changes. We use the text document content provider API to show the left side for diff view by creating a virtual document for the original content. This makes it readonly so users know to edit the right side if they want to keep their changes.
@ -140,6 +149,13 @@ export function activate(context: vscode.ExtensionContext) {
} }
break break
} }
case "/auth": {
const token = query.get("token")
if (token) {
await visibleProvider.handleAuthCallback(token)
}
break
}
default: default:
break break
} }

View File

@ -25,7 +25,7 @@ export interface ExtensionMessage {
| "vsCodeLmModels" | "vsCodeLmModels"
| "requestVsCodeLmModels" | "requestVsCodeLmModels"
text?: string text?: string
action?: "chatButtonClicked" | "mcpButtonClicked" | "settingsButtonClicked" | "historyButtonClicked" | "didBecomeVisible" action?: "chatButtonClicked" | "mcpButtonClicked" | "settingsButtonClicked" | "historyButtonClicked" | "didBecomeVisible" | "accountButtonClicked"
invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick"
state?: ExtensionState state?: ExtensionState
images?: string[] images?: string[]
@ -51,6 +51,7 @@ export interface ExtensionState {
autoApprovalSettings: AutoApprovalSettings autoApprovalSettings: AutoApprovalSettings
browserSettings: BrowserSettings browserSettings: BrowserSettings
chatSettings: ChatSettings chatSettings: ChatSettings
isLoggedIn: boolean
} }
export interface ClineMessage { export interface ClineMessage {

View File

@ -37,6 +37,7 @@ export interface WebviewMessage {
| "toggleToolAutoApprove" | "toggleToolAutoApprove"
| "toggleMcpServer" | "toggleMcpServer"
| "getLatestState" | "getLatestState"
| "accountButtonClicked"
// | "relaunchChromeDebugMode" // | "relaunchChromeDebugMode"
text?: string text?: string
disabled?: boolean disabled?: boolean

View File

@ -35,6 +35,7 @@ export const ExtensionStateContextProvider: React.FC<{
autoApprovalSettings: DEFAULT_AUTO_APPROVAL_SETTINGS, autoApprovalSettings: DEFAULT_AUTO_APPROVAL_SETTINGS,
browserSettings: DEFAULT_BROWSER_SETTINGS, browserSettings: DEFAULT_BROWSER_SETTINGS,
chatSettings: DEFAULT_CHAT_SETTINGS, chatSettings: DEFAULT_CHAT_SETTINGS,
isLoggedIn: false,
}) })
const [didHydrateState, setDidHydrateState] = useState(false) const [didHydrateState, setDidHydrateState] = useState(false)
const [showWelcome, setShowWelcome] = useState(false) const [showWelcome, setShowWelcome] = useState(false)