diff --git a/src/firmware/actions.ts b/src/firmware/actions.ts index 9d3ef72a..7a8549bc 100644 --- a/src/firmware/actions.ts +++ b/src/firmware/actions.ts @@ -120,15 +120,12 @@ export type FailToFinishReason = /** * Creates a new action to flash firmware to a hub. * @param data The firmware zip file data or `null` to get firmware later. - * @param customProgram If defined, flash the path of a program from file storage, - * otherwise use the main.py program from firmware.zip. * @param hubName A custom hub name or an empty string to use the default name. */ export const flashFirmware = createAction( - (data: ArrayBuffer | null, customProgram: string | undefined, hubName: string) => ({ + (data: ArrayBuffer | null, hubName: string) => ({ type: 'flashFirmware.action.flashFirmware', data, - customProgram, hubName, }), ); diff --git a/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx b/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx index e2f24aac..e9964f56 100644 --- a/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx +++ b/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx @@ -7,7 +7,6 @@ import { Callout, Checkbox, Classes, - Code, Collapse, ControlGroup, DialogStep, @@ -15,15 +14,12 @@ import { Icon, InputGroup, Intent, - MenuItem, MultistepDialog, NonIdealState, Pre, Spinner, - Switch, } from '@blueprintjs/core'; import { Classes as Classes2, Popover2 } from '@blueprintjs/popover2'; -import { Select2 } from '@blueprintjs/select'; import { FirmwareMetadata, HubType } from '@pybricks/firmware'; import { fileOpen } from 'browser-fs-access'; import classNames from 'classnames'; @@ -33,7 +29,6 @@ import { useDispatch } from 'react-redux'; import { useLocalStorage } from 'usehooks-ts'; import { alertsShowAlert } from '../../alerts/actions'; import { - appName, pybricksUsbDfuWindowsDriverInstallUrl, pybricksUsbLinuxUdevRulesUrl, } from '../../app/constants'; @@ -42,13 +37,10 @@ import { Hub, hubBootloaderType, hubHasBluetoothButton, - hubHasExternalFlash, hubHasUSB, } from '../../components/hubPicker'; import { HubPicker } from '../../components/hubPicker/HubPicker'; import { useHubPickerSelectedHub } from '../../components/hubPicker/hooks'; -import { FileMetadata } from '../../fileStorage'; -import { useFileStorageMetadata } from '../../fileStorage/hooks'; import { useSelector } from '../../reducers'; import { ensureError } from '../../utils'; import ExternalLinkIcon from '../../utils/ExternalLinkIcon'; @@ -363,27 +355,16 @@ const AcceptLicensePanel: React.VoidFunctionComponent = }; type SelectOptionsPanelProps = { - hubType: Hub; hubName: string; - includeProgram: boolean; - selectedIncludeFile: FileMetadata | undefined; onChangeHubName(hubName: string): void; - onChangeIncludeProgram(includeProgram: boolean): void; - onChangeSelectedIncludeFile(selectedIncludeFile: FileMetadata | undefined): void; }; const ConfigureOptionsPanel: React.VoidFunctionComponent = ({ - hubType, hubName, - includeProgram, - selectedIncludeFile, onChangeHubName, - onChangeIncludeProgram, - onChangeSelectedIncludeFile, }) => { const i18n = useI18n(); const isHubNameValid = validateHubName(hubName); - const files = useFileStorageMetadata(); return (
@@ -415,86 +396,6 @@ const ConfigureOptionsPanel: React.VoidFunctionComponent - - {(hubHasExternalFlash(hubType) && ( -

- {i18n.translate( - 'optionsPanel.customMain.notApplicable.message', - )} -

- )) || ( - - main.py }, - )} - checked={includeProgram} - onChange={(e) => - onChangeIncludeProgram( - (e.target as HTMLInputElement).checked, - ) - } - /> - ( - - )} - noResults={ - - } - filterable={false} - popoverProps={{ minimal: true }} - disabled={!includeProgram} - onItemSelect={onChangeSelectedIncludeFile} - > -
); }; @@ -617,8 +518,6 @@ export const InstallPybricksDialog: React.VoidFunctionComponent = () => { const { isOpen } = useSelector((s) => s.firmware.installPybricksDialog); const dispatch = useDispatch(); const [hubName, setHubName] = useState(''); - const [includeProgram, setIncludeProgram] = useState(false); - const [selectedIncludeFile, setSelectedIncludeFile] = useState(); const [licenseAccepted, setLicenseAccepted] = useState(false); const [hubType] = useHubPickerSelectedHub(); const { firmwareData } = useFirmware(hubType); @@ -646,7 +545,6 @@ export const InstallPybricksDialog: React.VoidFunctionComponent = () => { firmwareInstallPybricksDialogAccept( hubBootloaderType(selectedHubType), selectedFirmwareData?.firmwareZip ?? new ArrayBuffer(0), - selectedIncludeFile?.path, hubName, ), ), @@ -685,13 +583,8 @@ export const InstallPybricksDialog: React.VoidFunctionComponent = () => { title={i18n.translate('optionsPanel.title')} panel={ } backButtonProps={{ text: i18n.translate('backButton.label') }} diff --git a/src/firmware/installPybricksDialog/actions.ts b/src/firmware/installPybricksDialog/actions.ts index 6653de68..00449b5d 100644 --- a/src/firmware/installPybricksDialog/actions.ts +++ b/src/firmware/installPybricksDialog/actions.ts @@ -14,20 +14,13 @@ type FlashMethod = 'ble-lwp3-bootloader' | 'usb-lego-dfu'; * Action that indicates the user accepted the install Pybricks firmware dialog. * @param flashMethod The connection method and protocol used for flashing. * @param firmwareZip The firmware.zip raw data. - * @param customProgram Optional path of custom program to include when flashing firmware. * @param hubName The hub name to use when flashing firmware. */ export const firmwareInstallPybricksDialogAccept = createAction( - ( - flashMethod: FlashMethod, - firmwareZip: ArrayBuffer, - customProgram: string | undefined, - hubName: string, - ) => ({ + (flashMethod: FlashMethod, firmwareZip: ArrayBuffer, hubName: string) => ({ type: 'firmware.installPybricksDialog.action.accept', flashMethod, firmwareZip, - customProgram, hubName, }), ); diff --git a/src/firmware/installPybricksDialog/translations/en.json b/src/firmware/installPybricksDialog/translations/en.json index 12eaeed0..3f254b24 100644 --- a/src/firmware/installPybricksDialog/translations/en.json +++ b/src/firmware/installPybricksDialog/translations/en.json @@ -50,19 +50,6 @@ "labelInfo": "(optional)", "help": "Enter a name here to customize the hub name when flashing the firmware. This name will be used in the Bluetooth advertising data and can be used to identify the hub when connecting.", "error": "The name is too long." - }, - "customMain": { - "label": "Include custom program", - "labelInfo": "(optional)", - "notApplicable": { - "message": "This hub has external flash memory so including a custom program when flashing firmware is not needed." - }, - "include": { - "label": "Include selected program as {main}", - "noSelection": "(no selection)", - "noFiles": "(no files)", - "help": "Enable to include your program when flashing the firmware or disable to use the default program. Flashing your program along with the firmware will allow you to run your program without being connected to {appName}" - } } }, "bootloaderPanel": { diff --git a/src/firmware/sagas.test.ts b/src/firmware/sagas.test.ts index e1a63f22..e66823cc 100644 --- a/src/firmware/sagas.test.ts +++ b/src/firmware/sagas.test.ts @@ -88,7 +88,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, 'test name')); + saga.put(flashFirmwareAction(null, 'test name')); // first step is to connect to the hub bootloader @@ -236,7 +236,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, 'test name')); + saga.put(flashFirmwareAction(null, 'test name')); // first step is to connect to the hub bootloader @@ -366,7 +366,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -416,7 +416,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -484,7 +484,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -548,7 +548,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -615,7 +615,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -675,7 +675,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -741,7 +741,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -824,7 +824,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -890,7 +890,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -989,7 +989,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -1097,7 +1097,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -1245,7 +1245,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader @@ -1394,7 +1394,6 @@ describe('flashFirmware', () => { saga.put( flashFirmwareAction( await zip.generateAsync({ type: 'arraybuffer' }), - undefined, '', ), ); @@ -1547,7 +1546,6 @@ describe('flashFirmware', () => { saga.put( flashFirmwareAction( await zip.generateAsync({ type: 'arraybuffer' }), - undefined, '', ), ); @@ -1595,7 +1593,6 @@ describe('flashFirmware', () => { saga.put( flashFirmwareAction( await zip.generateAsync({ type: 'arraybuffer' }), - undefined, '', ), ); @@ -1642,7 +1639,6 @@ describe('flashFirmware', () => { saga.put( flashFirmwareAction( await zip.generateAsync({ type: 'arraybuffer' }), - undefined, '', ), ); @@ -1703,7 +1699,6 @@ describe('flashFirmware', () => { saga.put( flashFirmwareAction( await zip.generateAsync({ type: 'arraybuffer' }), - undefined, '', ), ); @@ -1765,7 +1760,6 @@ describe('flashFirmware', () => { saga.put( flashFirmwareAction( await zip.generateAsync({ type: 'arraybuffer' }), - undefined, '', ), ); @@ -1830,7 +1824,6 @@ describe('flashFirmware', () => { saga.put( flashFirmwareAction( await zip.generateAsync({ type: 'arraybuffer' }), - undefined, '', ), ); @@ -1917,7 +1910,7 @@ describe('flashFirmware', () => { // saga is triggered by this action - saga.put(flashFirmwareAction(null, undefined, '')); + saga.put(flashFirmwareAction(null, '')); // first step is to connect to the hub bootloader diff --git a/src/firmware/sagas.ts b/src/firmware/sagas.ts index e3daeb98..3045716b 100644 --- a/src/firmware/sagas.ts +++ b/src/firmware/sagas.ts @@ -31,11 +31,6 @@ import { takeEvery, } from 'typed-redux-saga/macro'; import { alertsDidShowAlert, alertsShowAlert } from '../alerts/actions'; -import { - fileStorageDidFailToReadFile, - fileStorageDidReadFile, - fileStorageReadFile, -} from '../fileStorage/actions'; import { checksumRequest, checksumResponse, @@ -192,11 +187,10 @@ function* firmwareIterator(data: DataView, maxSize: number): Generator { * Loads Pybricks firmware from a .zip file. * * @param data The zip file raw data - * @param program User program or `undefined` to use main.py from firmware.zip + * @param hubName Optional custom name for the hub. */ function* loadFirmware( data: ArrayBuffer, - program: string | undefined, hubName: string, ): SagaGenerator<{ firmware: Uint8Array; deviceId: HubType }> { const [reader, readerErr] = yield* call(() => maybe(FirmwareReader.load(data))); @@ -223,16 +217,7 @@ function* loadFirmware( // v1.x allows appending main.py to firmware, later versions do not if (metadataIsV100(metadata) || metadataIsV110(metadata)) { - // if a user program was not given, then use main.py from the firmware.zip - if (program === undefined) { - program = yield* call(() => reader.readMainPy()); - } - - // REVISIT: the firmware may eventually be changed to allow no main.py - // for now, ensure there is a program even if it does nothing - if (!program) { - program = ''; - } + const program = (yield* call(() => reader.readMainPy())) ?? ''; if (![5, 6].includes(metadata['mpy-abi-version'])) { yield* put( @@ -396,37 +381,8 @@ function* handleFlashFirmware(action: ReturnType): Generat let firmware: Uint8Array | undefined = undefined; let deviceId: HubType | undefined = undefined; - let program: string | undefined = undefined; - - if (action.customProgram) { - yield* put(fileStorageReadFile(action.customProgram)); - - const { didRead, didFailToRead } = yield* race({ - didRead: take( - fileStorageDidReadFile.when((a) => a.path === action.customProgram), - ), - didFailToRead: take( - fileStorageDidFailToReadFile.when( - (a) => a.path === action.customProgram, - ), - ), - }); - - if (didFailToRead) { - throw didFailToRead.error; - } - - defined(didRead); - - program = didRead.contents; - } - if (action.data !== null) { - ({ firmware, deviceId } = yield* loadFirmware( - action.data, - program, - action.hubName, - )); + ({ firmware, deviceId } = yield* loadFirmware(action.data, action.hubName)); } yield* put(connect()); @@ -468,11 +424,7 @@ function* handleFlashFirmware(action: ReturnType): Generat } const data = yield* call(() => response.arrayBuffer()); - ({ firmware, deviceId } = yield* loadFirmware( - data, - program, - action.hubName, - )); + ({ firmware, deviceId } = yield* loadFirmware(data, action.hubName)); if (deviceId !== undefined && info.hubType !== deviceId) { yield* put(didFailToFinish(FailToFinishReasonType.DeviceMismatch)); @@ -746,11 +698,7 @@ function* handleFlashUsbDfu(action: ReturnType): Gen }), ); - const { firmware, deviceId } = yield* loadFirmware( - action.data, - undefined, - action.hubName, - ); + const { firmware, deviceId } = yield* loadFirmware(action.data, action.hubName); if (deviceId !== productIdMap.get(device.productId)) { yield* put(alertsShowAlert('firmware', 'firmwareMismatch')); @@ -876,13 +824,7 @@ function* handleInstallPybricks(): Generator { switch (accepted.flashMethod) { case 'ble-lwp3-bootloader': - yield* put( - flashFirmware( - accepted.firmwareZip, - accepted.customProgram, - accepted.hubName, - ), - ); + yield* put(flashFirmware(accepted.firmwareZip, accepted.hubName)); break; case 'usb-lego-dfu': yield* put(firmwareFlashUsbDfu(accepted.firmwareZip, accepted.hubName));