Skip to content

Commit d084d5b

Browse files
committed
refactor: simplify getArduinoBoardHost function and improve error handling
1 parent 0719779 commit d084d5b

File tree

1 file changed

+7
-10
lines changed
  • scratch-prg-extensions/extensions/src/arduino_basics

1 file changed

+7
-10
lines changed

scratch-prg-extensions/extensions/src/arduino_basics/index.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ const details: ExtensionMenuDisplayDetails = {
1313
menuSelectColor: "#62AEB2",
1414
};
1515

16-
// Get Arduino board IP or hostname from URL parameter - required
16+
// Get Arduino board IP or hostname from URL parameter
1717
const getArduinoBoardHost = () => {
18-
if (typeof window !== "undefined" && window.location) {
19-
const urlParams = new URLSearchParams(window.location.search);
20-
const boardHost = urlParams.get("host");
21-
if (boardHost) {
22-
console.log(`Connecting to Arduino board: ${boardHost}`);
23-
return boardHost;
24-
}
25-
}
26-
throw new Error("Arduino board host required. Add ?host=arduino_board_ip_or_name to the URL");
18+
const urlParams = new URLSearchParams(window.location.search);
19+
const boardHost = urlParams.get("host");
20+
if (boardHost) {
21+
return boardHost
22+
}
23+
return window.location.hostname;
2724
};
2825

2926
// TODO: make the block to support the brightness `0-7' of the leds

0 commit comments

Comments
 (0)