Skip to content

Commit e1d9269

Browse files
authored
Merge pull request #794 from NordicSemiconductor/feat/improve-azure-analytics
Feat/improve azure analytics
2 parents 23292fd + 40431ba commit e1d9269

34 files changed

+1506
-397
lines changed

Changelog.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,44 @@ This project does _not_ adhere to
77
[Semantic Versioning](https://semver.org/spec/v2.0.0.html) but contrary to it
88
every new version is a new major version.
99

10-
## 123 - UNRELEASED
10+
## 123 - 2023-11-07
1111

1212
### Added
1313

14-
- PID to `nrfutil device` logs when trace is enabled
14+
- PID to `nrfutil device` logs when trace is enabled.
15+
- `launcherConfig` to retrieve the launcher config in any renderer process.
16+
17+
### Changed
18+
19+
- Analytic events names are now distinct with a prefix of the app name
20+
`<AppName>:` e.g `npm:` or `ppk:`.
21+
- `<App` component no longer provides property `reportUsageData` and for app
22+
to enable telemetry they must now use `usageData.enableTelemetry()`
23+
- The function to send telemetry data in `usageData` became async. If you have
24+
to be sure they completed, you now have to await them.
1525

1626
### Fixed
1727

1828
- Serial port in the device list where not aligned correctly
1929
- Auto select device when `--deviceSerial` is provided
2030

31+
### Steps to upgrade when using this package
32+
33+
- In `package.json` bump `engines.nrfconnect` to at least `>=4.2.2`.
34+
- Remove `reportUsageData` property if it is set in project. If this was set
35+
to true add `usageData.enableTelemetry()` as shown below. For projects like
36+
launcher add `usageData.enableTelemetry()` to main and renderer window.
37+
38+
```tsx
39+
import React from 'react';
40+
import { App, render } from '@nordicsemiconductor/pc-nrfconnect-shared';
41+
import usageData from '@nordicsemiconductor/pc-nrfconnect-shared/src/utils/usageData';
42+
43+
usageData.enableTelemetry();
44+
45+
render(<App panes={[]} />);
46+
```
47+
2148
## 122 - 2023-11-02
2249

2350
### Changed

ipc/launcherConfig.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5+
*/
6+
7+
import { ipcMain, ipcRenderer } from 'electron';
8+
9+
export interface Configuration {
10+
isRunningLauncherFromSource: boolean;
11+
isSkipUpdateApps: boolean;
12+
isSkipUpdateLauncher: boolean;
13+
launcherVersion: string;
14+
userDataDir: string;
15+
}
16+
const channel = 'get-config';
17+
18+
const getConfig = (): Configuration => ipcRenderer.sendSync(channel);
19+
const registerGetConfig = (config: Configuration) =>
20+
ipcMain.on(channel, event => {
21+
event.returnValue = config;
22+
});
23+
24+
export const forRenderer = { registerGetConfig };
25+
export const inMain = { getConfig };

ipc/schema/packageJson.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ import { knownDevicePcas } from '../device';
1010
import { nrfModules, semver } from '../MetaFiles';
1111
import { parseWithPrettifiedErrorMessage } from './parseJson';
1212

13+
const packageJson = z.object({
14+
name: z.string(),
15+
version: semver,
16+
17+
displayName: z.string().optional(),
18+
});
19+
20+
export type PackageJson = z.infer<typeof packageJson>;
21+
22+
export const parsePackageJson =
23+
parseWithPrettifiedErrorMessage<PackageJson>(packageJson);
24+
25+
// Apps have more required fields in their package.json
26+
1327
const nrfConnectForDesktop = z.object({
1428
supportedDevices: z.enum(knownDevicePcas).array().nonempty().optional(),
1529
nrfutil: nrfModules.optional(),
@@ -22,12 +36,7 @@ const engines = recordOfOptionalStrings.and(
2236
z.object({ nrfconnect: z.string() })
2337
);
2438

25-
const packageJson = z.object({
26-
name: z.string(),
27-
version: semver,
28-
29-
author: z.string().optional(),
30-
bin: z.string().or(recordOfOptionalStrings).optional(),
39+
const packageJsonApp = packageJson.extend({
3140
dependencies: recordOfOptionalStrings.optional(),
3241
description: z.string(),
3342
homepage: z.string().url().optional(),
@@ -36,34 +45,29 @@ const packageJson = z.object({
3645
engines,
3746
nrfConnectForDesktop,
3847
files: z.string().array().optional(),
39-
license: z.string().optional(),
40-
main: z.string().optional(),
4148
peerDependencies: recordOfOptionalStrings.optional(),
4249
repository: z
4350
.object({
4451
type: z.string(),
4552
url: z.string().url(),
4653
})
4754
.optional(),
48-
scripts: recordOfOptionalStrings.optional(),
4955
});
5056

51-
export type PackageJson = z.infer<typeof packageJson>;
57+
export type PackageJsonApp = z.infer<typeof packageJsonApp>;
5258

53-
export const parsePackageJson =
54-
parseWithPrettifiedErrorMessage<PackageJson>(packageJson);
59+
export const parsePackageJsonApp =
60+
parseWithPrettifiedErrorMessage<PackageJsonApp>(packageJsonApp);
5561

5662
// In the launcher we want to handle that the whole nrfConnectForDesktop may be missing
5763
// and the html in it can also be undefined, so there we need to use this legacy variant
58-
const legacyPackageJson = packageJson.merge(
59-
z.object({
60-
nrfConnectForDesktop: nrfConnectForDesktop
61-
.partial({ html: true })
62-
.optional(),
63-
})
64-
);
64+
const packageJsonLegacyApp = packageJsonApp.extend({
65+
nrfConnectForDesktop: nrfConnectForDesktop
66+
.partial({ html: true })
67+
.optional(),
68+
});
6569

66-
export type LegacyPackageJson = z.infer<typeof legacyPackageJson>;
70+
export type PackageJsonLegacyApp = z.infer<typeof packageJsonLegacyApp>;
6771

68-
export const parseLegacyPackageJson =
69-
parseWithPrettifiedErrorMessage<LegacyPackageJson>(legacyPackageJson);
72+
export const parsePackageJsonLegacyApp =
73+
parseWithPrettifiedErrorMessage<PackageJsonLegacyApp>(packageJsonLegacyApp);

main/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { forRenderer as forRendererAppDetails } from '../ipc/appDetails';
88
import { forRenderer as forRendererApps } from '../ipc/apps';
9+
import { forRenderer as forRendererLauncherConfig } from '../ipc/launcherConfig';
910
import { forRenderer as forRendererOpenWindow } from '../ipc/openWindow';
1011
import { forRenderer as forRendererPreventSleep } from '../ipc/preventSleep';
1112
import { forRenderer as forRendererSafeStorage } from '../ipc/safeStorage';
@@ -18,6 +19,7 @@ export { registerLauncherWindowFromMain } from '../ipc/infrastructure/mainToRend
1819

1920
export const appDetails = { forRenderer: forRendererAppDetails };
2021
export const apps = { forRenderer: forRendererApps };
22+
export const launcherConfig = { forRenderer: forRendererLauncherConfig };
2123
export const openWindow = { forRenderer: forRendererOpenWindow };
2224
export const preventSleep = { forRenderer: forRendererPreventSleep };
2325
export const safeStorage = {
@@ -37,10 +39,10 @@ export {
3739
type WithdrawnJson,
3840
} from '../ipc/MetaFiles';
3941
export {
40-
type LegacyPackageJson,
41-
type PackageJson,
42-
parseLegacyPackageJson,
43-
parsePackageJson,
42+
type PackageJsonLegacyApp,
43+
type PackageJsonApp,
44+
parsePackageJsonLegacyApp,
45+
parsePackageJsonApp,
4446
} from '../ipc/schema/packageJson';
4547

4648
export { type OverwriteOptions } from '../ipc/serialPort';

mocks/packageJsonMock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
55
*/
66

7-
export default () => ({
7+
export const packageJson = () => ({
88
name: 'mocked-test-app',
99
version: '27.6.72',
1010
});

nrfutil/moduleVersion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
55
*/
66

7-
import packageJson from '../src/utils/packageJson';
7+
import { packageJsonApp } from '../src/utils/packageJson';
88
import {
99
Dependency,
1010
isIncrementalVersion,
@@ -89,7 +89,7 @@ const overriddenVersion = (module: string) => {
8989
};
9090

9191
const versionFromPackageJson = (module: string) =>
92-
packageJson().nrfConnectForDesktop.nrfutil?.[module][0];
92+
packageJsonApp().nrfConnectForDesktop.nrfutil?.[module][0];
9393

9494
const failToDetermineVersion = (module: string) => {
9595
throw new Error(`No version specified for nrfutil-${module}`);

nrfutil/sandbox.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import os from 'os';
1010
import path from 'path';
1111

1212
import describeError from '../src/logging/describeError';
13+
import usageData from '../src/utils/usageData';
1314
import { versionToInstall } from './moduleVersion';
1415
import { getNrfutilLogger } from './nrfutilLogger';
1516
import {
@@ -266,7 +267,7 @@ export class NrfutilSandbox {
266267
}
267268

268269
error.message = error.message.replaceAll('Error: ', '');
269-
getNrfutilLogger()?.error(
270+
usageData.sendErrorReport(
270271
`${
271272
pid && this.logLevel === 'trace' ? `[PID:${pid}] ` : ''
272273
}${describeError(error)}`
@@ -301,6 +302,7 @@ export class NrfutilSandbox {
301302
) =>
302303
new Promise<void>((resolve, reject) => {
303304
let aborting = false;
305+
usageData.sendUsageData(`running nrfutil ${command}`, { args });
304306
const nrfutil = spawn(
305307
path.join(this.baseDir, 'nrfutil'),
306308
[
@@ -407,6 +409,7 @@ export class NrfutilSandbox {
407409
closedHandlers.forEach(callback => callback());
408410
})
409411
.catch(error => {
412+
usageData.sendErrorReport(describeError(error));
410413
running = false;
411414
closedHandlers.forEach(callback => callback(error));
412415
});

0 commit comments

Comments
 (0)