Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dont close when programming #449

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 4.2.1 - UNRELEASED

### Added

- Warning about closing the app while programming, which may lead to unwanted
consequences.

### Changed

- Update nrfutil device to v2.1.1.
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"prepare": "husky install"
},
"devDependencies": {
"@nordicsemiconductor/pc-nrfconnect-shared": "^157.0.0"
"@nordicsemiconductor/pc-nrfconnect-shared": "^161.0.0"
},
"eslintConfig": {
"extends": "./node_modules/@nordicsemiconductor/pc-nrfconnect-shared/config/eslintrc"
Expand Down
44 changes: 26 additions & 18 deletions src/components/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import Overlay from 'react-bootstrap/Overlay';
import Popover from 'react-bootstrap/Popover';
import { useDispatch, useSelector } from 'react-redux';
import {
AppDispatch,
Button,
colors,
Group,
logger,
preventAppCloseUntilComplete,
selectedDevice,
SidePanel,
Toggle,
Expand Down Expand Up @@ -165,7 +167,7 @@ const Mru = ({ mruFiles }: { mruFiles: string[] }) => {
};

const ControlPanel = () => {
const dispatch = useDispatch();
const dispatch = useDispatch<AppDispatch>();
const device = useSelector(selectedDevice);
const fileRegionSize = useSelector(getFileRegions)?.length;
const mruFiles = useSelector(getMruFiles);
Expand Down Expand Up @@ -216,24 +218,27 @@ const ControlPanel = () => {
variant="secondary"
className="w-100"
key="performRecover"
onClick={async () => {
onClick={() => {
if (!device) {
logger.error('No target device!');
return;
}

dispatch(setDeviceBusy(true));
try {
await dispatch(

preventAppCloseUntilComplete(
{
message: `The device is being recovered.
Closing application right now might result in some unknown behavior and might also brick the device.
Are you sure you want to continue?`,
},
dispatch(
jlinkTargetActions.recover(
device,
deviceDefinition
)
);
} catch (e) {
/* empty */
}
dispatch(setDeviceBusy(false));
).finally(() => dispatch(setDeviceBusy(false)))
);
}}
disabled={
isMcuboot ||
Expand All @@ -249,24 +254,26 @@ const ControlPanel = () => {
variant="secondary"
key="performRecoverAndWrite"
className="w-100"
onClick={async () => {
onClick={() => {
if (!device) {
logger.error('No target device!');
return;
}

dispatch(setDeviceBusy(true));
try {
await dispatch(
preventAppCloseUntilComplete(
{
message: `The device is being programmed.
Closing application right now might result in some unknown behavior and might also brick the device.
Are you sure you want to continue?`,
},
dispatch(
jlinkTargetActions.recoverAndWrite(
device,
deviceDefinition
)
);
} catch (e) {
/* empty */
}
dispatch(setDeviceBusy(false));
).finally(() => dispatch(setDeviceBusy(false)))
);
}}
disabled={
isMcuboot ||
Expand Down Expand Up @@ -338,9 +345,10 @@ const ControlPanel = () => {
logger.error('No target device!');
return;
}
// Refresh all files in case that some files have been updated right before write action.

dispatch(setDeviceBusy(true));
try {
// Refresh all files in case that some files have been updated right before write action.
refreshAllFiles();
dispatch(targetActions.write(device));
} catch (e) {
Expand Down
17 changes: 15 additions & 2 deletions src/components/McuUpdateDialogView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import ProgressBar from 'react-bootstrap/ProgressBar';
import Tooltip from 'react-bootstrap/Tooltip';
import { useDispatch, useSelector } from 'react-redux';
import {
addConfirmBeforeClose,
Alert,
classNames,
clearConfirmBeforeClose,
clearWaitForDevice,
DialogButton,
GenericDialog,
Expand Down Expand Up @@ -130,7 +132,19 @@ const McuUpdateDialogView = () => {
return;
}

abortController.current = new AbortController();

setWriting(true);
dispatch(
addConfirmBeforeClose({
id: 'mcuProgramming',
message: `The device is being programmed.
Closing application right now might result in some unknown behavior and might also brick the device.
Are you sure you want to continue?`,
onClose: () => abortController.current.abort(),
})
);

reset();
start();

Expand All @@ -142,8 +156,6 @@ const McuUpdateDialogView = () => {
})
);

abortController.current = new AbortController();

performUpdate(
device,
fwPath,
Expand Down Expand Up @@ -178,6 +190,7 @@ const McuUpdateDialogView = () => {
dispatch(clearWaitForDevice());
dispatch(canWrite());
setWriting(false);
clearConfirmBeforeClose('mcuProgramming');
});
};

Expand Down
19 changes: 17 additions & 2 deletions src/components/ModemUpdateDialogView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Form from 'react-bootstrap/Form';
import ProgressBar from 'react-bootstrap/ProgressBar';
import { useDispatch, useSelector } from 'react-redux';
import {
addConfirmBeforeClose,
Alert,
clearConfirmBeforeClose,
DialogButton,
GenericDialog,
logger,
Expand Down Expand Up @@ -108,10 +110,20 @@ const ModemUpdateDialogView = () => {
reset();
start();

abortController.current = new AbortController();

setWriting(true);
dispatch(
addConfirmBeforeClose({
id: 'modemProgramming',
message: `The device is being programmed.
Closing application right now might result in some unknown behavior and might also brick the device.
Are you sure you want to continue?`,
onClose: () => abortController.current.abort(),
})
);
setProgress(progress);

abortController.current = new AbortController();
performUpdate(
device,
modemFwName,
Expand Down Expand Up @@ -147,7 +159,10 @@ const ModemUpdateDialogView = () => {
setWritingFail(true);
}
})
.finally(() => setWriting(false));
.finally(() => {
setWriting(false);
clearConfirmBeforeClose('modemProgramming');
});
};

useEffect(() => {
Expand Down
13 changes: 13 additions & 0 deletions src/components/UsbSdfuUpdateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Form from 'react-bootstrap/Form';
import ProgressBar from 'react-bootstrap/ProgressBar';
import { useDispatch, useSelector } from 'react-redux';
import {
addConfirmBeforeClose,
Alert,
clearConfirmBeforeClose,
clearWaitForDevice,
describeError,
DialogButton,
Expand Down Expand Up @@ -82,6 +84,15 @@ export default () => {
);

setWriting(true);
dispatch(
addConfirmBeforeClose({
id: 'usbSdfuProgramming',
message: `The device is being programmed.
Closing application right now might result in some unknown behavior and might also brick the device.
Are you sure you want to continue?`,
})
);

try {
await operateDFU(device, images, programmingProgress => {
let updatedProgress: WithRequired<Progress, 'message'> = {
Expand All @@ -106,7 +117,9 @@ export default () => {
setWritingFailError(error.message);
setWritingFail(true);
}

setWriting(false);
dispatch(clearConfirmBeforeClose('usbSdfuProgramming'));

// Operation done reconnect one more time only
dispatch(
Expand Down