diff --git a/src/ble/reducers.ts b/src/ble/reducers.ts index 808a42fa6..13d03950f 100644 --- a/src/ble/reducers.ts +++ b/src/ble/reducers.ts @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2020-2022 The Pybricks Authors +// Copyright (c) 2020-2024 The Pybricks Authors // // Manages state for the Bluetooth Low Energy connection. // This assumes that there is only one global connection to a single device. diff --git a/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx b/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx index b5643ab6e..39cc3d5e6 100644 --- a/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx +++ b/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2022-2023 The Pybricks Authors +// Copyright (c) 2022-2024 The Pybricks Authors import './installPybricksDialog.scss'; import { @@ -23,7 +23,7 @@ import { ChevronDown, ChevronRight, Error, Heart } from '@blueprintjs/icons'; import { FirmwareMetadata, HubType } from '@pybricks/firmware'; import { fileOpen } from 'browser-fs-access'; import classNames from 'classnames'; -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { VisuallyHidden } from 'react-aria'; import { useDropzone } from 'react-dropzone'; import { useDispatch } from 'react-redux'; @@ -383,12 +383,14 @@ const AcceptLicensePanel: React.FunctionComponent = ({ type SelectOptionsPanelProps = { hubName: string; + hubDefaultName: string; metadata: FirmwareMetadata | undefined; onChangeHubName(hubName: string): void; }; const ConfigureOptionsPanel: React.FunctionComponent = ({ hubName, + hubDefaultName, metadata, onChangeHubName, }) => { @@ -408,7 +410,7 @@ const ConfigureOptionsPanel: React.FunctionComponent = onMouseOver={(e) => e.preventDefault()} onMouseDown={(e) => e.stopPropagation()} intent={isHubNameValid ? Intent.NONE : Intent.DANGER} - placeholder="Pybricks Hub" + placeholder={hubDefaultName || 'Pybricks Hub'} rightElement={ isHubNameValid ? undefined : ( = ( export const InstallPybricksDialog: React.FunctionComponent = () => { const { isOpen } = useSelector((s) => s.firmware.installPybricksDialog); + const deviceName = useSelector((s) => s.ble.deviceName); const inProgress = useSelector( (s) => s.firmware.isFirmwareFlashUsbDfuInProgress || s.firmware.isFirmwareRestoreOfficialDfuInProgress, ); const dispatch = useDispatch(); + const [deviceNameLastConnected, setDeviceNameLastConnected] = useLocalStorage( + 'setting.lastConnectedDeviceName', + '', + ); const [hubName, setHubName] = useState(''); const [licenseAccepted, setLicenseAccepted] = useState(false); const [hubType] = useHubPickerSelectedHub(); @@ -472,6 +479,12 @@ export const InstallPybricksDialog: React.FunctionComponent = () => { ? getHubTypeFromMetadata(customFirmwareData?.metadata, hubType) : hubType; + useEffect(() => { + if (deviceName) { + setDeviceNameLastConnected(deviceName); + } + }, [deviceName, setDeviceNameLastConnected]); + return ( { firmwareInstallPybricksDialogAccept( hubBootloaderType(selectedHubType), selectedFirmwareData?.firmwareZip ?? new ArrayBuffer(0), - hubName, + hubName || deviceNameLastConnected, ), ), }} @@ -528,6 +541,7 @@ export const InstallPybricksDialog: React.FunctionComponent = () => { panel={