feat: support cmd parameter to use correct IDE CLI
This commit is contained in:
16
src/main.ts
16
src/main.ts
@@ -67,6 +67,7 @@ export class DevStarExtension {
|
|||||||
const accessToken = params.get('access_token');
|
const accessToken = params.get('access_token');
|
||||||
const devstarUsername = params.get('devstar_username');
|
const devstarUsername = params.get('devstar_username');
|
||||||
const rawDevstarDomain = params.get('devstar_domain');
|
const rawDevstarDomain = params.get('devstar_domain');
|
||||||
|
const cmd = params.get('cmd') || 'code'; // 获取 cmd 参数,默认为 code
|
||||||
let devstarDomain = rawDevstarDomain;
|
let devstarDomain = rawDevstarDomain;
|
||||||
if (rawDevstarDomain) {
|
if (rawDevstarDomain) {
|
||||||
try {
|
try {
|
||||||
@@ -123,11 +124,11 @@ export class DevStarExtension {
|
|||||||
// 如果没有用户登录,则直接登录;
|
// 如果没有用户登录,则直接登录;
|
||||||
const res = await this.user.login(accessToken, devstarUsername)
|
const res = await this.user.login(accessToken, devstarUsername)
|
||||||
if (res === 'ok') {
|
if (res === 'ok') {
|
||||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context, cmd)
|
||||||
}
|
}
|
||||||
} else if (devstarUsername === this.user.getUsernameFromLocal()) {
|
} else if (devstarUsername === this.user.getUsernameFromLocal()) {
|
||||||
// 如果同用户已经登录,则忽略,直接打开项目
|
// 如果同用户已经登录,则忽略,直接打开项目
|
||||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context, cmd)
|
||||||
} else {
|
} else {
|
||||||
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
||||||
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
||||||
@@ -136,14 +137,14 @@ export class DevStarExtension {
|
|||||||
// 如果没有用户登录,则直接登录;
|
// 如果没有用户登录,则直接登录;
|
||||||
const res = await this.user.login(accessToken, devstarUsername)
|
const res = await this.user.login(accessToken, devstarUsername)
|
||||||
if (res === 'ok') {
|
if (res === 'ok') {
|
||||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context, cmd)
|
||||||
}
|
}
|
||||||
} else if (selection === 'No') {
|
} else if (selection === 'No') {
|
||||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath);
|
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath);
|
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath, cmd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vscode.window.showErrorMessage('Missing required parameters.');
|
vscode.window.showErrorMessage('Missing required parameters.');
|
||||||
@@ -160,6 +161,7 @@ export class DevStarExtension {
|
|||||||
const username = params.get('username');
|
const username = params.get('username');
|
||||||
const path = params.get('path');
|
const path = params.get('path');
|
||||||
const devstarDomain = params.get('devstar_domain')
|
const devstarDomain = params.get('devstar_domain')
|
||||||
|
const cmd = params.get('cmd') || 'code'; // 获取 cmd 参数,默认为 code
|
||||||
|
|
||||||
if (host && hostname && port && username && path) {
|
if (host && hostname && port && username && path) {
|
||||||
const container_host = host;
|
const container_host = host;
|
||||||
@@ -179,10 +181,10 @@ export class DevStarExtension {
|
|||||||
// 将devstar domain存在global state中
|
// 将devstar domain存在global state中
|
||||||
context.globalState.update('devstarDomain', devstarDomain)
|
context.globalState.update('devstarDomain', devstarDomain)
|
||||||
|
|
||||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context, cmd)
|
||||||
} else {
|
} else {
|
||||||
// devstarDomain参数不存在,则不存储,使用默认用户配置
|
// devstarDomain参数不存在,则不存储,使用默认用户配置
|
||||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context, cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default class RemoteContainer {
|
|||||||
/**
|
/**
|
||||||
* 第一次打开远程项目
|
* 第一次打开远程项目
|
||||||
*/
|
*/
|
||||||
async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string, context: vscode.ExtensionContext) {
|
async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string, context: vscode.ExtensionContext, cmd: string = 'code') {
|
||||||
if (vscode.env.remoteName) {
|
if (vscode.env.remoteName) {
|
||||||
try {
|
try {
|
||||||
await vscode.commands.executeCommand('workbench.action.terminal.newLocal');
|
await vscode.commands.executeCommand('workbench.action.terminal.newLocal');
|
||||||
@@ -76,7 +76,7 @@ export default class RemoteContainer {
|
|||||||
await this.firstConnect(host, hostname, username, port, path)
|
await this.firstConnect(host, hostname, username, port, path)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res === 'success') {
|
if (res === 'success') {
|
||||||
this.openRemoteFolder(host, port, username, path, context);
|
this.openRemoteFolder(host, port, username, path, context, cmd);
|
||||||
} else {
|
} else {
|
||||||
vscode.window.showErrorMessage('首次连接容器失败,请检查网络和容器状态。');
|
vscode.window.showErrorMessage('首次连接容器失败,请检查网络和容器状态。');
|
||||||
}
|
}
|
||||||
@@ -352,7 +352,7 @@ export default class RemoteContainer {
|
|||||||
/**
|
/**
|
||||||
* local env
|
* local env
|
||||||
*/
|
*/
|
||||||
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext): Promise<void> {
|
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext, cmd: string = 'code'): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const sshConfig = await this.getSSHConfig(host);
|
const sshConfig = await this.getSSHConfig(host);
|
||||||
if (sshConfig) {
|
if (sshConfig) {
|
||||||
@@ -368,7 +368,7 @@ export default class RemoteContainer {
|
|||||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
||||||
terminal.show(true);
|
terminal.show(true);
|
||||||
|
|
||||||
const command = `code --remote ssh-remote+root@${host}:${port} ${path} --reuse-window`;
|
const command = `${cmd} --remote ssh-remote+root@${host}:${port} ${path} --reuse-window`;
|
||||||
|
|
||||||
terminal.sendText(command);
|
terminal.sendText(command);
|
||||||
|
|
||||||
@@ -461,8 +461,8 @@ export default class RemoteContainer {
|
|||||||
/**
|
/**
|
||||||
* 打开项目(无须插件登录)
|
* 打开项目(无须插件登录)
|
||||||
*/
|
*/
|
||||||
export async function openProjectWithoutLogging(hostname: string, port: number, username: string, path: string): Promise<void> {
|
export async function openProjectWithoutLogging(hostname: string, port: number, username: string, path: string, cmd: string = 'code'): Promise<void> {
|
||||||
const command = `code --remote ssh-remote+${username}@${hostname}:${port} ${path} --reuse-window`;
|
const command = `${cmd} --remote ssh-remote+${username}@${hostname}:${port} ${path} --reuse-window`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
||||||
|
|||||||
Reference in New Issue
Block a user