From d77d712514073893c7ec6bda31d7ad34cf7e404b Mon Sep 17 00:00:00 2001 From: Grace Date: Wed, 19 Feb 2025 10:25:27 +0000 Subject: [PATCH 1/2] Upgrade microbit-connection library --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f15070e59..e7272d7c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@codemirror/view": "^6.26.3", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@microbit/microbit-connection": "^0.0.0-alpha.33", + "@microbit/microbit-connection": "^0.0.0-alpha.35", "@microbit/microbit-fs": "^0.10.0", "@sanity/block-content-to-react": "^3.0.0", "@sanity/image-url": "^1.0.1", @@ -4020,9 +4020,9 @@ } }, "node_modules/@microbit/microbit-connection": { - "version": "0.0.0-alpha.33", - "resolved": "https://registry.npmjs.org/@microbit/microbit-connection/-/microbit-connection-0.0.0-alpha.33.tgz", - "integrity": "sha512-UnETgYm/ZkMDxq2qEG+7FVoUrhXTV0Kc2WE1v3kXDCaoknQn+uYr0MIbQ4/5AqtlfAmigUYLFXPFTGBXnV4L+g==", + "version": "0.0.0-alpha.35", + "resolved": "https://registry.npmjs.org/@microbit/microbit-connection/-/microbit-connection-0.0.0-alpha.35.tgz", + "integrity": "sha512-Zya42Bivjm7qBaRXyi5A8472f41f1zzv5QFt8+esMkxwVWibZctOV8THmHE7eCUex9F7xSnYmgdaMdbtYxjVdg==", "dependencies": { "@microbit/microbit-universal-hex": "^0.2.2", "@types/web-bluetooth": "^0.0.20", diff --git a/package.json b/package.json index 46f10b429..06f60e0cb 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@codemirror/view": "^6.26.3", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@microbit/microbit-connection": "^0.0.0-alpha.33", + "@microbit/microbit-connection": "^0.0.0-alpha.35", "@microbit/microbit-fs": "^0.10.0", "@sanity/block-content-to-react": "^3.0.0", "@sanity/image-url": "^1.0.1", From b7093d1ba423ce2774e78708c3240b95902db52f Mon Sep 17 00:00:00 2001 From: Grace Date: Wed, 19 Feb 2025 10:51:02 +0000 Subject: [PATCH 2/2] Fix tsc --- src/App.tsx | 4 ++-- src/device/device-hooks.tsx | 6 +++--- src/device/mock.ts | 13 ++++++++++--- src/device/simulator.ts | 15 ++++++++++++--- .../codemirror/language-server/diagnostics.ts | 4 ++-- src/editor/codemirror/language-server/view.ts | 6 +++--- src/project/project-actions.tsx | 4 ++-- src/serial/serial-actions.ts | 4 ++-- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e4e197fcf..813fea79d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,7 +10,7 @@ import "./App.css"; import { DialogProvider } from "./common/use-dialogs"; import VisualViewPortCSSVariables from "./common/VisualViewportCSSVariables"; import { deployment, useDeployment } from "./deployment"; -import { MicrobitWebUSBConnection } from "@microbit/microbit-connection"; +import { createWebUSBConnection } from "@microbit/microbit-connection"; import { DeviceContextProvider } from "./device/device-hooks"; import { MockDeviceConnection } from "./device/mock"; import DocumentationProvider from "./documentation/documentation-hooks"; @@ -40,7 +40,7 @@ const isMockDeviceMode = () => const logging = deployment.logging; const device = isMockDeviceMode() ? new MockDeviceConnection() - : new MicrobitWebUSBConnection({ logging }); + : createWebUSBConnection({ logging }); const host = createHost(logging); const fs = new FileSystem(logging, host, fetchMicroPython); diff --git a/src/device/device-hooks.tsx b/src/device/device-hooks.tsx index 8c111d2c1..c85fe1dbc 100644 --- a/src/device/device-hooks.tsx +++ b/src/device/device-hooks.tsx @@ -15,13 +15,13 @@ import { useFileSystem } from "../fs/fs-hooks"; import { useLogging } from "../logging/logging-hooks"; import { ConnectionStatus, - DeviceConnection, + MicrobitWebUSBConnection, SerialDataEvent, ConnectionStatusEvent, } from "@microbit/microbit-connection"; import { SimulatorDeviceConnection } from "./simulator"; -const DeviceContext = React.createContext( +const DeviceContext = React.createContext( undefined ); @@ -234,7 +234,7 @@ export const DeviceContextProvider = ({ value: device, children, }: { - value: DeviceConnection; + value: MicrobitWebUSBConnection; children: ReactNode; }) => { const syncStatusState = useState(SyncStatus.OUT_OF_SYNC); diff --git a/src/device/mock.ts b/src/device/mock.ts index 3d2ec7dfc..817a3fbc4 100644 --- a/src/device/mock.ts +++ b/src/device/mock.ts @@ -6,7 +6,6 @@ import { BoardVersion, ConnectionStatus, - DeviceConnection, DeviceConnectionEventMap, FlashDataSource, FlashEvent, @@ -15,6 +14,8 @@ import { DeviceError, DeviceErrorCode, TypedEventTarget, + MicrobitWebUSBConnection, + SerialConnectionEventMap, } from "@microbit/microbit-connection"; /** @@ -25,8 +26,8 @@ import { * the connected state without a real device. */ export class MockDeviceConnection - extends TypedEventTarget - implements DeviceConnection + extends TypedEventTarget + implements MicrobitWebUSBConnection { status: ConnectionStatus = (navigator as any).usb ? ConnectionStatus.NO_AUTHORIZED_DEVICE @@ -51,6 +52,12 @@ export class MockDeviceConnection async initialize(): Promise {} dispose() {} + getDeviceId(): number | undefined { + return undefined; + } + setRequestDeviceExclusionFilters(): void {} + getDevice() {} + async softwareReset(): Promise {} async connect(): Promise { const next = this.connectResults.shift(); diff --git a/src/device/simulator.ts b/src/device/simulator.ts index fcaa42f12..fce601d38 100644 --- a/src/device/simulator.ts +++ b/src/device/simulator.ts @@ -7,9 +7,10 @@ import { BoardVersion, ConnectionStatus, ConnectionStatusEvent, - DeviceConnection, DeviceConnectionEventMap, FlashEvent, + MicrobitWebUSBConnection, + SerialConnectionEventMap, SerialDataEvent, SerialResetEvent, TypedEventTarget, @@ -178,8 +179,8 @@ class SimulatorEventMap extends DeviceConnectionEventMap { * This communicates with the iframe that is used to embed the simulator. */ export class SimulatorDeviceConnection - extends TypedEventTarget - implements DeviceConnection + extends TypedEventTarget + implements MicrobitWebUSBConnection { status: ConnectionStatus = ConnectionStatus.NO_AUTHORIZED_DEVICE; state: SimulatorState | undefined; @@ -425,4 +426,12 @@ export class SimulatorDeviceConnection "*" ); } + + getDeviceId(): number | undefined { + return undefined; + } + setRequestDeviceExclusionFilters(): void {} + async flash(): Promise {} + getDevice() {} + async softwareReset(): Promise {} } diff --git a/src/editor/codemirror/language-server/diagnostics.ts b/src/editor/codemirror/language-server/diagnostics.ts index bcb9c26f9..a6045addf 100644 --- a/src/editor/codemirror/language-server/diagnostics.ts +++ b/src/editor/codemirror/language-server/diagnostics.ts @@ -7,7 +7,7 @@ import { Text } from "@codemirror/state"; import * as LSP from "vscode-languageserver-protocol"; import { Action, Diagnostic } from "../lint/lint"; import { positionToOffset } from "./positions"; -import { DeviceConnection } from "@microbit/microbit-connection"; +import { MicrobitWebUSBConnection } from "@microbit/microbit-connection"; const reportMicrobitVersionApiUnsupported = "reportMicrobitVersionApiUnsupported"; @@ -22,7 +22,7 @@ const severityMapping = { export const diagnosticsMapping = ( document: Text, lspDiagnostics: LSP.Diagnostic[], - device: DeviceConnection, + device: MicrobitWebUSBConnection, warnOnV2OnlyFeatures: boolean, warnOnV2OnlyFeaturesAction: () => Action ): Diagnostic[] => diff --git a/src/editor/codemirror/language-server/view.ts b/src/editor/codemirror/language-server/view.ts index 30898d9e9..aeec02d33 100644 --- a/src/editor/codemirror/language-server/view.ts +++ b/src/editor/codemirror/language-server/view.ts @@ -17,7 +17,7 @@ import { autocompletion } from "./autocompletion"; import { BaseLanguageServerView, clientFacet, uriFacet } from "./common"; import { diagnosticsMapping } from "./diagnostics"; import { signatureHelp } from "./signatureHelp"; -import { DeviceConnection } from "@microbit/microbit-connection"; +import { MicrobitWebUSBConnection } from "@microbit/microbit-connection"; /** * The main extension. This synchronises the diagnostics between the client @@ -60,7 +60,7 @@ class LanguageServerView extends BaseLanguageServerView implements PluginValue { constructor( view: EditorView, - private device: DeviceConnection, + private device: MicrobitWebUSBConnection, private intl: IntlShape, private warnOnV2OnlyFeatures: boolean, private disableV2OnlyFeaturesWarning: () => void @@ -126,7 +126,7 @@ interface Actions { */ export function languageServer( client: LanguageServerClient, - device: DeviceConnection, + device: MicrobitWebUSBConnection, uri: string, intl: IntlShape, logging: Logging, diff --git a/src/project/project-actions.tsx b/src/project/project-actions.tsx index 46e4e8668..6ac24c17e 100644 --- a/src/project/project-actions.tsx +++ b/src/project/project-actions.tsx @@ -19,7 +19,7 @@ import { ActionFeedback } from "../common/use-action-feedback"; import { Dialogs } from "../common/use-dialogs"; import { ConnectionStatus, - DeviceConnection, + MicrobitWebUSBConnection, AfterRequestDevice, FlashDataError, DeviceError, @@ -105,7 +105,7 @@ export enum ConnectionAction { export class ProjectActions { constructor( private fs: FileSystem, - private device: DeviceConnection, + private device: MicrobitWebUSBConnection, private actionFeedback: ActionFeedback, private dialogs: Dialogs, private setSelection: (selection: WorkbenchSelection) => void, diff --git a/src/serial/serial-actions.ts b/src/serial/serial-actions.ts index f7ff5df50..da463b8ab 100644 --- a/src/serial/serial-actions.ts +++ b/src/serial/serial-actions.ts @@ -3,8 +3,8 @@ * * SPDX-License-Identifier: MIT */ +import { MicrobitWebUSBConnection } from "@microbit/microbit-connection"; import { Terminal } from "xterm"; -import { DeviceConnection } from "@microbit/microbit-connection"; import { Logging } from "../logging/logging"; /** @@ -13,7 +13,7 @@ import { Logging } from "../logging/logging"; export class SerialActions { constructor( private terminal: React.RefObject, - private device: DeviceConnection, + private device: MicrobitWebUSBConnection, private onSerialSizeChange: (size: "compact" | "open") => void, private logging: Logging ) {}