feat: support open with vscode url in devstar web
This commit is contained in:
		@@ -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": [
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								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)
 | 
			
		||||
      })
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user