feat: support link that open with code to carry access token
This commit is contained in:
		
							
								
								
									
										50
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								src/main.ts
									
									
									
									
									
								
							@@ -1,15 +1,17 @@
 | 
				
			|||||||
import * as vscode from 'vscode';
 | 
					import * as vscode from 'vscode';
 | 
				
			||||||
import QuickAccessTreeProvider from './views/quick-access-tree';
 | 
					import QuickAccessTreeProvider from './views/quick-access-tree';
 | 
				
			||||||
import DSHome from './home';
 | 
					import DSHome from './home';
 | 
				
			||||||
import {openProjectWithoutLogging} from './remote-container';
 | 
					import RemoteContainer, {openProjectWithoutLogging} from './remote-container';
 | 
				
			||||||
 | 
					import User from './user';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class DevStarExtension {
 | 
					export class DevStarExtension {
 | 
				
			||||||
 | 
					  user: User;
 | 
				
			||||||
 | 
					  remoteContainer: RemoteContainer;
 | 
				
			||||||
  dsHome: DSHome;
 | 
					  dsHome: DSHome;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(private context: vscode.ExtensionContext) {
 | 
					  constructor(private context: vscode.ExtensionContext) {
 | 
				
			||||||
    this.dsHome = new DSHome(context);
 | 
					    this.user = new User(context);
 | 
				
			||||||
 | 
					    this.remoteContainer = new RemoteContainer(this.user);
 | 
				
			||||||
    this.registerGlobalCommands(context);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const handler = vscode.window.registerUriHandler({
 | 
					    const handler = vscode.window.registerUriHandler({
 | 
				
			||||||
      handleUri: async (uri: vscode.Uri) => {
 | 
					      handleUri: async (uri: vscode.Uri) => {
 | 
				
			||||||
@@ -19,10 +21,45 @@ export class DevStarExtension {
 | 
				
			|||||||
          const port = params.get('port');
 | 
					          const port = params.get('port');
 | 
				
			||||||
          const username = params.get('username');
 | 
					          const username = params.get('username');
 | 
				
			||||||
          const path = params.get('path');
 | 
					          const path = params.get('path');
 | 
				
			||||||
 | 
					          const access_token = params.get('access_token');
 | 
				
			||||||
 | 
					          const devstar_username = params.get('devstar_username');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (host && port && username && path) {
 | 
					          if (host && port && username && path) {
 | 
				
			||||||
            await openProjectWithoutLogging(host, parseInt(port, 10), username, decodeURIComponent(path))
 | 
					            const container_host = host;
 | 
				
			||||||
 | 
					            const container_port = parseInt(port, 10);
 | 
				
			||||||
 | 
					            const container_username = username;
 | 
				
			||||||
 | 
					            const project_path = decodeURIComponent(path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (access_token && devstar_username) {
 | 
				
			||||||
 | 
					              if (!this.user.isLogged()) {
 | 
				
			||||||
 | 
					                // 如果没有用户登录,则直接登录;
 | 
				
			||||||
 | 
					                this.user.setUserTokenToLocal(access_token)
 | 
				
			||||||
 | 
					                this.user.setUsernameToLocal(devstar_username)
 | 
				
			||||||
 | 
					              } else if (devstar_username === this.user.getUsernameFromLocal()){
 | 
				
			||||||
 | 
					                // 如果同用户已经登录,则弃用,无操作;
 | 
				
			||||||
 | 
					              } else {
 | 
				
			||||||
 | 
					                // 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
 | 
				
			||||||
 | 
					                const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
 | 
				
			||||||
 | 
					                 'Yes', 'No',);
 | 
				
			||||||
 | 
					                if (selection === 'Yes') {
 | 
				
			||||||
 | 
					                  this.user.setUserTokenToLocal(access_token);
 | 
				
			||||||
 | 
					                  this.user.setUsernameToLocal(devstar_username);
 | 
				
			||||||
 | 
					                } else if (selection === 'No') {
 | 
				
			||||||
 | 
					                  await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              // 使用登录已经登录过的容器连接方法
 | 
				
			||||||
 | 
					              await this.remoteContainer.firstConnect(container_host, container_username, container_port)
 | 
				
			||||||
 | 
					                .then((_res) => {
 | 
				
			||||||
 | 
					                  if (_res == 'success') {
 | 
				
			||||||
 | 
					                    //  only success then open folder
 | 
				
			||||||
 | 
					                    this.remoteContainer.openRemoteFolder(container_host, container_port, container_username, project_path);
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            vscode.window.showErrorMessage('Missing required parameters.');
 | 
					            vscode.window.showErrorMessage('Missing required parameters.');
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
@@ -39,6 +76,9 @@ export class DevStarExtension {
 | 
				
			|||||||
      )
 | 
					      )
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.dsHome = new DSHome(context);
 | 
				
			||||||
 | 
					    this.registerGlobalCommands(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.startDevStarHome();
 | 
					    this.startDevStarHome();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user