下载
This commit is contained in:
parent
5231b22181
commit
ba126f651d
@ -47,13 +47,8 @@ async function launch(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await vscode.window.withProgress({
|
await lspClient.activate(context, versionString);
|
||||||
location: vscode.ProgressLocation.Window,
|
await LspClient.DigitalIDE?.onReady();
|
||||||
title: t('progress.active-lsp-server')
|
|
||||||
}, async (progress: vscode.Progress<IProgress>, token: vscode.CancellationToken) => {
|
|
||||||
await lspClient.activate(context, progress, versionString);
|
|
||||||
await LspClient.DigitalIDE?.onReady();
|
|
||||||
});
|
|
||||||
|
|
||||||
await vscode.window.withProgress({
|
await vscode.window.withProgress({
|
||||||
location: vscode.ProgressLocation.Window,
|
location: vscode.ProgressLocation.Window,
|
||||||
|
@ -10,7 +10,7 @@ import * as path from 'path';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { platform } from "os";
|
import { platform } from "os";
|
||||||
import { IProgress, LspClient } from '../../global';
|
import { IProgress, LspClient } from '../../global';
|
||||||
import axios from "axios";
|
import axios, { AxiosResponse } from "axios";
|
||||||
import { getGiteeDownloadLink, getPlatformPlatformSignature } from "./cdn";
|
import { getGiteeDownloadLink, getPlatformPlatformSignature } from "./cdn";
|
||||||
|
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ function getLspServerExecutionName() {
|
|||||||
return 'digital-lsp';
|
return 'digital-lsp';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkAndDownload(context: vscode.ExtensionContext, progress: vscode.Progress<IProgress>, version: string): boolean {
|
async function checkAndDownload(context: vscode.ExtensionContext, version: string): boolean {
|
||||||
const { t } = vscode.l10n;
|
const { t } = vscode.l10n;
|
||||||
|
|
||||||
const versionFolderPath = context.asAbsolutePath(
|
const versionFolderPath = context.asAbsolutePath(
|
||||||
@ -35,22 +35,47 @@ async function checkAndDownload(context: vscode.ExtensionContext, progress: vsco
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 流式下载
|
await vscode.window.withProgress({
|
||||||
progress.report({ message: t('progress.download-digital-lsp') });
|
location: vscode.ProgressLocation.Notification,
|
||||||
const signature = getPlatformPlatformSignature().toString();
|
title: t('progress.download-digital-lsp')
|
||||||
const giteeDownloadLink = getGiteeDownloadLink(signature, version)
|
}, async (progress: vscode.Progress<IProgress>, token: vscode.CancellationToken) => {
|
||||||
console.log('download link ', giteeDownloadLink);
|
progress.report({ increment: 0 });
|
||||||
|
const signature = getPlatformPlatformSignature().toString();
|
||||||
|
const downloadLink = getGiteeDownloadLink(signature, version);
|
||||||
|
const response = await axios.get(downloadLink, { responseType: 'stream' });
|
||||||
|
|
||||||
const response = await axios.get(giteeDownloadLink, { responseType: 'stream' });
|
});
|
||||||
const totalLength = response.headers['content-length'];
|
|
||||||
console.log('totalLength ', totalLength);
|
|
||||||
|
|
||||||
|
function streamDownload(progress: vscode.Progress<IProgress>, response: AxiosResponse<any, any>): Promise<void> {
|
||||||
|
const totalLength = response.headers['content-length'];
|
||||||
|
const totalSize = parseInt(totalLength);
|
||||||
|
let downloadSize = 0;
|
||||||
|
const savePath = context.asAbsolutePath(
|
||||||
|
path.join('resources', 'dide-lsp', 'server', 'tmp.tar.gz')
|
||||||
|
);
|
||||||
|
const fileStream = fs.createWriteStream(savePath);
|
||||||
|
|
||||||
|
response.data.on('data', (chunk: Buffer) => {
|
||||||
|
downloadSize += chunk.length;
|
||||||
|
let increment = Math.ceil(downloadSize / totalSize * 100);
|
||||||
|
progress.report({ message: t('progress.download-digital-lsp'), increment });
|
||||||
|
});
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fileStream.on('finish', () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
fileStream.on('error', (error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function activate(context: vscode.ExtensionContext, progress: vscode.Progress<IProgress>, version: string) {
|
export async function activate(context: vscode.ExtensionContext, version: string) {
|
||||||
await checkAndDownload(context, progress, version);
|
await checkAndDownload(context, version);
|
||||||
|
|
||||||
|
|
||||||
const lspServerName = getLspServerExecutionName();
|
const lspServerName = getLspServerExecutionName();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user