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">
import AppContainer from "../AppContainer.svelte";
import { Notifications } from "../../Notifications/notifications";
import { onMount } from "svelte";
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?"
);
};
import AppContainer from '../AppContainer.svelte'
import { Notifications } from '../../Notifications/notifications'
import { onMount } from 'svelte'
import { gbaEmulatorBootupSequence } from '../../Sequences/sequences'
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>
<AppContainer useContainer={false} class="h-screen w-full">
@ -21,6 +28,5 @@
src="/static/external-apps/gba-emulator/index.html"
class="w-full h-screen rounded-xl"
frameborder="0"
on:error={handleError}
/>
</AppContainer>

View file

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