73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
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;
|
|
|
|
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',
|
|
new QuickAccessTreeProvider()
|
|
)
|
|
);
|
|
|
|
this.startDevStarHome();
|
|
}
|
|
|
|
async startDevStarHome() {
|
|
vscode.commands.executeCommand('devstar.showHome');
|
|
}
|
|
|
|
|
|
registerGlobalCommands(context: vscode.ExtensionContext) {
|
|
context.subscriptions.push(
|
|
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)
|
|
})
|
|
);
|
|
}
|
|
}
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
return new DevStarExtension(context);
|
|
}
|
|
|
|
export function deactivate() {
|
|
}
|