revert: 取消功能【避免打开同一个项目】
This commit is contained in:
21
src/home.ts
21
src/home.ts
@@ -68,29 +68,12 @@ export default class DSHome {
|
|||||||
panel.webview.postMessage({ command: 'getUsername', data: { username: username } })
|
panel.webview.postMessage({ command: 'getUsername', data: { username: username } })
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'getCurrentHost':
|
|
||||||
let currentHost = null
|
|
||||||
if (vscode.env.remoteName) {
|
|
||||||
// 远程环境,需要确认当前host名称(项目名称)
|
|
||||||
const currentHostRecorded = this.context.globalState.get('currentHost')
|
|
||||||
currentHost = currentHostRecorded != undefined ? currentHostRecorded : ""
|
|
||||||
} else {
|
|
||||||
// 如果当前是本地环境,则没有限制
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null == currentHost || "" == currentHost) {
|
|
||||||
panel.webview.postMessage({ command: 'getCurrentHost', data: {currentHost: ''}})
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
panel.webview.postMessage({ command: 'getCurrentHost', data: {currentHost: currentHost}})
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'firstOpenRemoteFolder':
|
case 'firstOpenRemoteFolder':
|
||||||
// data.host - project name
|
// data.host - project name
|
||||||
await this.remoteContainer.firstOpenProject(data.host, data.hostname, data.port, data.username, data.path, this.context)
|
await this.remoteContainer.firstOpenProject(data.host, data.hostname, data.port, data.username, data.path)
|
||||||
break;
|
break;
|
||||||
case 'openRemoteFolder':
|
case 'openRemoteFolder':
|
||||||
this.remoteContainer.openRemoteFolder(data.host, data.port, data.username, data.path, this.context);
|
this.remoteContainer.openRemoteFolder(data.host, data.port, data.username, data.path);
|
||||||
break;
|
break;
|
||||||
case 'getDevstarDomain':
|
case 'getDevstarDomain':
|
||||||
panel.webview.postMessage({ command: 'getDevstarDomain', data: { devstarDomain: this.devstarDomain } })
|
panel.webview.postMessage({ command: 'getDevstarDomain', data: { devstarDomain: this.devstarDomain } })
|
||||||
|
23
src/main.ts
23
src/main.ts
@@ -45,14 +45,11 @@ export class DevStarExtension {
|
|||||||
// 如果没有用户登录,则直接登录;
|
// 如果没有用户登录,则直接登录;
|
||||||
const res = await this.user.login(access_token, devstar_username)
|
const res = await this.user.login(access_token, devstar_username)
|
||||||
if (res === 'ok') {
|
if (res === 'ok') {
|
||||||
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)
|
||||||
}
|
}
|
||||||
} else if (devstar_username === this.user.getUsernameFromLocal()) {
|
} else if (devstar_username === this.user.getUsernameFromLocal()) {
|
||||||
// 如果同用户已经登录,则忽略,直接打开项目
|
// 如果同用户已经登录,则忽略,直接打开项目
|
||||||
// 检查项目是否已经打开
|
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path)
|
||||||
if (!this.isSameProject(container_host, this.context)) {
|
|
||||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
||||||
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
||||||
@@ -61,7 +58,7 @@ export class DevStarExtension {
|
|||||||
// 如果没有用户登录,则直接登录;
|
// 如果没有用户登录,则直接登录;
|
||||||
const res = await this.user.login(access_token, devstar_username)
|
const res = await this.user.login(access_token, devstar_username)
|
||||||
if (res === 'ok') {
|
if (res === 'ok') {
|
||||||
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)
|
||||||
}
|
}
|
||||||
} else if (selection === 'No') {
|
} else if (selection === 'No') {
|
||||||
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
|
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
|
||||||
@@ -89,7 +86,7 @@ export class DevStarExtension {
|
|||||||
const container_username = username;
|
const container_username = username;
|
||||||
const project_path = decodeURIComponent(path);
|
const project_path = decodeURIComponent(path);
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,18 +106,6 @@ export class DevStarExtension {
|
|||||||
this.startDevStarHome();
|
this.startDevStarHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
isSameProject(project_name: string, context: vscode.ExtensionContext) {
|
|
||||||
// 远程环境且目标项目名称==currentHost,则提示项目已经打开
|
|
||||||
if (vscode.env.remoteName) {
|
|
||||||
const currentHostRecorded = context.globalState.get('currentHost')
|
|
||||||
const currentHost = currentHostRecorded != undefined ? currentHostRecorded : ""
|
|
||||||
if (currentHost == project_name) {
|
|
||||||
vscode.window.showWarningMessage(vscode.l10n.t("Project has been open!"))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async startDevStarHome() {
|
async startDevStarHome() {
|
||||||
vscode.commands.executeCommand('devstar.showHome');
|
vscode.commands.executeCommand('devstar.showHome');
|
||||||
|
@@ -27,7 +27,7 @@ export default class RemoteContainer {
|
|||||||
* @param path
|
* @param path
|
||||||
* @param context 用于支持远程项目环境
|
* @param context 用于支持远程项目环境
|
||||||
*/
|
*/
|
||||||
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) {
|
||||||
if (vscode.env.remoteName) {
|
if (vscode.env.remoteName) {
|
||||||
vscode.commands.executeCommand('workbench.action.terminal.newLocal').then(() => {
|
vscode.commands.executeCommand('workbench.action.terminal.newLocal').then(() => {
|
||||||
const terminal = vscode.window.terminals[vscode.window.terminals.length - 1];
|
const terminal = vscode.window.terminals[vscode.window.terminals.length - 1];
|
||||||
@@ -41,7 +41,7 @@ export default class RemoteContainer {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res === 'success') {
|
if (res === 'success') {
|
||||||
// only success then open folder
|
// only success then open folder
|
||||||
this.openRemoteFolder(host, port, username, path, context);
|
this.openRemoteFolder(host, port, username, path);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -167,16 +167,11 @@ export default class RemoteContainer {
|
|||||||
*
|
*
|
||||||
* @host 表示project name
|
* @host 表示project name
|
||||||
*/
|
*/
|
||||||
openRemoteFolder(host: string, port: number, username: string, path: string, context: vscode.ExtensionContext): void {
|
openRemoteFolder(host: string, port: number, username: string, path: string): void {
|
||||||
// local env
|
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
||||||
if (vscode.env.remoteName === undefined) {
|
terminal.show(true);
|
||||||
// 在打开之前,需要先将host的信息记录到global state中,让home能够确认打开的host是哪个project的
|
// 在原窗口打开
|
||||||
context.globalState.update('currentHost', host)
|
terminal.sendText(`code --remote ssh-remote+${username}@${host}:${port} ${path} --reuse-window`);
|
||||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
|
||||||
terminal.show(true);
|
|
||||||
// 在原窗口打开
|
|
||||||
terminal.sendText(`code --remote ssh-remote+${username}@${host}:${port} ${path} --reuse-window`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user