Code Refactoring and Error Handling
This commit is contained in:
9
hg.css
9
hg.css
@@ -326,3 +326,12 @@ canvas {
|
||||
right: 0;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.ERRORS {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
color: #ffff;
|
||||
left: 0;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
</div>
|
||||
<div id="codef-canvas"></div>
|
||||
<div class="OVR hidden"></div>
|
||||
<div class="ERRORS hidden"></div>
|
||||
<input id="file-upload" type="file" accept="application/json" />
|
||||
<!-- <script src="libs/codef_core.js"></script>
|
||||
<script src="libs/codef_starfield.js"></script>
|
||||
|
||||
42
player.js
42
player.js
@@ -9,6 +9,7 @@
|
||||
let refreshBtn = document.querySelector(".refresh");
|
||||
let ovr = document.querySelector(".OVR");
|
||||
let fullScreenBtn = document.querySelector(".fullscreen");
|
||||
let errorEl = document.querySelector(".ERRORS");
|
||||
const modalEl = document.getElementById("intro-modal");
|
||||
// const uploadInfoEl = document.getElementById("upload-info");
|
||||
const fileUploadEl = document.getElementById("file-upload");
|
||||
@@ -19,7 +20,6 @@
|
||||
const synthwaveColor = 0xff2975;
|
||||
|
||||
openDialog();
|
||||
getMusic();
|
||||
listenUploadFileChange();
|
||||
|
||||
function initDynamicTooltips() {
|
||||
@@ -96,10 +96,12 @@
|
||||
};
|
||||
}
|
||||
|
||||
document.getElementById("initButton")?.addEventListener("click", () => {
|
||||
document.getElementById("initButton")?.addEventListener("click", async () => {
|
||||
var hydra = new Hydra({ detectAudio: false });
|
||||
modalEl.classList.remove("open");
|
||||
getMusic().then(() => {
|
||||
playMusic();
|
||||
});
|
||||
initHydra();
|
||||
initControls();
|
||||
});
|
||||
@@ -133,7 +135,7 @@
|
||||
case "h":
|
||||
toggleControls();
|
||||
break;
|
||||
case 'x':
|
||||
case "x":
|
||||
toggleEverything();
|
||||
}
|
||||
});
|
||||
@@ -177,6 +179,7 @@
|
||||
}
|
||||
|
||||
async function getMusic() {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://retrowave.ru/api/v1/tracks?limit=10&cursor=${cursor}`
|
||||
).then((res) => res.json());
|
||||
@@ -185,6 +188,13 @@
|
||||
} = res;
|
||||
cursor = currentCursor;
|
||||
currentTracks = tracks;
|
||||
} catch (error) {
|
||||
console.error("Error fetching music:", error);
|
||||
showErrors(
|
||||
"Failed to fetch music. Please check your internet connection or try again later."
|
||||
);
|
||||
throw error; // rethrow the error to be caught in the catch block below
|
||||
}
|
||||
}
|
||||
|
||||
function initPlayer() {}
|
||||
@@ -242,7 +252,7 @@
|
||||
titleEl.innerText = trackDetails.title;
|
||||
document.title = `Now Playing... ${trackDetails.title}`;
|
||||
coverArtEl.style.backgroundImage = `url("${retroWaveRu}${trackDetails.artworkUrl}")`;
|
||||
ovr.innerHTML = `${trackDetails.title}`
|
||||
ovr.innerHTML = `${trackDetails.title}`;
|
||||
}
|
||||
|
||||
function getHistory() {
|
||||
@@ -310,9 +320,17 @@ https://retrowave.ru/${musicData.streamUrl}
|
||||
});
|
||||
}
|
||||
|
||||
function toggleFullScreen() {
|
||||
async function toggleFullScreen() {
|
||||
if (!document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen();
|
||||
try {
|
||||
await document.documentElement.requestFullscreen();
|
||||
} catch (error) {
|
||||
console.error("Error attempting to enable full-screen mode:", error);
|
||||
showErrors(
|
||||
"Failed to enter full-screen mode. Please check your browser settings." +
|
||||
error
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
@@ -332,6 +350,15 @@ https://retrowave.ru/${musicData.streamUrl}
|
||||
ovr.classList.toggle("hidden");
|
||||
}
|
||||
|
||||
function showErrors(error) {
|
||||
errorEl.classList.remove("hidden");
|
||||
errorEl.innerText = error;
|
||||
setTimeout(() => {
|
||||
errorEl.innerText = "";
|
||||
errorEl.classList.add("hidden");
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
// function initCodef() {
|
||||
// const width = window.innerWidth;
|
||||
// const height = window.innerHeight;
|
||||
@@ -371,6 +398,9 @@ https://retrowave.ru/${musicData.streamUrl}
|
||||
.out();
|
||||
} catch (error) {
|
||||
console.error("Hydra initialization failed:", error);
|
||||
showErrors(
|
||||
"Hydra initialization failed. Please check your browser compatibility or try again later."
|
||||
);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user