From f9031a59dfb46fb8d0f5ca18bd64ad106a8535dc Mon Sep 17 00:00:00 2001 From: ABevier Date: Tue, 6 Jun 2023 19:36:51 -0400 Subject: [PATCH] report overall progress from libtea (#656) --- modules/desktop/electron/libs/cli.ts | 24 ++++-------------------- modules/desktop/package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/modules/desktop/electron/libs/cli.ts b/modules/desktop/electron/libs/cli.ts index 5f7da28..32fa8cc 100644 --- a/modules/desktop/electron/libs/cli.ts +++ b/modules/desktop/electron/libs/cli.ts @@ -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() }); } }; diff --git a/modules/desktop/package.json b/modules/desktop/package.json index 0d2a8cb..7493683 100644 --- a/modules/desktop/package.json +++ b/modules/desktop/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cbbe754..476e333 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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