fix: correctly detect failed iframe loads

This commit is contained in:
Youwen Wu 2024-02-24 20:54:01 -08:00
parent 5f8a166cae
commit 25253c56fc
2 changed files with 38 additions and 26 deletions

View file

@ -1,18 +1,25 @@
<script lang="ts"> <script lang="ts">
import AppContainer from "../AppContainer.svelte"; import AppContainer from '../AppContainer.svelte'
import { Notifications } from "../../Notifications/notifications"; import { Notifications } from '../../Notifications/notifications'
import { onMount } from "svelte"; import { onMount } from 'svelte'
import { gbaEmulatorBootupSequence } from "../../Sequences/sequences"; import { gbaEmulatorBootupSequence } from '../../Sequences/sequences'
const handleError = () => {
Notifications.error(
"Failed to load the GBA Emulator app. Did you add it to the app/static/external-apps directory?"
);
};
onMount(() => { onMount(() => {
gbaEmulatorBootupSequence(); fetch('/static/external-apps/gba-emulator/index.html')
}); .then((res: Response) => {
if (!res.ok) {
throw new Error('GBA failed to load', { cause: res })
} else {
gbaEmulatorBootupSequence()
}
})
.catch(() => {
Notifications.error(
'Failed to load the GBA Emulator app. Did you add it to the app/static/external-apps directory?',
{ duration: 10000 }
)
})
})
</script> </script>
<AppContainer useContainer={false} class="h-screen w-full"> <AppContainer useContainer={false} class="h-screen w-full">
@ -21,6 +28,5 @@
src="/static/external-apps/gba-emulator/index.html" src="/static/external-apps/gba-emulator/index.html"
class="w-full h-screen rounded-xl" class="w-full h-screen rounded-xl"
frameborder="0" frameborder="0"
on:error={handleError}
/> />
</AppContainer> </AppContainer>

View file

@ -1,18 +1,25 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte"; import { onMount } from 'svelte'
import AppContainer from "../AppContainer.svelte"; import AppContainer from '../AppContainer.svelte'
import { doomBootupSequence } from "../../Sequences/sequences"; import { doomBootupSequence } from '../../Sequences/sequences'
import { Notifications } from "../../Notifications/notifications"; import { Notifications } from '../../Notifications/notifications'
onMount(() => { onMount(() => {
doomBootupSequence(); fetch('/static/external-apps/jsdoom/index.html')
}); .then((res: Response) => {
if (!res.ok) {
const handleError = () => { throw new Error('Doom failed to load', { cause: res })
} else {
doomBootupSequence()
}
})
.catch(() => {
Notifications.error( Notifications.error(
"Failed to load the Doom app. Did you add it to the app/static/external-apps directory?" 'Failed to load the Doom app. Did you add it to the app/static/external-apps directory?',
); { duration: 10000 }
}; )
})
})
</script> </script>
<AppContainer> <AppContainer>
@ -21,6 +28,5 @@
src="/static/external-apps/jsdoom/index.html" src="/static/external-apps/jsdoom/index.html"
class="w-full h-screen rounded-xl" class="w-full h-screen rounded-xl"
frameborder="0" frameborder="0"
on:error={handleError}
/> />
</AppContainer> </AppContainer>