From 848b5a3519f85594c9ce4e684c95f75a7bb8fac4 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Fri, 9 Feb 2024 10:56:06 -0500 Subject: [PATCH 1/4] Show static logo if Ruffle logo fails to load with Ruffle --- src/components/logo.tsx | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/logo.tsx b/src/components/logo.tsx index 4dd8ef23..74420ad1 100644 --- a/src/components/logo.tsx +++ b/src/components/logo.tsx @@ -35,6 +35,23 @@ export default class InteractiveLogo extends React.Component { 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. @@ -54,16 +71,16 @@ export default class InteractiveLogo extends React.Component { 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; @@ -75,6 +92,7 @@ export default class InteractiveLogo extends React.Component {