Skip to content

Commit

Permalink
feat: devbox status
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhiter committed Nov 12, 2024
1 parent 5c2340f commit 3c624aa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion extensions/ide/vscode/devbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions extensions/ide/vscode/devbox/src/api/devbox.ts
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 5 additions & 3 deletions extensions/ide/vscode/devbox/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,53 @@ class MyTreeDataProvider implements vscode.TreeDataProvider<MyTreeItem> {
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<void> {
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 = [
{
Expand Down Expand Up @@ -267,7 +279,8 @@ class MyTreeDataProvider implements vscode.TreeDataProvider<MyTreeItem> {
namespace,
devboxName,
devbox.host,
devbox.remotePath
devbox.remotePath,
devbox.iconPath
)
treeItem.contextValue = 'devbox'
return treeItem
Expand Down

0 comments on commit 3c624aa

Please sign in to comment.