Skip to content

Commit ab72ff2

Browse files
authored
Use Default Theme in Multiplayer (#10399)
Themes impact multiplayer in a few places (though not many, since it primarily uses Tailwind). Notably, the settings dropdown and a few buttons. Actually supporting themes would be a big undertaking, so for now, I've just set it up to always load the default theme. With themes, the presence buttons were getting dark backgrounds because they were disabled. This looked odd, so I've added a tailwind class to force them back to their white backgrounds instead. I also had to fix a bug in our multiplayer serve that assumed all webconfig values were strings (no longer the case with ocv).
1 parent fca9783 commit ab72ff2

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

multiplayer/public/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<link rel="stylesheet" href="/blb/icons.css" type="text/css">
1414
<link rel="stylesheet" href="/blb/react-common-multiplayer.css" type="text/css">
1515
</head>
16-
<body>
16+
<body class="pxt-theme-root">
1717
<noscript>You need to enable JavaScript to run this app.</noscript>
1818

1919
<!-- @include tracking.html -->
@@ -23,6 +23,7 @@
2323
<script type="text/javascript" src="/blb/target.js"></script>
2424
<script type="text/javascript" src="/blb/pxtlib.js"></script>
2525
<script type="text/javascript" src="/blb/pxtsim.js"></script>
26+
<script type="text/javascript" src="/blb/pxtrcdeps.js"></script>
2627

2728

2829
<div id="root"></div>

multiplayer/src/App.css

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
--black: #000;
33
--white: #fff;
44

5-
--primary-color: #E77038;
6-
--secondary-color: #ffeb9a;
7-
--tertiary-color: #E77038;
8-
95
--header-height: 4rem;
106
--header-padding-top: 1rem;
117

@@ -29,19 +25,19 @@ code {
2925
font-family: var(--body-font-family);
3026
}
3127
.common-button.primary {
32-
background: var(--primary-color);
33-
color: #fff;
34-
border: 1px solid var(--primary-color);
28+
background: var(--pxt-primary-background);
29+
color: var(--pxt-primary-foreground);
30+
border: 1px solid var(--pxt-primary-background);
3531
}
3632
.common-button.secondary {
37-
background: var(--secondary-color);
38-
color: #fff;
39-
border: 1px solid var(--secondary-color);
33+
background: var(--pxt-secondary-background);
34+
color: var(--pxt-secondary-foreground);
35+
border: 1px solid var(--pxt-secondary-background);
4036
}
4137
.common-button.tertiary {
42-
background: var(--tertiary-color);
43-
color: #fff;
44-
border: 1px solid var(--tertiary-color);
38+
background: var(--pxt-tertiary-background);
39+
color: var(--pxt-tertiary-foreground);
40+
border: 1px solid var(--pxt-tertiary-background);
4541
}
4642

4743
img.pixel-art-image {

multiplayer/src/App.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { setDeepLinks, setTargetConfig } from "./state/actions";
1212
import { cleanupJoinCode, cleanupShareCode } from "./util";
1313
import { joinGameAsync, hostGameAsync, visibilityChanged } from "./epics";
1414
import { useVisibilityChange } from "./hooks";
15+
import { ThemeManager } from "react-common/components/theming/themeManager";
1516

1617
// eslint-disable-next-line import/no-unassigned-import
1718
import "./App.css";
@@ -44,6 +45,17 @@ function App() {
4445
.catch(() => setAuthCheckComplete(true));
4546
}, [setAuthCheckComplete]);
4647

48+
useEffect(() => {
49+
// We don't currently support switching themes in multiplayer, so just load the default.
50+
const themeId = pxt.appTarget?.appTheme?.defaultColorTheme;
51+
if (themeId) {
52+
const themeManager = ThemeManager.getInstance(document);
53+
if (themeId !== themeManager.getCurrentColorTheme()?.id) {
54+
themeManager.switchColorTheme(themeId);
55+
}
56+
}
57+
});
58+
4759
const parseUrlParams = useCallback(() => {
4860
let params: URLSearchParams | undefined = undefined;
4961
if (window.location.hash[1] === "?") {

multiplayer/src/components/Presence.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function PlayerMenu(
141141
<div>
142142
<div className="tw-px-[50%]">{menu}</div>
143143
<Button
144-
className="tw-rounded-full tw-m-0 tw-p-0"
144+
className="tw-rounded-full tw-m-0 tw-p-0 !tw-bg-white"
145145
hardDisabled={!menu}
146146
label={
147147
<div

multiplayer/src/components/TabButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function Render(props: {
2222
}
2323
style={{
2424
borderColor: props.selected
25-
? "var(--primary-color)"
25+
? "var(--pxt-primary-background)"
2626
: "transparent",
2727
}}
2828
></div>

multiplayer/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ window.addEventListener("DOMContentLoaded", () => {
4949
const wc = pxt.webConfig as any;
5050

5151
for (const key of Object.keys(wc)) {
52-
if (wc[key]?.startsWith("/") && wc[key]?.indexOf("worker") == -1) {
52+
if (typeof wc[key] === "string" && wc[key]?.startsWith("/") && wc[key]?.indexOf("worker") == -1) {
5353
wc[key] = `http://localhost:3232${wc[key]}`;
5454
}
5555
}

multiplayer/tailwind.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module.exports = {
66
extend: {
77
/* TODO multiplayer : How does high contrast work? */
88
colors: {
9-
"primary-color": "var(--primary-color)",
10-
"secondary-color": "var(--secondary-color)",
11-
"tertiary-color": "var(--tertiary-color)",
12-
"inactive-color": "var(--inactive-color)",
13-
"body-background-color": "var(--body-background-color);",
9+
"primary-color": "var(--pxt-primary-background)",
10+
"secondary-color": "var(--pxt-secondary-background)",
11+
"tertiary-color": "var(--pxt-tertiary-background)",
12+
"inactive-color": "var(--pxt-neutral-background3)",
13+
"body-background-color": "var(--pxt-neutral-background1);",
1414
white: "var(--white)",
1515
slot: {
1616
0: "rgb(var(--slot-0-color))", // empty slot

0 commit comments

Comments
 (0)