From 3fe4ee50518b98a6b2e101f6e0143dc6ba21bdb1 Mon Sep 17 00:00:00 2001 From: nutty Date: Wed, 1 Jul 2026 03:36:27 +1000 Subject: [PATCH] Refactored FetchMedia() --- now-playing/script.js | 161 +++++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 71 deletions(-) diff --git a/now-playing/script.js b/now-playing/script.js index 4c20b44..e45f5b4 100644 --- a/now-playing/script.js +++ b/now-playing/script.js @@ -147,10 +147,7 @@ async function FetchMedia() { const data = await response.json(); // Remove the SMTC Bridge popup if it's on screen - if (smtcBridgePopup) { - smtcBridgePopup.close(); - smtcBridgePopup = null; - } + CloseSMTCBridgePopup(); // Check the SMTC Bridge version CheckSMTCBridgeVersion(data.app_version); @@ -162,23 +159,7 @@ async function FetchMedia() { console.error("Failed to connect to Flask media server:", error); // Show a popup to instruct the user to install SMTC Bridge - 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; - } + ShowWaitingForSMTCBridgePopup(); } } @@ -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.', + `Installed Version: ${installedVersion}
New Version: ${REQUIRED_VERSION}`, + '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.', + `Installed Version: ${installedVersion}
New Version: ${REQUIRED_VERSION}`, + '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 // ////////////////////// @@ -207,62 +273,15 @@ function CheckSMTCBridgeVersion(installedVersion) { switch (versionStatus) { case 'incompatible': - { - const newPopup = showPopup( - '/.common/resources/smtc-bridge-icon.png', - 'Update Required', - 'Your version of SMTC Bridge is out of date.', - `Installed Version: ${installedVersion}
New Version: ${REQUIRED_VERSION}`, - 'linear-gradient(0deg, #1b0005 0%, #4f000d 100%)', - { - text: 'Download', - action: () => { - window.open(SMTC_BRIDGE_DOWNLOAD_URL, "_blank"); - } - } - ); - - if (newPopup) { - versionCheckPopup = newPopup; - } - } - + ShowSMTCBridgeUpdateRequiredPopup(installedVersion); skipVersionCheck = false; break; case 'soft-warning': - { - const newPopup = showPopup( - '/.common/resources/smtc-bridge-icon.png', - 'Update Available', - 'A new version of SMTC Bridge is available.', - `Installed Version: ${installedVersion}
New Version: ${REQUIRED_VERSION}`, - '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); - } + ShowSMTCBridgeUpdateAvailablePopup(installedVersion); skipVersionCheck = true; break; default: - if (versionCheckPopup) { - versionCheckPopup.close(); - versionCheckPopup = null; - } + CloseVersionCheckPopup(); break; } }