Browse Source

Just do it all in JS.

Ian Walton 3 years ago
parent
commit
ddccc58bb6
3 changed files with 27 additions and 71 deletions
  1. 27 30
      native/jmpUpdatePlugin.js
  2. 0 34
      src/system/SystemComponent.cpp
  3. 0 7
      src/system/SystemComponent.h

+ 27 - 30
native/jmpUpdatePlugin.js

@@ -7,37 +7,34 @@ class jmpUpdatePlugin {
         (async () => {
             const api = await window.apiPromise;
 
-            const onUpdateNotify = async (url) => {
-                if (url == "SSL_UNAVAILABLE") {
-                    // Windows (and possibly macOS) don't ship with SSL in QT......
-                    // So we get to do a full request to GitHub here :(
-                    const checkUrl = "https://github.com/jellyfin/jellyfin-media-player/releases/latest";
-                    url = (await fetch(checkUrl)).url;
-                }
-
-                const urlSegments = url.split("/");
-                const version = urlSegments[urlSegments.length - 1].substring(1);
-                const currentVersion = navigator.userAgent.split(" ")[1];
-
-                if (version == currentVersion) return;
-                if (!/^[0-9.-]+$/.test(version)) return;
-
-                try {
-                    await confirm({
-                        title: "Update Available",
-                        text: `Jellyfin Media Player version ${version} is available.`,
-                        cancelText: "Ignore",
-                        confirmText: "Download"
-                    });
-
-                    api.system.openExternalUrl(url);
-                } catch (e) {
-                    // User cancelled update
-                }
-            }
+            const checkForUpdates = await new Promise(resolve => {
+                api.settings.value("main", "checkForUpdates", resolve);
+            });
+
+            if (!checkForUpdates) return;
+
+            const checkUrl = "https://github.com/jellyfin/jellyfin-media-player/releases/latest";
+            const url = (await fetch(checkUrl)).url;
+
+            const urlSegments = url.split("/");
+            const version = urlSegments[urlSegments.length - 1].substring(1);
+            const currentVersion = navigator.userAgent.split(" ")[1];
 
-            api.system.updateInfoEmitted.connect(onUpdateNotify);
-            api.system.checkForUpdates();
+            if (version == currentVersion) return;
+            if (!/^[0-9.-]+$/.test(version)) return;
+
+            try {
+                await confirm({
+                    title: "Update Available",
+                    text: `Jellyfin Media Player version ${version} is available.`,
+                    cancelText: "Ignore",
+                    confirmText: "Download"
+                });
+
+                api.system.openExternalUrl(url);
+            } catch (e) {
+                // User cancelled update
+            }
         })();
     }
 }

+ 0 - 34
src/system/SystemComponent.cpp

@@ -6,9 +6,6 @@
 #include <QDesktopServices>
 #include <QDir>
 #include <QJsonObject>
-#include <QNetworkRequest>
-#include <QNetworkAccessManager>
-#include <QNetworkReply>
 
 #include "input/InputComponent.h"
 #include "SystemComponent.h"
@@ -334,37 +331,6 @@ QString SystemComponent::getNativeShellScript()
   return nativeshellString;
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
-void SystemComponent::checkForUpdates()
-{
-  if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "checkForUpdates").toBool()) {
-#if !defined(Q_OS_WIN) && !defined(Q_OS_MAC)
-    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
-    QString checkUrl = "https://github.com/jellyfin/jellyfin-media-player/releases/latest";
-    QUrl qCheckUrl = QUrl(checkUrl);
-    QLOG_DEBUG() << QString("Checking URL for updates: %1").arg(checkUrl);
-    QNetworkRequest req(qCheckUrl);
-
-    connect(manager, &QNetworkAccessManager::finished, this, &SystemComponent::updateInfoHandler);
-    manager->get(req);
-#else
-    emit updateInfoEmitted("SSL_UNAVAILABLE");
-#endif
-  }
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-void SystemComponent::updateInfoHandler(QNetworkReply* reply)
-{
-  if (reply->error() == QNetworkReply::NoError) {
-    int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
-    if(statusCode == 302) {
-      QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
-      emit updateInfoEmitted(redirectUrl.toString());
-    }
-  }
-}
-
 /////////////////////////////////////////////////////////////////////////////////////////
 #define BASESTR "protocols=shoutcast,http-video;videoDecoders=h264{profile:high&resolution:2160&level:52};audioDecoders=mp3,aac,dts{bitrate:800000&channels:%1},ac3{bitrate:800000&channels:%2}"
 

+ 0 - 7
src/system/SystemComponent.h

@@ -47,8 +47,6 @@ public:
 
   Q_INVOKABLE QString getNativeShellScript();
 
-  Q_INVOKABLE void checkForUpdates();
-
   // called by the web-client when everything is properly inited
   Q_INVOKABLE void hello(const QString& version);
 
@@ -56,8 +54,6 @@ public:
   Q_SIGNAL void capabilitiesChanged(const QString& capabilities);
   Q_SIGNAL void userInfoChanged();
 
-  Q_SIGNAL void updateInfoEmitted(QString url);
-
   // possible os types type enum
   enum PlatformType
   {
@@ -93,9 +89,6 @@ public:
 
   void updateScale(qreal scale);
 
-private Q_SLOTS:
-  void updateInfoHandler(QNetworkReply* reply);
-
 signals:
   void hostMessage(const QString& message);
   void settingsMessage(const QString& setting, const QString& value);