From 8772074ab23cd803d437ac9759f5adab65ddc7cd Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Wed, 19 Feb 2025 10:16:46 +0800 Subject: [PATCH] feat: support open with vscode url in devstar web --- package.json | 9 +++++++++ src/main.ts | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 87b4933..c14a326 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,17 @@ "command": "devstar.connectRemoteContainer", "title": "Connect to a Remote Container", "category": "DevStar" + }, + { + "command": "devstar.openProject", + "title": "Open Project", + "category": "DevStar" } ], + "uriHandlers": [{ + "protocol": "vscode", + "path": "/openProject" + }], "menus": { "file/newFile": [ { diff --git a/src/main.ts b/src/main.ts index 24d7bb9..6db0c2f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import QuickAccessTreeProvider from './views/quick-access-tree'; import DSHome from './home'; +import RemoteContainer from './remote-container'; export class DevStarExtension { dsHome: DSHome; @@ -8,6 +9,33 @@ export class DevStarExtension { constructor(private context: vscode.ExtensionContext) { this.dsHome = new DSHome(context); + this.registerGlobalCommands(context); + + const handler = vscode.window.registerUriHandler({ + handleUri: async (uri: vscode.Uri) => { + if (uri.path === '/openProject') { + const params = new URLSearchParams(uri.query); + const host = params.get('host'); + const port = params.get('port'); + const username = params.get('username'); + const path = params.get('path'); + + if (host && port && username && path) { + await vscode.commands.executeCommand('devstar.openProject', { + host: host, + port: parseInt(port, 10), + username: username, + path: decodeURIComponent(path) // 解码路径 + }); + } else { + vscode.window.showErrorMessage('Missing required parameters.'); + } + } + } + }); + + context.subscriptions.push(handler); + context.subscriptions.push( vscode.window.registerTreeDataProvider( 'devstar.quickAccess', @@ -15,8 +43,6 @@ export class DevStarExtension { ) ); - this.registerGlobalCommands(context); - this.startDevStarHome(); } @@ -30,6 +56,10 @@ export class DevStarExtension { vscode.commands.registerCommand('devstar.showHome', (url: string) => this.dsHome.toggle(url) ), + vscode.commands.registerCommand('devstar.openProject', (args) => { + const { host, port, username, path } = args; + RemoteContainer.openRemoteFolder(host, port, username, path) + }) ); } }