report overall progress from libtea (#656)

This commit is contained in:
ABevier 2023-06-06 19:36:51 -04:00 committed by GitHub
parent 17acada221
commit f9031a59df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 25 deletions

View file

@ -23,34 +23,18 @@ export async function installPackage(
}
function newInstallProgressNotifier(full_name: string, notifyMainWindow: MainWindowNotifier) {
// the totall number of packages to install - this is set by the "resolved" message
let numberOfPackages = 1;
// the current package number - this is incremented by the "installed" or "downloaded" message
let currentPackageNumber = 0;
return {
resolved: ({ pending }: Resolution) => {
numberOfPackages = pending.length ?? 1;
log.info(`resolved ${numberOfPackages} packages to install`);
log.info(`resolved ${pending.length} packages to install`);
},
installing: ({ pkg, progress }: { pkg: Package; progress: number | undefined }) => {
log.info(`installing ${pkg.project}@${pkg.version} - ${progress}`);
if (progress && progress > 0) {
// how many total packages are completed
const completedProgress = (currentPackageNumber / numberOfPackages) * 100;
// overallProgress is the total packages completed plus the percentage of the current package
const overallProgress = completedProgress + (progress / numberOfPackages) * 100;
notifyMainWindow("install-progress", { full_name, progress: overallProgress });
progress: (progress: number) => {
if (progress > 0 && progress <= 1) {
notifyMainWindow("install-progress", { full_name, progress: progress * 100 });
}
},
installed: (installation: Installation) => {
log.info("installed", installation);
const { project, version } = installation.pkg;
currentPackageNumber++;
const progress = (currentPackageNumber / numberOfPackages) * 100;
notifyMainWindow("install-progress", { full_name, progress });
notifyMainWindow("pkg-installed", { full_name: project, version: version.toString() });
}
};

View file

@ -87,7 +87,7 @@
"@sentry/electron": "^4.4.0",
"@sentry/svelte": "^7.47.0",
"@sentry/vite-plugin": "^0.7.2",
"@teaxyz/lib": "^0.3.0",
"@teaxyz/lib": "0.4.1",
"@types/electron": "^1.6.10",
"@types/mousetrap": "^1.6.11",
"@vitest/coverage-c8": "^0.27.1",

View file

@ -27,7 +27,7 @@ importers:
'@sveltejs/adapter-static': ^1.0.0-next.48
'@sveltejs/kit': ^1.15.9
'@tea/ui': workspace:*
'@teaxyz/lib': ^0.3.0
'@teaxyz/lib': 0.4.1
'@testing-library/jest-dom': ^5.16.5
'@testing-library/svelte': ^3.2.2
'@testing-library/webdriverio': ^3.2.1
@ -106,7 +106,7 @@ importers:
'@sentry/electron': 4.5.0
'@sentry/svelte': 7.51.2_svelte@3.59.1
'@sentry/vite-plugin': 0.7.2
'@teaxyz/lib': 0.3.0
'@teaxyz/lib': 0.4.1
'@types/electron': 1.6.10
'@types/mousetrap': 1.6.11
'@vitest/coverage-c8': 0.27.3_jsdom@21.1.2
@ -3624,8 +3624,8 @@ packages:
tailwindcss: 3.3.2
dev: false
/@teaxyz/lib/0.3.0:
resolution: {integrity: sha512-NFoVdSE4iX5JBdiXXOo0aGk4fsTb5zjBOqkY9ldA8asa8pITSJjPOxoa34H7gkkxuTcjv/zjeiOREveWdibcdA==}
/@teaxyz/lib/0.4.1:
resolution: {integrity: sha512-DVXOFyhbS1fM5acBU4jdR6WybK6Rt15NaO7qqpkRx7TuNz5mX3AHFszHgoNAhnnyyxvXc8cYSeL7OxYzT04hxQ==}
dependencies:
'@deno/shim-crypto': 0.3.1
'@deno/shim-deno': 0.16.1