Skip to content

Commit

Permalink
Show static logo if Ruffle logo fails to load with Ruffle
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs committed Feb 16, 2024
1 parent c770f0f commit 51dc269
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/components/logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
this.container = React.createRef();
}

private createStaticLogo() {
if (this.container.current) {
const staticLogo = document.createElement("IMG") as HTMLImageElement;
staticLogo.src = "/logo.svg";
staticLogo.alt = "Ruffle Logo";
staticLogo.style.width = "85%";
staticLogo.style.height = "auto";
staticLogo.style.margin = "0 auto";
staticLogo.style.display = "block";
staticLogo.style.position = "relative";
staticLogo.style.top = "50%";
staticLogo.style.transform = "translateY(-50%)";
this.container.current.textContent = "";
this.container.current.appendChild(staticLogo);
}
}

private load() {
if (this.player) {
// Already loaded.
Expand All @@ -54,16 +71,16 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
contextMenu: "off",
splashScreen: false,
preferredRenderer: "canvas",
}).catch(() => {
this.createStaticLogo();
});
this.player.style.width = "100%";
this.player.style.height = "100%";
} else {
this.createStaticLogo();
}
}

componentDidMount() {
this.load();
}

componentWillUnmount() {
this.player?.remove();
this.player = null;
Expand All @@ -75,6 +92,7 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
<Script
src="https://unpkg.com/@ruffle-rs/ruffle"
onReady={() => this.load()}
onError={() => this.createStaticLogo()}
/>
<div ref={this.container} className={this.props.className} />
</>
Expand Down

0 comments on commit 51dc269

Please sign in to comment.