Refactored FetchMedia()

This commit is contained in:
nutty
2026-07-01 03:36:27 +10:00
parent 75fee5ed01
commit 3fe4ee5051
+90 -71
View File
@@ -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,23 +159,7 @@ 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
const newPopup = showPopup( ShowWaitingForSMTCBridgePopup();
'/.common/resources/smtc-bridge-icon.png',
'Waiting for SMTC Bridge',
'Please launch SMTC Bridge',
'', // Attribute text
'linear-gradient(0deg, #111111 0%, #11001f 100%)',
{
text: 'Download',
action: () => {
window.open(SMTC_BRIDGE_DOWNLOAD_URL, "_blank");
}
}
);
if (newPopup) {
smtcBridgePopup = newPopup;
}
} }
} }
@@ -192,6 +173,91 @@ window.addEventListener('DOMContentLoaded', () => {
////////////
// POPUPS //
////////////
function ShowWaitingForSMTCBridgePopup() {
const newPopup = showPopup(
'/.common/resources/smtc-bridge-icon.png',
'Waiting for SMTC Bridge',
'Please launch SMTC Bridge',
'', // Attribute text
'linear-gradient(0deg, #111111 0%, #11001f 100%)',
{
text: 'Download',
action: () => {
window.open(SMTC_BRIDGE_DOWNLOAD_URL, "_blank");
}
}
);
if (newPopup) {
smtcBridgePopup = newPopup;
}
}
function ShowSMTCBridgeUpdateRequiredPopup(installedVersion) {
const newPopup = showPopup(
'/.common/resources/smtc-bridge-icon.png',
'Update Required',
'Your version of SMTC Bridge is out of date.',
`<b>Installed Version: ${installedVersion}</b><br><b>New Version: ${REQUIRED_VERSION}</b>`,
'linear-gradient(0deg, #1b0005 0%, #4f000d 100%)',
{
text: 'Download',
action: () => {
window.open(SMTC_BRIDGE_DOWNLOAD_URL, "_blank");
}
}
);
if (newPopup) {
versionCheckPopup = newPopup;
}
}
function ShowSMTCBridgeUpdateAvailablePopup(installedVersion) {
const newPopup = showPopup(
'/.common/resources/smtc-bridge-icon.png',
'Update Available',
'A new version of SMTC Bridge is available.',
`<b>Installed Version: ${installedVersion}</b><br><b>New Version: ${REQUIRED_VERSION}</b>`,
'linear-gradient(0deg, #2a004f 0%, #4f2675 100%)',
{
text: 'Download',
action: () => {
window.open(SMTC_BRIDGE_DOWNLOAD_URL, "_blank");
}
}
);
if (newPopup) {
versionCheckPopup = newPopup;
}
setTimeout(() => {
CloseVersionCheckPopup();
}, 10000);
}
function CloseSMTCBridgePopup()
{
if (smtcBridgePopup) {
smtcBridgePopup.close();
smtcBridgePopup = null;
}
}
function CloseVersionCheckPopup()
{
if (versionCheckPopup) {
versionCheckPopup.close();
versionCheckPopup = null;
}
}
////////////////////// //////////////////////
// HELPER FUNCTIONS // // HELPER FUNCTIONS //
////////////////////// //////////////////////
@@ -207,62 +273,15 @@ function CheckSMTCBridgeVersion(installedVersion) {
switch (versionStatus) switch (versionStatus)
{ {
case 'incompatible': case 'incompatible':
{ ShowSMTCBridgeUpdateRequiredPopup(installedVersion);
const newPopup = showPopup(
'/.common/resources/smtc-bridge-icon.png',
'Update Required',
'Your version of SMTC Bridge is out of date.',
`<b>Installed Version: ${installedVersion}</b><br><b>New Version: ${REQUIRED_VERSION}</b>`,
'linear-gradient(0deg, #1b0005 0%, #4f000d 100%)',
{
text: 'Download',
action: () => {
window.open(SMTC_BRIDGE_DOWNLOAD_URL, "_blank");
}
}
);
if (newPopup) {
versionCheckPopup = newPopup;
}
}
skipVersionCheck = false; skipVersionCheck = false;
break; break;
case 'soft-warning': case 'soft-warning':
{ ShowSMTCBridgeUpdateAvailablePopup(installedVersion);
const newPopup = showPopup(
'/.common/resources/smtc-bridge-icon.png',
'Update Available',
'A new version of SMTC Bridge is available.',
`<b>Installed Version: ${installedVersion}</b><br><b>New Version: ${REQUIRED_VERSION}</b>`,
'linear-gradient(0deg, #2a004f 0%, #4f2675 100%)',
{
text: 'Download',
action: () => {
window.open(SMTC_BRIDGE_DOWNLOAD_URL, "_blank");
}
}
);
if (newPopup) {
versionCheckPopup = newPopup;
}
setTimeout(() => {
if (versionCheckPopup) {
versionCheckPopup.close();
versionCheckPopup = null;
}
}, 10000);
}
skipVersionCheck = true; skipVersionCheck = true;
break; break;
default: default:
if (versionCheckPopup) { CloseVersionCheckPopup();
versionCheckPopup.close();
versionCheckPopup = null;
}
break; break;
} }
} }