Everything must be async

I feel it's not proper to keep the promises `dismissWarning()` returns unhandled, even if they're infallible, but Hazel and Julia have forced my hand
This commit is contained in:
CenTdemeern1 2024-11-09 02:33:23 +01:00
parent 2305eb9e97
commit 953d7ee254

View file

@ -82,16 +82,16 @@ let loadingStatus = ref<string | undefined>(undefined);
let player = ref<PlayerElement | undefined>(undefined); let player = ref<PlayerElement | undefined>(undefined);
let ruffleError = ref<string | undefined>(undefined); let ruffleError = ref<string | undefined>(undefined);
function dismissWarning() { async function dismissWarning() {
playerHide.value = false; playerHide.value = false;
loadRuffle().then(() => { try {
try { await loadRuffle();
createPlayer(); // NOTE: I don't like this because this handles a success implicitly but Hazel and Julia have forced my hand
loadContent(); createPlayer();
} catch (error) { await loadContent();
handleError(error); } catch (error) {
} handleError(error);
}).catch(handleError); }
} }
function handleError(error: unknown) { function handleError(error: unknown) {
@ -170,22 +170,25 @@ function createPlayer() {
/** /**
* @throws If `player.value` is uninitialized. * @throws If `player.value` is uninitialized.
*/ */
function loadContent() { async function loadContent() {
if (player.value === undefined) throw Error('Player is uninitialized.'); if (player.value === undefined) throw Error('Player is uninitialized.');
ruffleContainer.value?.appendChild(player.value); ruffleContainer.value?.appendChild(player.value);
loadingStatus.value = i18n.ts._flash.loadingFlashFile; loadingStatus.value = i18n.ts._flash.loadingFlashFile;
player.value.load(url.value).then(() => { try {
await player.value.load(url.value);
loadingStatus.value = undefined; loadingStatus.value = undefined;
}).catch(error => { } catch (error) {
fetch('https://raw.esm.sh/', { try {
mode: 'cors', await fetch('https://raw.esm.sh/', {
}).then(() => { mode: 'cors',
});
// NOTE: I don't like this because this handles a success implicitly but Hazel and Julia have forced my hand
handleError(error); // Unexpected error handleError(error); // Unexpected error
}).catch(() => { } catch (_) {
// Must be CSP because esm.sh should be online if `loadRuffle()` didn't fail // Must be CSP because esm.sh should be online if `loadRuffle()` didn't fail
handleError(i18n.ts._flash.cspError); handleError(i18n.ts._flash.cspError);
}); }
}); }
} }
function playPause() { function playPause() {