Skip to content

Commit

Permalink
Fix: issue from older nrfutil core (#1030)
Browse files Browse the repository at this point in the history
* Fix: issue from older nrfutil core

* Update Changelog.md

* Update Changelog.md

* Update Changelog.md

* Update Changelog.md

* eslint fix

---------

Co-authored-by: Sviatoslav Svitlychnyi <[email protected]>
  • Loading branch information
kylebonnici and KievDevel authored Jul 24, 2024
1 parent 70bb102 commit 09b17eb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 19 deletions.
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 5.0.2 - 2024-07-24

### Fixed

- Implemented recovery from invalid nRF Util module installations.
- Corrected the progress bar behavior to accurately reflect the installation
progress when multiple applications relying on the same nRF Util are being
installed simultaneously.

## 5.0.1 - 2024-07-09

### Fixed
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nrfconnect",
"version": "5.0.1",
"version": "5.0.2",
"description": "nRF Connect for Desktop",
"repository": {
"type": "git",
Expand Down Expand Up @@ -96,7 +96,7 @@
},
"devDependencies": {
"@electron/notarize": "^2.2.0",
"@nordicsemiconductor/pc-nrfconnect-shared": "^180.0.0",
"@nordicsemiconductor/pc-nrfconnect-shared": "^181.0.0",
"@playwright/test": "^1.16.3",
"@testing-library/user-event": "^14.4.3",
"@types/chmodr": "1.0.0",
Expand Down
63 changes: 52 additions & 11 deletions src/main/nrfutilModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
NrfutilModules,
NrfutilModuleVersion,
} from '@nordicsemiconductor/pc-nrfconnect-shared/main';
import { Progress } from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil';
import { setNrfutilLogger } from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil/nrfutilLogger';
import getSandbox, {
NrfutilSandbox,
Expand All @@ -19,16 +20,40 @@ import { inRenderer as downloadProgress } from '../ipc/downloadProgress';
import { getUserDataDir } from './config';
import { logger } from './log';

type SandboxesCacheKeyType = `${NrfutilModuleName}-${NrfutilModuleVersion}`;
type SandboxesCacheType = {
sandbox?: Promise<NrfutilSandbox>;
progressCallbacks: ((progress: Progress) => void)[];
lastProgress?: Progress;
};
const sandboxesCache: {
[
index: `${NrfutilModuleName}-${NrfutilModuleVersion}`
]: Promise<NrfutilSandbox>;
[index: SandboxesCacheKeyType]: SandboxesCacheType;
} = {};

const cachedSandbox = (
app: AppSpec,
moduleName: string,
moduleVersion: NrfutilModuleVersion
) => sandboxesCache[`${moduleName}-${moduleVersion}`];
) => {
const cached = sandboxesCache[`${moduleName}-${moduleVersion}`];

if (cached) {
const progressCallback = (progress: Progress) => {
downloadProgress.reportDownloadProgress({
app,
progressFraction: progress.totalProgressPercentage,
fractionName: moduleName,
});
};

if (cached.lastProgress) {
progressCallback(cached.lastProgress);
}

cached.progressCallbacks.push(progressCallback);
return cached.sandbox;
}
};

const preparedSandbox = (
app: AppSpec,
Expand All @@ -37,20 +62,36 @@ const preparedSandbox = (
) => {
setNrfutilLogger(logger);

const key: SandboxesCacheKeyType = `${moduleName}-${moduleVersion}`;
sandboxesCache[key] = {
progressCallbacks: [
progress => {
downloadProgress.reportDownloadProgress({
app,
progressFraction: progress.totalProgressPercentage,
fractionName: moduleName,
});
},
],
};

const sandbox = getSandbox(
getUserDataDir(),
moduleName,
moduleVersion,
progress => {
downloadProgress.reportDownloadProgress({
app,
progressFraction: progress.totalProgressPercentage,
fractionName: moduleName,
});
if (sandboxesCache[key]) {
sandboxesCache[key].progressCallbacks.forEach(fn =>
fn(progress)
);
sandboxesCache[key].lastProgress = progress;
}
}
);

sandboxesCache[`${moduleName}-${moduleVersion}`] = sandbox;
sandbox.finally(() => delete sandboxesCache[key]);
sandboxesCache[key].sandbox = sandbox;

return sandbox;
};
export const assertPreparedNrfutilModules = (
Expand All @@ -59,6 +100,6 @@ export const assertPreparedNrfutilModules = (
) =>
Object.entries(nrfutilModules).map(
([moduleName, [moduleVersion]]) =>
cachedSandbox(moduleName, moduleVersion) ??
cachedSandbox(app, moduleName, moduleVersion) ??
preparedSandbox(app, moduleName, moduleVersion)
);

0 comments on commit 09b17eb

Please sign in to comment.