mirror of
https://github.com/nuttylmao/nutty.gg.git
synced 2026-09-19 04:00:59 -04:00
Refactored FetchMedia()
This commit is contained in:
+58
-39
@@ -147,10 +147,7 @@ async function FetchMedia() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
// Remove the SMTC Bridge popup if it's on screen
|
// Remove the SMTC Bridge popup if it's on screen
|
||||||
if (smtcBridgePopup) {
|
CloseSMTCBridgePopup();
|
||||||
smtcBridgePopup.close();
|
|
||||||
smtcBridgePopup = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the SMTC Bridge version
|
// Check the SMTC Bridge version
|
||||||
CheckSMTCBridgeVersion(data.app_version);
|
CheckSMTCBridgeVersion(data.app_version);
|
||||||
@@ -162,6 +159,25 @@ async function FetchMedia() {
|
|||||||
console.error("Failed to connect to Flask media server:", error);
|
console.error("Failed to connect to Flask media server:", error);
|
||||||
|
|
||||||
// Show a popup to instruct the user to install SMTC Bridge
|
// Show a popup to instruct the user to install SMTC Bridge
|
||||||
|
ShowWaitingForSMTCBridgePopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
// Start polling every 1000 milliseconds
|
||||||
|
setInterval(FetchMedia, 1000);
|
||||||
|
|
||||||
|
// Run once immediately on script load
|
||||||
|
FetchMedia();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// POPUPS //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
function ShowWaitingForSMTCBridgePopup() {
|
||||||
const newPopup = showPopup(
|
const newPopup = showPopup(
|
||||||
'/.common/resources/smtc-bridge-icon.png',
|
'/.common/resources/smtc-bridge-icon.png',
|
||||||
'Waiting for SMTC Bridge',
|
'Waiting for SMTC Bridge',
|
||||||
@@ -180,34 +196,9 @@ async function FetchMedia() {
|
|||||||
smtcBridgePopup = newPopup;
|
smtcBridgePopup = newPopup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
|
||||||
// Start polling every 1000 milliseconds
|
|
||||||
setInterval(FetchMedia, 1000);
|
|
||||||
|
|
||||||
// Run once immediately on script load
|
|
||||||
FetchMedia();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
function ShowSMTCBridgeUpdateRequiredPopup(installedVersion) {
|
||||||
//////////////////////
|
|
||||||
// HELPER FUNCTIONS //
|
|
||||||
//////////////////////
|
|
||||||
|
|
||||||
function CheckSMTCBridgeVersion(installedVersion) {
|
|
||||||
// Check that the server/client are on the same SMTC Bridge version
|
|
||||||
// const VersionStatus = VersionCheck(REQUIRED_VERSION, installedVersion);
|
|
||||||
const versionStatus = VersionCheck(REQUIRED_VERSION, installedVersion);
|
|
||||||
|
|
||||||
if (skipVersionCheck)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (versionStatus)
|
|
||||||
{
|
|
||||||
case 'incompatible':
|
|
||||||
{
|
|
||||||
const newPopup = showPopup(
|
const newPopup = showPopup(
|
||||||
'/.common/resources/smtc-bridge-icon.png',
|
'/.common/resources/smtc-bridge-icon.png',
|
||||||
'Update Required',
|
'Update Required',
|
||||||
@@ -227,10 +218,7 @@ function CheckSMTCBridgeVersion(installedVersion) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skipVersionCheck = false;
|
function ShowSMTCBridgeUpdateAvailablePopup(installedVersion) {
|
||||||
break;
|
|
||||||
case 'soft-warning':
|
|
||||||
{
|
|
||||||
const newPopup = showPopup(
|
const newPopup = showPopup(
|
||||||
'/.common/resources/smtc-bridge-icon.png',
|
'/.common/resources/smtc-bridge-icon.png',
|
||||||
'Update Available',
|
'Update Available',
|
||||||
@@ -250,19 +238,50 @@ function CheckSMTCBridgeVersion(installedVersion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
CloseVersionCheckPopup();
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CloseSMTCBridgePopup()
|
||||||
|
{
|
||||||
|
if (smtcBridgePopup) {
|
||||||
|
smtcBridgePopup.close();
|
||||||
|
smtcBridgePopup = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function CloseVersionCheckPopup()
|
||||||
|
{
|
||||||
if (versionCheckPopup) {
|
if (versionCheckPopup) {
|
||||||
versionCheckPopup.close();
|
versionCheckPopup.close();
|
||||||
versionCheckPopup = null;
|
versionCheckPopup = null;
|
||||||
}
|
}
|
||||||
}, 10000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
|
// HELPER FUNCTIONS //
|
||||||
|
//////////////////////
|
||||||
|
|
||||||
|
function CheckSMTCBridgeVersion(installedVersion) {
|
||||||
|
// Check that the server/client are on the same SMTC Bridge version
|
||||||
|
// const VersionStatus = VersionCheck(REQUIRED_VERSION, installedVersion);
|
||||||
|
const versionStatus = VersionCheck(REQUIRED_VERSION, installedVersion);
|
||||||
|
|
||||||
|
if (skipVersionCheck)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (versionStatus)
|
||||||
|
{
|
||||||
|
case 'incompatible':
|
||||||
|
ShowSMTCBridgeUpdateRequiredPopup(installedVersion);
|
||||||
|
skipVersionCheck = false;
|
||||||
|
break;
|
||||||
|
case 'soft-warning':
|
||||||
|
ShowSMTCBridgeUpdateAvailablePopup(installedVersion);
|
||||||
skipVersionCheck = true;
|
skipVersionCheck = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (versionCheckPopup) {
|
CloseVersionCheckPopup();
|
||||||
versionCheckPopup.close();
|
|
||||||
versionCheckPopup = null;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user