Skip to content

Commit b727b8a

Browse files
Enable the simulator service worker on beta/staging (#1181)
This is experimental at this point and is part of investigating PWA support for the micro:bit Python Editor.
1 parent 37da34f commit b727b8a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/simulator/Simulator.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useToken,
1212
VStack,
1313
} from "@chakra-ui/react";
14-
import { useEffect, useRef, useState } from "react";
14+
import { useEffect, useMemo, useRef, useState } from "react";
1515
import { IntlShape, useIntl } from "react-intl";
1616
import HideSplitViewButton from "../common/SplitView/HideSplitViewButton";
1717
import { topBarHeight } from "../deployment/misc";
@@ -43,14 +43,20 @@ const Simulator = ({
4343
minWidth,
4444
simFocus,
4545
}: SimulatorProps) => {
46-
const production =
47-
"https://python-simulator.usermbit.org/v/0.1/simulator.html";
48-
const staging =
49-
"https://python-simulator.usermbit.org/staging/simulator.html";
50-
const url = stage === "PRODUCTION" ? production : staging;
51-
// For testing with sim branches:
52-
//const branch = "upgrade-mpy";
53-
//const url = `https://review-python-simulator.usermbit.org/${branch}/simulator.html`;
46+
const [brand500] = useToken("colors", ["brand.500"]);
47+
const url = useMemo(() => {
48+
const production =
49+
"https://python-simulator.usermbit.org/v/0.1/simulator.html";
50+
const staging =
51+
"https://python-simulator.usermbit.org/staging/simulator.html?flag=sw";
52+
53+
// For testing with sim branches:
54+
//const branch = "upgrade-mpy";
55+
//const url = new URL(`https://review-python-simulator.usermbit.org/${branch}/simulator.html`);
56+
const url = new URL(stage === "PRODUCTION" ? production : staging);
57+
url.searchParams.append("color", brand500);
58+
return url.toString();
59+
}, [brand500]);
5460

5561
const ref = useRef<HTMLIFrameElement>(null);
5662
const intl = useIntl();
@@ -72,7 +78,6 @@ const Simulator = ({
7278
updateTranslations(simulator.current, intl);
7379
}, [simulator, intl]);
7480
const simControlsRef = useRef<HTMLDivElement>(null);
75-
const [brand500] = useToken("colors", ["brand.500"]);
7681
const [running, setRunning] = useState<RunningStatus>(RunningStatus.STOPPED);
7782
const previouslyShown = usePrevious(shown);
7883

@@ -117,7 +122,7 @@ const Simulator = ({
117122
<Box
118123
ref={ref}
119124
as="iframe"
120-
src={`${url}?color=${encodeURIComponent(brand500)}`}
125+
src={url}
121126
title={simulatorTitle}
122127
name={simulatorTitle}
123128
frameBorder="no"

0 commit comments

Comments
 (0)