Skip to content

Commit 2621fe7

Browse files
committed
optimize eide-binaries update process
1 parent 9a58a0e commit 2621fe7

2 files changed

Lines changed: 49 additions & 26 deletions

File tree

src/extension.ts

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function postLaunchHook(extensionCtx: vscode.ExtensionContext) {
315315
if (isFirstLaunch) {
316316

317317
// setup install time
318-
resManager.setAppUsrData('InstallTime', Date.now().toString());
318+
resManager.setAppUsrData('InstallTime', Date.now());
319319

320320
// only enable github proxy for GMT+8:00 by default
321321
const timeZone = Math.floor((new Date().getTimezoneOffset() / 60) * -1);
@@ -328,10 +328,16 @@ function postLaunchHook(extensionCtx: vscode.ExtensionContext) {
328328
// not first launch
329329
else {
330330

331+
// fix type error for old version
332+
if (typeof appUsrData['InstallTime'] === 'string') {
333+
appUsrData['InstallTime'] = parseInt(appUsrData['InstallTime']) || 0;
334+
resManager.setAppUsrData('InstallTime', appUsrData['InstallTime']);
335+
}
336+
331337
// A few days ago, show feedback message
332-
const some_days = 7 * (24 * 3600 * 1000);
338+
const some_days = 7 * utility.TIME_ONE_DAY;
333339
if (!appUsrData['Feedbacked'] &&
334-
Date.now() - appUsrData['InstallTime'] > some_days) {
340+
Date.now() > appUsrData['InstallTime'] + some_days) {
335341
resManager.setAppUsrData('Feedbacked', true);
336342
const msg = view_str$prompt$feedback;
337343
vscode.window.showInformationMessage(msg, rating_text, sponsor_author_text).then((ans) => {
@@ -433,9 +439,10 @@ async function checkAndInstallBinaries(forceInstall?: boolean): Promise<boolean>
433439
}
434440

435441
/* check eide binaries */
436-
// if user force reinstall, delete old 'bin' dir
442+
443+
// force reinstall
437444
if (forceInstall) {
438-
platform.DeleteDir(binFolder);
445+
return await tryUpdateBinaries(binFolder, undefined);
439446
}
440447

441448
// if binaries is installed, we need check binaries's version
@@ -461,12 +468,18 @@ async function checkAndInstallBinaries(forceInstall?: boolean): Promise<boolean>
461468
// try fetch update after 5sec delay
462469
if (localVersion) {
463470
setTimeout(async (curLocalVersion: string) => {
464-
const done = await tryUpdateBinaries(binFolder, curLocalVersion, true); // no prompt
465-
if (!done) {
466-
const msg = `Update eide-binaries failed, please restart vscode to try again !`;
467-
const sel = await vscode.window.showErrorMessage(msg, 'Restart', 'Cancel');
468-
if (sel == 'Restart') {
469-
vscode.commands.executeCommand('workbench.action.reloadWindow');
471+
const appUsrData = resManager.getAppUsrData() || {};
472+
const lastCheckUpdateTime: number = appUsrData['LastCheckBinariesUpdateTime'] || 0;
473+
if (Date.now() > lastCheckUpdateTime + (6 * utility.TIME_ONE_HOUR)) {
474+
const done = await tryUpdateBinaries(binFolder, curLocalVersion); // no prompt
475+
if (done) {
476+
resManager.setAppUsrData('LastCheckBinariesUpdateTime', Date.now());
477+
} else {
478+
const msg = `Update eide-binaries failed, please restart vscode to try again !`;
479+
const sel = await vscode.window.showErrorMessage(msg, 'Restart', 'Cancel');
480+
if (sel == 'Restart') {
481+
vscode.commands.executeCommand('workbench.action.reloadWindow');
482+
}
470483
}
471484
}
472485
}, 5 * 1000, localVersion);
@@ -476,7 +489,7 @@ async function checkAndInstallBinaries(forceInstall?: boolean): Promise<boolean>
476489
// the binaries maybe damaged, we need to force reinstall it
477490
else {
478491
platform.DeleteDir(binFolder); // del existed folder
479-
return await tryUpdateBinaries(binFolder, undefined, true);
492+
return await tryUpdateBinaries(binFolder, undefined);
480493
}
481494

482495
// export current binaries version
@@ -491,10 +504,13 @@ async function checkAndInstallBinaries(forceInstall?: boolean): Promise<boolean>
491504
}
492505

493506
// not found binaries folder, install it
494-
return await tryUpdateBinaries(binFolder, undefined, true);
507+
return await tryUpdateBinaries(binFolder, undefined);
495508
}
496509

497-
async function tryUpdateBinaries(binFolder: File, localVer?: string, notConfirm?: boolean): Promise<boolean> {
510+
/**
511+
* @param localVer 当前本地的版本号,通过比对版本号决定是否执行安装,如果为 undefined 则强制安装
512+
*/
513+
async function tryUpdateBinaries(binFolder: File, localVer?: string): Promise<boolean> {
498514

499515
const eideCfg = ResManager.GetInstance().getAppConfig<any>();
500516
const minReqVersion = eideCfg['binary_min_version'];
@@ -578,15 +594,12 @@ async function tryUpdateBinaries(binFolder: File, localVer?: string, notConfirm?
578594
// check bin folder
579595
// show notify to user and request a confirm
580596
if (checkBinFolder(binFolder) && preinstallVersion) {
581-
582-
if (!notConfirm) {
583-
const msg = `New update for eide binaries, version: '${preinstallVersion}', [ChangeLog](https://github.com/github0null/eide-resource/pulls?q=is%3Apr+is%3Aclosed), install now ?`;
584-
const sel = await vscode.window.showInformationMessage(msg, 'Yes', 'Later');
585-
if (sel != 'Yes') { return true; } // user canceled
586-
}
587-
588-
// del old bin folder before install
589-
platform.DeleteDir(binFolder);
597+
//TODO
598+
// if (!notConfirm) {
599+
// const msg = `New update for eide binaries, version: '${preinstallVersion}', [ChangeLog](https://github.com/github0null/eide-resource/pulls?q=is%3Apr+is%3Aclosed), install now ?`;
600+
// const sel = await vscode.window.showInformationMessage(msg, 'Yes', 'Later');
601+
// if (sel != 'Yes') { return true; } // user canceled
602+
// }
590603
}
591604

592605
return await tryInstallBinaries(binFolder, preinstallVersion);
@@ -615,9 +628,6 @@ async function tryInstallBinaries(binFolder: File, binVersion: string): Promise<
615628
try {
616629
const tmpFile = File.fromArray([os.tmpdir(), `eide-binaries-${binVersion}.${binType}`]);
617630

618-
/* make dir */
619-
binFolder.CreateDir(true);
620-
621631
const done = await vscode.window.withProgress({
622632
location: vscode.ProgressLocation.Notification,
623633
title: 'Downloading eide binaries',
@@ -666,6 +676,15 @@ async function tryInstallBinaries(binFolder: File, binVersion: string): Promise<
666676

667677
let prevPercent: number = 0;
668678

679+
// del old binaries
680+
if (binFolder.IsDir()) {
681+
progress.report({ message: `Cleanup old files ...` });
682+
platform.DeleteAllChildren(binFolder);
683+
}
684+
685+
// make dir
686+
binFolder.CreateDir(true);
687+
669688
// start unzip
670689
node7z.extractFull(tmpFile.path, binFolder.path, {
671690
$bin: ResManager.GetInstance().Get7za().path,

src/utility.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ import { SettingManager } from './SettingManager';
4545
import { ToolchainName } from './ToolchainManager';
4646
import { Time } from '../lib/node-utility/Time';
4747

48+
export const TIME_ONE_MINUTE = 60 * 1000;
49+
export const TIME_ONE_HOUR = 3600 * 1000;
50+
export const TIME_ONE_DAY = 24 * 3600 * 1000;
51+
4852
/**
4953
* @param len len必须是2的整数倍
5054
*/

0 commit comments

Comments
 (0)