Skip to content

Commit

Permalink
fix: give more consistent and immediate feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed Oct 7, 2024
1 parent 6c55343 commit 246be4d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib/state/workspace.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type MicroPythonIO from "../micropython";
import type { IOEventTarget } from "../micropython";
import { workspace } from "./blockly.svelte";
import { popups } from "./popup.svelte";
import Error from "$components/core/popups/popups/Error.svelte";

export type LeaphyPort =
| SerialPort
Expand Down Expand Up @@ -120,13 +121,26 @@ function createPortState() {

let onReady: () => void;
let onFailure: () => void;
let showFeedback = false;
subscribe(async (port) => {
if (!port || reserved) return;

if (!port.readable || !port.writable) {
try {
await port.open({ baudRate: 115200 });
} catch (e) {
set(undefined);
if (showFeedback) {
popups.open({
component: Error,
data: {
title: "ROBOT_RESERVED",
message: "ROBOT_RESERVED_MESSAGE"
},
allowInteraction: false
})
}

onFailure();
throw e;
}
Expand Down Expand Up @@ -198,6 +212,7 @@ function createPortState() {
onFailure = reject;
}),
async requestPort(prompt: Prompt): Promise<SerialPort | USBDevice> {
showFeedback = prompt === Prompt.ALWAYS;
if (navigator.serial) {
if (prompt !== Prompt.ALWAYS) {
const [port] = await navigator.serial.getPorts();
Expand Down

0 comments on commit 246be4d

Please sign in to comment.