@nordicsemiconductor/pc-nrfconnect-shared 76.0.0 → 78.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/Changelog.md +39 -0
  2. package/config/tailwind.config.js +1 -1
  3. package/main/index.ts +19 -21
  4. package/mocks/electronMock.ts +2 -0
  5. package/package.json +2 -1
  6. package/scripts/check-app-properties.ts +1 -1
  7. package/scripts/esbuild-renderer.js +3 -1
  8. package/scripts/esbuild.js +3 -3
  9. package/scripts/nordic-publish.ts +1 -1
  10. package/scripts/release-shared.ts +1 -1
  11. package/src/About/ApplicationCard.tsx +6 -35
  12. package/src/App/App.tsx +2 -2
  13. package/src/SerialPort/SerialPort.test.ts +5 -9
  14. package/src/SerialPort/SerialPort.ts +47 -77
  15. package/src/index.ts +5 -12
  16. package/src/logging/sendInitialLogMessages.ts +35 -38
  17. package/src/utils/packageJson.ts +1 -1
  18. package/src/utils/usageData.ts +1 -1
  19. package/typings/generated/{src/utils/AppTypes.d.ts → ipc/MetaFiles.d.ts} +10 -8
  20. package/typings/generated/ipc/MetaFiles.d.ts.map +1 -0
  21. package/typings/generated/ipc/appDetails.d.ts +19 -0
  22. package/typings/generated/ipc/appDetails.d.ts.map +1 -0
  23. package/typings/generated/ipc/apps.d.ts +67 -0
  24. package/typings/generated/ipc/apps.d.ts.map +1 -0
  25. package/typings/generated/ipc/infrastructure/mainToRenderer.d.ts +7 -0
  26. package/typings/generated/ipc/infrastructure/mainToRenderer.d.ts.map +1 -0
  27. package/typings/generated/ipc/infrastructure/rendererToMain.d.ts +7 -0
  28. package/typings/generated/ipc/infrastructure/rendererToMain.d.ts.map +1 -0
  29. package/typings/generated/ipc/openWindow.d.ts +19 -0
  30. package/typings/generated/ipc/openWindow.d.ts.map +1 -0
  31. package/typings/generated/ipc/preventSleep.d.ts +11 -0
  32. package/typings/generated/ipc/preventSleep.d.ts.map +1 -0
  33. package/typings/generated/ipc/serialPort.d.ts +49 -0
  34. package/typings/generated/ipc/serialPort.d.ts.map +1 -0
  35. package/typings/generated/ipc/sources.d.ts +15 -0
  36. package/typings/generated/ipc/sources.d.ts.map +1 -0
  37. package/typings/generated/main/index.d.ts +51 -21
  38. package/typings/generated/main/index.d.ts.map +1 -1
  39. package/typings/generated/src/About/ApplicationCard.d.ts.map +1 -1
  40. package/typings/generated/src/App/App.d.ts.map +1 -1
  41. package/typings/generated/src/SerialPort/SerialPort.d.ts +6 -6
  42. package/typings/generated/src/SerialPort/SerialPort.d.ts.map +1 -1
  43. package/typings/generated/src/index.d.ts +4 -4
  44. package/typings/generated/src/index.d.ts.map +1 -1
  45. package/typings/generated/src/logging/sendInitialLogMessages.d.ts +1 -1
  46. package/typings/generated/src/logging/sendInitialLogMessages.d.ts.map +1 -1
  47. package/typings/generated/src/utils/packageJson.d.ts +1 -1
  48. package/typings/generated/src/utils/packageJson.d.ts.map +1 -1
  49. package/typings/generated/src/utils/usageData.d.ts +1 -1
  50. package/typings/generated/src/utils/usageData.d.ts.map +1 -1
  51. package/src/OpenApp/openApp.ts +0 -18
  52. package/src/utils/AppTypes.ts +0 -60
  53. package/typings/generated/src/OpenApp/openApp.d.ts +0 -8
  54. package/typings/generated/src/OpenApp/openApp.d.ts.map +0 -1
  55. package/typings/generated/src/utils/AppTypes.d.ts.map +0 -1
package/Changelog.md CHANGED
@@ -7,6 +7,45 @@ This project does _not_ adhere to
7
7
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html) but contrary to it
8
8
  every new version is a new major version.
9
9
 
10
+ ## 78 - 2023-08-02
11
+
12
+ ### Changed
13
+
14
+ - New name for the shared package, it is now under the `@nordicsemiconductor`
15
+ namespace on npm. The idea is that apps will now install shared from npm,
16
+ and use the new name `@nordicsemiconductor/pc-nrfconnect-shared` when
17
+ importing components from shared
18
+
19
+ ## 77 - 2023-08-01
20
+
21
+ ### Added
22
+
23
+ - Functions to invoke functionality in the main process via IPC:
24
+
25
+ - `apps.getDownloadableApps()`
26
+ - `apps.installDownloadableApp(app, version?)`
27
+ - `openWindow.openApp(app, openAppOptions?)` (This was previously exported
28
+ as `openAppWindow``)
29
+ - `openWindow.openLauncher()`
30
+ - `preventSleep.start()`
31
+ - `preventSleep.end(id)`
32
+
33
+ ### Removed
34
+
35
+ - Export of the serialport IPC channel names.
36
+
37
+ ### Changed
38
+
39
+ - On the build server the generated types are removed before regenerating
40
+ them, so we make sure that we do not have stale declaration files for source
41
+ files we already removed.
42
+
43
+ ### Steps to upgrade when using this package
44
+
45
+ - Replace all code that still uses `ipcRenderer` with invocations of the
46
+ appropriate functions.
47
+ - Replace invocations of `openAppWindow` with `openWindow.openApp`.
48
+
10
49
  ## 76 - 2023-07-28
11
50
 
12
51
  ### Changed
@@ -12,7 +12,7 @@ module.exports = {
12
12
  prefix: 'tw-',
13
13
  content: [
14
14
  './src/**/*.{html,jsx,tsx}',
15
- './node_modules/pc-nrfconnect-shared/src/**/*.tsx',
15
+ './node_modules/@nordicsemiconductor/pc-nrfconnect-shared/src/**/*.tsx',
16
16
  ],
17
17
  theme: {
18
18
  colors,
package/main/index.ts CHANGED
@@ -4,29 +4,27 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- export const SERIALPORT_CHANNEL = {
8
- OPEN: 'serialport:open',
9
- CLOSE: 'serialport:close',
10
- WRITE: 'serialport:write',
11
- UPDATE: 'serialport:update',
12
- SET: 'serialport:set',
7
+ import { forRenderer as forRendererAppDetails } from '../ipc/appDetails';
8
+ import { forRenderer as forRendererApps } from '../ipc/apps';
9
+ import { forRenderer as forRendererOpenWindow } from '../ipc/openWindow';
10
+ import { forRenderer as forRendererPreventSleep } from '../ipc/preventSleep';
11
+ import {
12
+ forRenderer as forRendererSerialPort,
13
+ inRenderer as inRendererSerialPort,
14
+ } from '../ipc/serialPort';
13
15
 
14
- ON_CLOSED: 'serialport:on-close',
15
- ON_DATA: 'serialport:on-data',
16
- ON_UPDATE: 'serialport:on-update',
17
- ON_SET: 'serialport:on-set',
18
- ON_CHANGED: 'serialport:on-changed',
19
- ON_WRITE: 'serialport:on-write',
16
+ export { registerLauncherWindowFromMain } from '../ipc/infrastructure/mainToRenderer';
20
17
 
21
- IS_OPEN: 'serialport:is-open',
22
- GET_OPTIONS: 'serialport:get-options',
18
+ export const appDetails = { forRenderer: forRendererAppDetails };
19
+ export const apps = { forRenderer: forRendererApps };
20
+ export const openWindow = { forRenderer: forRendererOpenWindow };
21
+ export const preventSleep = { forRenderer: forRendererPreventSleep };
22
+ export const serialPort = {
23
+ inRenderer: inRendererSerialPort,
24
+ forRenderer: forRendererSerialPort,
23
25
  };
24
26
 
25
- export type OverwriteOptions = {
26
- overwrite?: boolean;
27
- settingsLocked?: boolean;
28
- };
27
+ export * from '../ipc/MetaFiles';
29
28
 
30
- export type OpenAppOptions = {
31
- device?: { serialNumber: string; serialPortPath?: string };
32
- };
29
+ export { type OverwriteOptions } from '../ipc/serialPort';
30
+ export { type OpenAppOptions } from '../ipc/openWindow';
@@ -10,6 +10,8 @@ export const match = jest.fn();
10
10
  export const app = jest.fn();
11
11
  export const dialog = jest.fn();
12
12
  export const ipcRenderer = {
13
+ on: jest.fn(),
13
14
  once: jest.fn(),
15
+ invoke: jest.fn().mockResolvedValue(undefined),
14
16
  send: jest.fn(),
15
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nordicsemiconductor/pc-nrfconnect-shared",
3
- "version": "76.0.0",
3
+ "version": "78.0.0",
4
4
  "description": "Shared commodities for developing pc-nrfconnect-* packages",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,6 +37,7 @@
37
37
  "check:lint": "eslint --color .",
38
38
  "check:types": "tsc --noEmit",
39
39
  "check:license": "ts-node scripts/nrfconnect-license.ts check",
40
+ "clean-generate-types": "rimraf ./typings/generated",
40
41
  "generate-types": "tsc --emitDeclarationOnly --declaration --declarationMap --outDir ./typings/generated --rootDir .",
41
42
  "prepare": "ts-node scripts/installHusky.ts",
42
43
  "release-shared": "ts-node scripts/release-shared.ts",
@@ -10,7 +10,7 @@ import { execSync } from 'child_process';
10
10
  import { existsSync, readdirSync, readFileSync } from 'fs';
11
11
  import property from 'lodash/property';
12
12
 
13
- import { PackageJson } from '../src/utils/AppTypes';
13
+ import { PackageJson } from '../ipc/MetaFiles';
14
14
 
15
15
  const format = (strings: string[]) =>
16
16
  strings.map(string => `\`${string}\``).join(', ');
@@ -22,7 +22,9 @@ const projectSpecificTailwindConfigPath = path.join(
22
22
  const tailwindConfig = () =>
23
23
  fs.existsSync(projectSpecificTailwindConfigPath)
24
24
  ? projectSpecificTailwindConfigPath
25
- : require.resolve('pc-nrfconnect-shared/config/tailwind.config.js');
25
+ : require.resolve(
26
+ '@nordicsemiconductor/pc-nrfconnect-shared/config/tailwind.config.js'
27
+ );
26
28
 
27
29
  function options(additionalOptions) {
28
30
  const { dependencies } = JSON.parse(
@@ -26,7 +26,7 @@ if (!fs.existsSync(distFolder)) {
26
26
  fs.copyFileSync(
27
27
  join(
28
28
  process.cwd(),
29
- './node_modules/pc-nrfconnect-shared/scripts/nordic-publish.js'
29
+ './node_modules/@nordicsemiconductor/pc-nrfconnect-shared/scripts/nordic-publish.js'
30
30
  ),
31
31
  join(distFolder, 'nordic-publish.js')
32
32
  );
@@ -34,7 +34,7 @@ fs.copyFileSync(
34
34
  fs.copyFileSync(
35
35
  join(
36
36
  process.cwd(),
37
- './node_modules/pc-nrfconnect-shared/dist/bootstrap.css'
37
+ './node_modules/@nordicsemiconductor/pc-nrfconnect-shared/dist/bootstrap.css'
38
38
  ),
39
39
  join(distFolder, 'bootstrap.css')
40
40
  );
@@ -47,7 +47,7 @@ if (process.argv.includes('--include-bootloader')) {
47
47
  fs.copyFileSync(
48
48
  join(
49
49
  process.cwd(),
50
- './node_modules/pc-nrfconnect-shared/fw/bootloader/graviton_bootloader_v1.0.1-[nRF5_SDK_15.0.1-1.alpha_f76d012].zip'
50
+ './node_modules/@nordicsemiconductor/pc-nrfconnect-shared/fw/bootloader/graviton_bootloader_v1.0.1-[nRF5_SDK_15.0.1-1.alpha_f76d012].zip'
51
51
  ),
52
52
  join(
53
53
  process.cwd(),
@@ -13,7 +13,7 @@ import FtpClient from 'ftp';
13
13
  import semver from 'semver';
14
14
  import calculateShasum from 'shasum';
15
15
 
16
- import { AppInfo, PackageJson, SourceJson } from '../src/utils/AppTypes';
16
+ import { AppInfo, PackageJson, SourceJson } from '../ipc/MetaFiles';
17
17
  import checkAppProperties from './check-app-properties';
18
18
 
19
19
  interface LegacyAppInfo {
@@ -25,7 +25,7 @@
25
25
  */
26
26
  import { execSync, spawnSync } from 'node:child_process';
27
27
 
28
- import { PackageJson } from '../src/utils/AppTypes';
28
+ import { PackageJson } from '../ipc/MetaFiles';
29
29
 
30
30
  const logError = (message: string) => {
31
31
  console.error(message);
@@ -5,51 +5,22 @@
5
5
  */
6
6
 
7
7
  import React, { useEffect, useState } from 'react';
8
- import { ipcRenderer } from 'electron';
9
8
 
9
+ import {
10
+ AppDetailsFromLauncher,
11
+ inMain as appDetails,
12
+ } from '../../ipc/appDetails';
10
13
  import Card from '../Card/Card';
11
14
  import FactoryResetButton from '../FactoryReset/FactoryResetButton';
12
15
  import AboutButton from './AboutButton';
13
16
  import Section from './Section';
14
17
  import ShortcutButton from './ShortcutButton';
15
18
 
16
- interface AppDetails {
17
- coreVersion: string;
18
- corePath: string;
19
- homeDir: string;
20
- tmpDir: string;
21
- }
22
-
23
- interface LauncerApp {
24
- name?: string;
25
- displayName?: string;
26
- description?: string;
27
- homepage?: string;
28
- currentVersion?: string;
29
- latestVersion?: string;
30
- engineVersion?: string;
31
- path?: string;
32
- iconPath?: string;
33
- shortcutIconPath?: string;
34
- isOfficial?: string;
35
- sharedVersion?: string;
36
- source?: string;
37
- url?: string;
38
- releaseNote?: string;
39
- upgradeAvailable?: string;
40
- repositoryUrl?: string;
41
- }
42
-
43
- type DetailsFromLauncher = AppDetails & LauncerApp;
44
-
45
19
  export default () => {
46
- const [appInfo, setAppInfo] = useState<DetailsFromLauncher>();
20
+ const [appInfo, setAppInfo] = useState<AppDetailsFromLauncher>();
47
21
 
48
22
  useEffect(() => {
49
- ipcRenderer.once('app-details', (_, details: DetailsFromLauncher) => {
50
- setAppInfo(details);
51
- });
52
- ipcRenderer.send('get-app-details');
23
+ appDetails.getAppDetails().then(setAppInfo);
53
24
  }, [setAppInfo]);
54
25
 
55
26
  if (appInfo == null) return null;
package/src/App/App.tsx CHANGED
@@ -9,9 +9,9 @@ import 'focus-visible';
9
9
  import React, { FC, ReactNode, useEffect, useMemo } from 'react';
10
10
  import Carousel from 'react-bootstrap/Carousel';
11
11
  import { useDispatch, useSelector } from 'react-redux';
12
- import { ipcRenderer } from 'electron';
13
12
  import { Reducer } from 'redux';
14
13
 
14
+ import { inMain as openWindow } from '../../ipc/openWindow';
15
15
  import About from '../About/About';
16
16
  import BrokenDeviceDialog from '../Device/BrokenDeviceDialog/BrokenDeviceDialog';
17
17
  import { setAutoReselect } from '../Device/deviceAutoSelectSlice';
@@ -102,7 +102,7 @@ const ConnectedApp: FC<ConnectedAppProps> = ({
102
102
  hotKey: 'alt+l',
103
103
  title: 'Open launcher',
104
104
  isGlobal: true,
105
- action: () => ipcRenderer.send('open-app-launcher'),
105
+ action: openWindow.openLauncher,
106
106
  });
107
107
 
108
108
  useEffect(() => {
@@ -6,20 +6,16 @@
6
6
 
7
7
  import { ipcRenderer } from 'electron';
8
8
 
9
- import { OverwriteOptions, SERIALPORT_CHANNEL } from '../../main';
9
+ import { OverwriteOptions } from '../../ipc/serialPort';
10
10
  import { createSerialPort } from './SerialPort';
11
11
 
12
- jest.mock('electron', () => ({
13
- ipcRenderer: { invoke: jest.fn(), on: jest.fn(), send: jest.fn() },
14
- }));
15
-
16
12
  const defaultOptions = { path: '/dev/ROBOT', baudRate: 115200 };
17
13
 
18
14
  test('SerialPort is initialized with the correct setup', async () => {
19
15
  const port = await createSerialPort(defaultOptions);
20
16
 
21
17
  expect(ipcRenderer.invoke).toHaveBeenCalledWith(
22
- SERIALPORT_CHANNEL.OPEN,
18
+ 'serialport:open',
23
19
  defaultOptions,
24
20
  { overwrite: false, settingsLocked: false }
25
21
  );
@@ -31,7 +27,7 @@ test('SerialPort may be initialized with overwrite and settingsLocked', async ()
31
27
  let overwriteOptions: OverwriteOptions = { overwrite: true };
32
28
  await createSerialPort(defaultOptions, overwriteOptions);
33
29
  expect(ipcRenderer.invoke).toHaveBeenCalledWith(
34
- SERIALPORT_CHANNEL.OPEN,
30
+ 'serialport:open',
35
31
  defaultOptions,
36
32
  overwriteOptions
37
33
  );
@@ -39,7 +35,7 @@ test('SerialPort may be initialized with overwrite and settingsLocked', async ()
39
35
  overwriteOptions = { settingsLocked: true };
40
36
  await createSerialPort(defaultOptions, overwriteOptions);
41
37
  expect(ipcRenderer.invoke).toHaveBeenCalledWith(
42
- SERIALPORT_CHANNEL.OPEN,
38
+ 'serialport:open',
43
39
  defaultOptions,
44
40
  overwriteOptions
45
41
  );
@@ -47,7 +43,7 @@ test('SerialPort may be initialized with overwrite and settingsLocked', async ()
47
43
  overwriteOptions = { settingsLocked: true, overwrite: true };
48
44
  await createSerialPort(defaultOptions, overwriteOptions);
49
45
  expect(ipcRenderer.invoke).toHaveBeenCalledWith(
50
- SERIALPORT_CHANNEL.OPEN,
46
+ 'serialport:open',
51
47
  defaultOptions,
52
48
  overwriteOptions
53
49
  );
@@ -9,11 +9,10 @@ import type {
9
9
  SetOptions,
10
10
  UpdateOptions,
11
11
  } from '@serialport/bindings-cpp';
12
- import { ipcRenderer } from 'electron';
13
12
  import EventEmitter from 'events';
14
13
  import type { SerialPortOpenOptions } from 'serialport';
15
14
 
16
- import { OverwriteOptions, SERIALPORT_CHANNEL } from '../../main';
15
+ import { forMain, inMain, OverwriteOptions } from '../../ipc/serialPort';
17
16
  import logger from '../logging';
18
17
 
19
18
  export type SerialPort = Awaited<ReturnType<typeof createSerialPort>>;
@@ -29,77 +28,30 @@ export const createSerialPort = async (
29
28
  const eventEmitter = new EventEmitter();
30
29
  let closed = false;
31
30
 
32
- ipcRenderer.on(`${SERIALPORT_CHANNEL.ON_DATA}_${path}`, (_event, data) =>
31
+ forMain.registerOnDataReceived(path)(data =>
33
32
  eventEmitter.emit('onData', data)
34
33
  );
35
- ipcRenderer.on(`${SERIALPORT_CHANNEL.ON_CLOSED}_${path}`, () => {
34
+ forMain.registerOnDataWritten(path)(data =>
35
+ eventEmitter.emit('onDataWritten', data)
36
+ );
37
+
38
+ forMain.registerOnClosed(path)(() => {
36
39
  eventEmitter.emit('onClosed');
37
40
  closed = true;
38
41
  });
39
- ipcRenderer.on(
40
- `${SERIALPORT_CHANNEL.ON_UPDATE}_${path}`,
41
- (_event, newOptions) => eventEmitter.emit('onUpdate', newOptions)
42
+ forMain.registerOnUpdated(path)(newOptions =>
43
+ eventEmitter.emit('onUpdate', newOptions)
42
44
  );
43
- ipcRenderer.on(
44
- `${SERIALPORT_CHANNEL.ON_SET}_${path}`,
45
- (_event, newOptions) => eventEmitter.emit('onSet', newOptions)
45
+ forMain.registerOnSet(path)(newOptions =>
46
+ eventEmitter.emit('onSet', newOptions)
46
47
  );
47
- ipcRenderer.on(
48
- `${SERIALPORT_CHANNEL.ON_CHANGED}_${path}`,
49
- (_event, newOptions) => eventEmitter.emit('onChange', newOptions)
50
- );
51
-
52
- // The origin of this event is emitted when a renderer writes to the port.
53
- ipcRenderer.on(`${SERIALPORT_CHANNEL.ON_WRITE}_${path}`, (_event, data) =>
54
- eventEmitter.emit('onDataWritten', data)
48
+ forMain.registerOnChanged(path)(newOptions =>
49
+ eventEmitter.emit('onChange', newOptions)
55
50
  );
56
51
 
57
- const write = (data: string | number[] | Buffer): void => {
58
- ipcRenderer.invoke(SERIALPORT_CHANNEL.WRITE, path, data);
59
- };
60
-
61
- const isOpen = (): Promise<boolean> =>
62
- ipcRenderer.invoke(SERIALPORT_CHANNEL.IS_OPEN, path);
63
-
64
- const close = async () => {
65
- if (closed) return;
66
- const error = await ipcRenderer.invoke(SERIALPORT_CHANNEL.CLOSE, path);
67
- if (error) {
68
- // IPC only carries the error message, that's why we throw new Error.
69
- throw new Error(error);
70
- }
71
-
72
- try {
73
- if (await isOpen()) {
74
- logger.info(
75
- `Port ${options.path} still in use by other window(s)`
76
- );
77
- }
78
- } catch {
79
- logger.info(`Closed port: ${options.path}`);
80
- }
81
- };
82
-
83
- // Only supports baudRate, same as serialport.io
84
- const update = (newOptions: UpdateOptions) => {
85
- ipcRenderer.invoke(SERIALPORT_CHANNEL.UPDATE, path, newOptions);
86
- };
87
-
88
- const set = (newOptions: SetOptions) => {
89
- ipcRenderer.invoke(SERIALPORT_CHANNEL.SET, path, newOptions);
90
- };
91
-
92
- const getOptions = ():
93
- | Promise<SerialPortOpenOptions<AutoDetectTypes>>
94
- | undefined => ipcRenderer.invoke(SERIALPORT_CHANNEL.GET_OPTIONS, path);
95
-
96
52
  const openWithRetries = async (retryCount: number) => {
97
53
  try {
98
- return (await ipcRenderer.invoke(
99
- SERIALPORT_CHANNEL.OPEN,
100
- options,
101
- overwriteOptions
102
- )) as string;
54
+ return await inMain.open(options, overwriteOptions);
103
55
  } catch (error) {
104
56
  if (
105
57
  (error as Error).message.includes(
@@ -107,18 +59,37 @@ export const createSerialPort = async (
107
59
  ) &&
108
60
  retryCount > 0
109
61
  ) {
110
- return new Promise<string>(resolve => {
62
+ return new Promise<void | string>(resolve => {
111
63
  setTimeout(async () => {
112
- resolve(
113
- (await openWithRetries(retryCount - 1)) as string
114
- );
64
+ resolve(await openWithRetries(retryCount - 1));
115
65
  }, 50 + Math.random() * 100);
116
66
  });
117
67
  }
118
- return Promise.resolve<string>((error as Error).message);
68
+ return (error as Error).message;
69
+ }
70
+ };
71
+
72
+ const close = async () => {
73
+ if (closed) return;
74
+ await inMain.close(path);
75
+
76
+ try {
77
+ if (await inMain.isOpen(path)) {
78
+ logger.info(
79
+ `Port ${options.path} still in use by other window(s)`
80
+ );
81
+ }
82
+ } catch {
83
+ logger.info(`Closed port: ${options.path}`);
119
84
  }
120
85
  };
121
86
 
87
+ const write = (data: string | number[] | Buffer) =>
88
+ inMain.write(path, data);
89
+ const update = (newOptions: UpdateOptions) =>
90
+ inMain.update(path, newOptions); // Only supports baudRate, same as serialport.io
91
+ const set = (newOptions: SetOptions) => inMain.set(path, newOptions);
92
+
122
93
  const error = await openWithRetries(3);
123
94
 
124
95
  if (error) {
@@ -138,12 +109,15 @@ export const createSerialPort = async (
138
109
 
139
110
  return {
140
111
  path,
141
- write,
112
+
142
113
  close,
143
- isOpen,
114
+ write,
144
115
  update,
145
116
  set,
146
- getOptions,
117
+
118
+ isOpen: () => inMain.isOpen(path),
119
+ getOptions: () => inMain.getOptions(path),
120
+
147
121
  onData: (handler: (data: Uint8Array) => void) => {
148
122
  eventEmitter.on('onData', handler);
149
123
  return () => {
@@ -187,15 +161,11 @@ export const createSerialPort = async (
187
161
  };
188
162
  };
189
163
 
190
- export const getSerialPortOptions = async (
191
- path: string
192
- ): Promise<SerialPortOpenOptions<AutoDetectTypes> | undefined> => {
164
+ export const getSerialPortOptions = async (path: string) => {
193
165
  try {
194
166
  console.log('will fetch options from path=', path);
195
- return (await ipcRenderer.invoke(
196
- SERIALPORT_CHANNEL.GET_OPTIONS,
197
- path
198
- )) as SerialPortOpenOptions<AutoDetectTypes> | undefined;
167
+
168
+ return await inMain.getOptions(path);
199
169
  } catch (error) {
200
170
  logger.error(`Failed to get options for port: ${path}`);
201
171
  }
package/src/index.ts CHANGED
@@ -5,9 +5,7 @@
5
5
  */
6
6
  import { hideDialog, showDialog } from './ErrorDialog/errorDialogSlice';
7
7
 
8
- const ErrorDialogActions = { hideDialog, showDialog };
9
-
10
- export { ErrorDialogActions };
8
+ export const ErrorDialogActions = { hideDialog, showDialog };
11
9
 
12
10
  export { default as App, type PaneProps } from './App/App';
13
11
  export { default as Logo } from './Logo/Logo';
@@ -130,8 +128,6 @@ export {
130
128
  } from './SerialPort/SerialPort';
131
129
  export { default as ConflictingSettingsDialog } from './SerialPort/ConflictingSettingsDialog';
132
130
 
133
- export { openAppWindow } from './OpenApp/openApp';
134
-
135
131
  export type { AppDispatch, AppThunk, NrfConnectState } from './store';
136
132
 
137
133
  export {
@@ -140,13 +136,6 @@ export {
140
136
  prepareDevice,
141
137
  } from './Device/deviceSetup';
142
138
 
143
- export type {
144
- AppInfo,
145
- AppVersions,
146
- PackageJson,
147
- SourceJson,
148
- } from './utils/AppTypes';
149
-
150
139
  export {
151
140
  addNewMessage,
152
141
  newCopiedFlashMessage,
@@ -155,3 +144,7 @@ export {
155
144
  newErrorFlashMessage,
156
145
  newSuccessFlashMessage,
157
146
  } from './FlashMessage/FlashMessageSlice';
147
+
148
+ export { inMain as apps } from '../ipc/apps';
149
+ export { inMain as openWindow } from '../ipc/openWindow';
150
+ export { inMain as preventSleep } from '../ipc/preventSleep';
@@ -5,8 +5,8 @@
5
5
  */
6
6
 
7
7
  import { getModuleVersions } from '@nordicsemiconductor/nrf-device-lib-js';
8
- import { ipcRenderer } from 'electron';
9
8
 
9
+ import { inMain as appDetails } from '../../ipc/appDetails';
10
10
  import {
11
11
  getDeviceLibContext,
12
12
  getModuleVersion,
@@ -17,48 +17,45 @@ import logLibVersions from '../utils/logLibVersions';
17
17
  import logger from '.';
18
18
 
19
19
  let initialMessagesSent = false;
20
- export default () => {
20
+ export default async () => {
21
21
  if (initialMessagesSent) return;
22
22
  initialMessagesSent = true;
23
23
 
24
24
  logLibVersions();
25
25
  logger.debug(`Application data folder: ${getAppDataDir()}`);
26
26
 
27
- ipcRenderer.once('app-details', async (_event, details) => {
28
- const {
29
- name,
30
- currentVersion,
31
- engineVersion,
32
- coreVersion,
33
- corePath,
34
- isOfficial,
35
- installed,
36
- homeDir,
37
- tmpDir,
38
- bundledJlink,
39
- } = details;
40
-
41
- const official = isOfficial ? 'official' : 'local';
42
-
43
- logger.debug(`App ${name} v${currentVersion} ${official}`);
44
- logger.debug(`App path: ${installed.path}`);
45
- logger.debug(
46
- `nRFConnect ${coreVersion}, required by the app is (${engineVersion})`
47
- );
48
- logger.debug(`nRFConnect path: ${corePath}`);
49
- logger.debug(`HomeDir: ${homeDir}`);
50
- logger.debug(`TmpDir: ${tmpDir}`);
51
-
52
- if (bundledJlink) {
53
- const versions = await getModuleVersions(getDeviceLibContext());
54
- const jlinkVersion = getModuleVersion('JlinkARM', versions);
55
-
56
- if (!describeVersion(jlinkVersion).includes(bundledJlink)) {
57
- logger.info(
58
- `Installed JLink version does not match the provided version (${bundledJlink})`
59
- );
60
- }
27
+ const details = await appDetails.getAppDetails();
28
+
29
+ const {
30
+ name,
31
+ currentVersion,
32
+ engineVersion,
33
+ coreVersion,
34
+ corePath,
35
+ installed,
36
+ homeDir,
37
+ tmpDir,
38
+ bundledJlink,
39
+ source,
40
+ } = details;
41
+
42
+ logger.debug(`App ${name} v${currentVersion} (${source})`);
43
+ logger.debug(`App path: ${installed.path}`);
44
+ logger.debug(
45
+ `nRFConnect ${coreVersion}, required by the app is (${engineVersion})`
46
+ );
47
+ logger.debug(`nRFConnect path: ${corePath}`);
48
+ logger.debug(`HomeDir: ${homeDir}`);
49
+ logger.debug(`TmpDir: ${tmpDir}`);
50
+
51
+ if (bundledJlink) {
52
+ const versions = await getModuleVersions(getDeviceLibContext());
53
+ const jlinkVersion = getModuleVersion('JlinkARM', versions);
54
+
55
+ if (!describeVersion(jlinkVersion).includes(bundledJlink)) {
56
+ logger.info(
57
+ `Installed JLink version does not match the provided version (${bundledJlink})`
58
+ );
61
59
  }
62
- });
63
- ipcRenderer.send('get-app-details');
60
+ }
64
61
  };
@@ -33,7 +33,7 @@ import { readFileSync } from 'fs';
33
33
  // @ts-ignore This will be available when the app uses it.
34
34
  // eslint-disable-next-line import/no-unresolved
35
35
  import packageJsons from '../../../../package.json';
36
- import type { PackageJson } from './AppTypes';
36
+ import type { PackageJson } from '../../ipc/MetaFiles';
37
37
 
38
38
  let packageJson: PackageJson = packageJsons;
39
39
 
@@ -7,8 +7,8 @@
7
7
  import { ApplicationInsights } from '@microsoft/applicationinsights-web';
8
8
  import type Systeminformation from 'systeminformation';
9
9
 
10
+ import type { PackageJson } from '../../ipc/MetaFiles';
10
11
  import logger from '../logging';
11
- import type { PackageJson } from './AppTypes';
12
12
  import { isDevelopment } from './environment';
13
13
  import {
14
14
  deleteIsSendingUsageData,