2024-07-11 12:42:23 +08:00
|
|
|
import * as vscode from 'vscode';
|
2024-07-01 12:25:28 +08:00
|
|
|
import QuickAccessTreeProvider from './views/quick-access-tree';
|
2024-07-16 23:28:56 +08:00
|
|
|
import DSHome from './home';
|
2025-02-26 00:47:00 +08:00
|
|
|
import RemoteContainer, {openProjectWithoutLogging} from './remote-container';
|
|
|
|
import User from './user';
|
2024-06-27 01:20:37 +08:00
|
|
|
|
2024-09-18 13:52:19 +08:00
|
|
|
export class DevStarExtension {
|
2025-02-26 00:47:00 +08:00
|
|
|
user: User;
|
|
|
|
remoteContainer: RemoteContainer;
|
2024-07-16 23:28:56 +08:00
|
|
|
dsHome: DSHome;
|
2024-06-27 01:20:37 +08:00
|
|
|
|
2024-07-02 12:15:39 +08:00
|
|
|
constructor(private context: vscode.ExtensionContext) {
|
2025-02-26 00:47:00 +08:00
|
|
|
this.user = new User(context);
|
|
|
|
this.remoteContainer = new RemoteContainer(this.user);
|
2025-02-19 10:16:46 +08:00
|
|
|
|
|
|
|
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');
|
2025-02-26 00:47:00 +08:00
|
|
|
const access_token = params.get('access_token');
|
|
|
|
const devstar_username = params.get('devstar_username');
|
2025-02-19 10:16:46 +08:00
|
|
|
|
2025-02-25 11:43:06 +08:00
|
|
|
if (host && port && username && path) {
|
2025-02-26 00:47:00 +08:00
|
|
|
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)
|
2025-02-26 11:04:36 +08:00
|
|
|
// 使用登录已经登录过的容器连接方法
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
})
|
2025-02-26 00:47:00 +08:00
|
|
|
} else if (devstar_username === this.user.getUsernameFromLocal()){
|
2025-02-26 11:04:36 +08:00
|
|
|
// 如果同用户已经登录,则忽略;
|
|
|
|
// 使用登录已经登录过的容器连接方法
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
})
|
2025-02-26 00:47:00 +08:00
|
|
|
} 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);
|
2025-02-26 11:04:36 +08:00
|
|
|
// 使用登录已经登录过的容器连接方法
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
})
|
2025-02-26 00:47:00 +08:00
|
|
|
} else if (selection === 'No') {
|
|
|
|
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
|
|
|
|
}
|
2025-02-25 11:43:06 +08:00
|
|
|
|
2025-02-26 11:04:36 +08:00
|
|
|
}
|
2025-02-26 00:47:00 +08:00
|
|
|
} else {
|
|
|
|
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
|
|
|
|
}
|
2025-02-19 10:16:46 +08:00
|
|
|
} else {
|
|
|
|
vscode.window.showErrorMessage('Missing required parameters.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
context.subscriptions.push(handler);
|
|
|
|
|
2024-07-02 12:15:39 +08:00
|
|
|
context.subscriptions.push(
|
2024-06-27 01:20:37 +08:00
|
|
|
vscode.window.registerTreeDataProvider(
|
2024-07-16 23:28:56 +08:00
|
|
|
'devstar.quickAccess',
|
2024-06-27 01:20:37 +08:00
|
|
|
new QuickAccessTreeProvider()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2025-02-26 00:47:00 +08:00
|
|
|
this.dsHome = new DSHome(context);
|
|
|
|
this.registerGlobalCommands(context);
|
|
|
|
|
2024-09-18 13:52:19 +08:00
|
|
|
this.startDevStarHome();
|
2024-06-27 01:20:37 +08:00
|
|
|
}
|
|
|
|
|
2024-09-18 13:52:19 +08:00
|
|
|
async startDevStarHome() {
|
2024-07-16 23:28:56 +08:00
|
|
|
vscode.commands.executeCommand('devstar.showHome');
|
2024-06-27 01:20:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-02 12:15:39 +08:00
|
|
|
registerGlobalCommands(context: vscode.ExtensionContext) {
|
|
|
|
context.subscriptions.push(
|
2024-07-16 23:28:56 +08:00
|
|
|
vscode.commands.registerCommand('devstar.showHome', (url: string) =>
|
|
|
|
this.dsHome.toggle(url)
|
2025-02-25 11:43:06 +08:00
|
|
|
)
|
2024-06-27 01:20:37 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 12:15:39 +08:00
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
2024-09-18 13:52:19 +08:00
|
|
|
return new DevStarExtension(context);
|
2024-06-27 01:20:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function deactivate() {
|
|
|
|
}
|