Skip to content

Commit 51dc269

Browse files
committed
Show static logo if Ruffle logo fails to load with Ruffle
1 parent c770f0f commit 51dc269

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/components/logo.tsx

+22-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
3535
this.container = React.createRef();
3636
}
3737

38+
private createStaticLogo() {
39+
if (this.container.current) {
40+
const staticLogo = document.createElement("IMG") as HTMLImageElement;
41+
staticLogo.src = "/logo.svg";
42+
staticLogo.alt = "Ruffle Logo";
43+
staticLogo.style.width = "85%";
44+
staticLogo.style.height = "auto";
45+
staticLogo.style.margin = "0 auto";
46+
staticLogo.style.display = "block";
47+
staticLogo.style.position = "relative";
48+
staticLogo.style.top = "50%";
49+
staticLogo.style.transform = "translateY(-50%)";
50+
this.container.current.textContent = "";
51+
this.container.current.appendChild(staticLogo);
52+
}
53+
}
54+
3855
private load() {
3956
if (this.player) {
4057
// Already loaded.
@@ -54,16 +71,16 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
5471
contextMenu: "off",
5572
splashScreen: false,
5673
preferredRenderer: "canvas",
74+
}).catch(() => {
75+
this.createStaticLogo();
5776
});
5877
this.player.style.width = "100%";
5978
this.player.style.height = "100%";
79+
} else {
80+
this.createStaticLogo();
6081
}
6182
}
6283

63-
componentDidMount() {
64-
this.load();
65-
}
66-
6784
componentWillUnmount() {
6885
this.player?.remove();
6986
this.player = null;
@@ -75,6 +92,7 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
7592
<Script
7693
src="https://unpkg.com/@ruffle-rs/ruffle"
7794
onReady={() => this.load()}
95+
onError={() => this.createStaticLogo()}
7896
/>
7997
<div ref={this.container} className={this.props.className} />
8098
</>

0 commit comments

Comments
 (0)