import * as React from "react"; import { canUseWebSerial, enableWebSerialAsync } from "./deploy"; import { projectView } from "./extension"; let confirmAsync: (options: any) => Promise; export function bluetoothTryAgainAsync(): Promise { return confirmAsync({ header: lf("Bluetooth download failed..."), jsx: , hasCloseIcon: false, hideCancel: true, hideAgree: false, agreeLbl: lf("Try again") }).then(r => {}); } function enableWebSerialAndCompileAsync() { return enableWebSerialAsync() .then(() => Promise.delay(500)) .then(() => projectView.compile()); } let bluetoothDialogShown = false; function explainWebSerialPairingAsync(): Promise { if (!confirmAsync || bluetoothDialogShown) return Promise.resolve(); bluetoothDialogShown = true; return confirmAsync({ header: lf("Bluetooth pairing"), hasCloseIcon: false, hideCancel: true, buttons: [{ label: lf("Help"), icon: "question circle", className: "lightgrey", url: "/bluetooth" }], jsx:

{lf("You will be prompted to select a serial port.")} {pxt.BrowserUtils.isWindows() ? lf("Look for 'Standard Serial over Bluetooth link'.") : lf("Loop for 'cu.EV3-SerialPort'.")} {lf("If you have paired multiple EV3, you might have to try out multiple ports until you find the correct one.")}

}).then(() => { }) } export function showUploadDialogAsync(fn: string, url: string, _confirmAsync: (options: any) => Promise): Promise { confirmAsync = _confirmAsync; // https://msdn.microsoft.com/en-us/library/cc848897.aspx // "For security reasons, data URIs are restricted to downloaded resources. // Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements" const downloadAgain = !pxt.BrowserUtils.isIE() && !pxt.BrowserUtils.isEdge(); const docUrl = pxt.appTarget.appTheme.usbDocs; const jsx =
{lf("First time here?")}
{lf("You must have version 1.10E or above of the firmware")}
{lf("Check your firmware version here and update if needed")}
1 {lf("Connect the EV3 to your computer with a USB cable")}
{lf("Use the miniUSB port on the top of the EV3 Brick")}
2 {lf("Move the .uf2 file to the EV3 Brick")}
{lf("Locate the downloaded .uf2 file and drag it to the EV3 USB drive")}
; return confirmAsync({ header: lf("Download to your EV3"), jsx, hasCloseIcon: true, hideCancel: true, hideAgree: false, agreeLbl: lf("I got it"), className: 'downloaddialog', buttons: [canUseWebSerial() ? { label: lf("Bluetooth"), icon: "bluetooth", className: "bluetooth focused", onclick: () => { pxt.tickEvent("bluetooth.enable"); explainWebSerialPairingAsync() .then(() => enableWebSerialAndCompileAsync()) .done(); } } : undefined, downloadAgain ? { label: fn, icon: "download", className: "lightgrey focused", url, fileName: fn } : undefined, docUrl ? { label: lf("Help"), icon: "help", className: "lightgrey", url: docUrl } : undefined] //timeout: 20000 }).then(() => { }); }