diff --git a/extensions/ide/vscode/devbox/package.json b/extensions/ide/vscode/devbox/package.json index df5908344e6..b15079738f7 100644 --- a/extensions/ide/vscode/devbox/package.json +++ b/extensions/ide/vscode/devbox/package.json @@ -2,7 +2,7 @@ "name": "devbox-aio", "displayName": "Devbox", "description": "help code for cloud devbox in sailos/sealos", - "version": "0.9.10", + "version": "0.9.11", "keywords": [ "devbox", "remote development", diff --git a/extensions/ide/vscode/devbox/src/api/devbox.ts b/extensions/ide/vscode/devbox/src/api/devbox.ts index 04b49384100..d458cf2d9c5 100644 --- a/extensions/ide/vscode/devbox/src/api/devbox.ts +++ b/extensions/ide/vscode/devbox/src/api/devbox.ts @@ -1,8 +1,14 @@ import { GET } from './index' export const getDevboxDetail = async (token: string) => { - const { devbox } = await GET('/api/v1/getDevboxDetail', { - authorization: token, - }) + const { devbox } = await GET( + '/api/v1/getDevboxDetail', + {}, + { + headers: { + Authorization: encodeURIComponent(token), + }, + } + ) return devbox } diff --git a/extensions/ide/vscode/devbox/src/api/index.ts b/extensions/ide/vscode/devbox/src/api/index.ts index 6ca22b4e117..1db6a4ebeee 100644 --- a/extensions/ide/vscode/devbox/src/api/index.ts +++ b/extensions/ide/vscode/devbox/src/api/index.ts @@ -80,9 +80,11 @@ request.interceptors.request.use( const workspaceFolder = workspaceFolders[0] const remoteUri = workspaceFolder.uri.authority const devboxId = remoteUri.replace(/^ssh-remote\+/, '') // devbox = sshHostLabel - _headers['Authorization'] = encodeURIComponent( - GlobalStateManager.getToken(devboxId) || '' - ) + if (!_headers['Authorization']) { + _headers['Authorization'] = encodeURIComponent( + GlobalStateManager.getToken(devboxId) || '' + ) + } } if (!config.headers || config.headers['Content-Type'] === '') { diff --git a/extensions/ide/vscode/devbox/src/providers/DevboxListViewProvider.ts b/extensions/ide/vscode/devbox/src/providers/DevboxListViewProvider.ts index 7a877ae73ab..a066b3c8989 100644 --- a/extensions/ide/vscode/devbox/src/providers/DevboxListViewProvider.ts +++ b/extensions/ide/vscode/devbox/src/providers/DevboxListViewProvider.ts @@ -77,41 +77,53 @@ class MyTreeDataProvider implements vscode.TreeDataProvider { constructor(treeName: string) { this.treeName = treeName this.refreshData() + if (this.treeName === 'devboxDashboard') { + setInterval(() => { + this.refresh() + }, 3 * 1000) + } } refresh(): void { this.refreshData() } - private refreshData(): void { + private async refreshData(): Promise { if (this.treeName === 'devboxDashboard') { convertSSHConfigToVersion2(defaultDevboxSSHConfigPath) - parseSSHConfig(defaultDevboxSSHConfigPath).then((data) => { - this.treeData = data as DevboxListItem[] - this._onDidChangeTreeData.fire(undefined) - }) - this.treeData.forEach(async (item) => { - const token = GlobalStateManager.getToken(item.host) - if (!token) { - return - } - // get devbox detail - const data = await getDevboxDetail(token) - const status = data.status.value - switch (status) { - case 'Running': - item.iconPath = new vscode.ThemeIcon('vm-running') - break - case 'Stopped': - item.iconPath = new vscode.ThemeIcon('vm') - break - case 'Error': - item.iconPath = new vscode.ThemeIcon('error') - break - default: - item.iconPath = new vscode.ThemeIcon('question') - } - }) + const data = await parseSSHConfig(defaultDevboxSSHConfigPath) + this.treeData = data as DevboxListItem[] + + await Promise.all( + this.treeData.map(async (item) => { + const token = GlobalStateManager.getToken(item.host) + if (!token) { + return + } + try { + const data = await getDevboxDetail(token) + const status = data.status.value + switch (status) { + case 'Running': + item.iconPath = new vscode.ThemeIcon('debug-start') + break + case 'Stopped': + item.iconPath = new vscode.ThemeIcon('debug-pause') + break + case 'Error': + item.iconPath = new vscode.ThemeIcon('error') + break + default: + item.iconPath = new vscode.ThemeIcon('question') + } + } catch (error) { + console.error(`get devbox detail failed: ${error}`) + item.iconPath = new vscode.ThemeIcon('warning') + } + }) + ) + + this._onDidChangeTreeData.fire(undefined) } else if (this.treeName === 'devboxFeedback') { this.treeData = [ { @@ -267,7 +279,8 @@ class MyTreeDataProvider implements vscode.TreeDataProvider { namespace, devboxName, devbox.host, - devbox.remotePath + devbox.remotePath, + devbox.iconPath ) treeItem.contextValue = 'devbox' return treeItem