From 7b8beeb57b6497194c3a8f5fd134381f93abb22c Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Thu, 6 Dec 2018 10:36:13 +0000 Subject: [PATCH] [Launcher] Added arg/setting to disable update check. --- src/main.cpp | 77 ++++++++++++++++++++++++++++-------------------- src/qml/main.qml | 1 + 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ac72d77..ead2582 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,6 +52,7 @@ catchUnixSignals(std::initializer_list quitSignals) int main(int argc, char* argv[]) { + #ifdef DISABLE_MpvPlayerBackend Enums::Backends backend = Enums::Backends::DirectMpvBackend; #else @@ -63,43 +64,55 @@ main(int argc, char* argv[]) catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP }); #endif -#ifdef GIT_COMMIT_HASH - QString current_version = QString(GIT_COMMIT_HASH); - qDebug() << "Current Version: " << current_version; - - QNetworkRequest request(QUrl("https://api.github.com/repos/NamedKitten/" - "KittehPlayer/releases/tags/continuous")); - QNetworkAccessManager nam; - QNetworkReply* reply = nam.get(request); - - while (!reply->isFinished()) { - qApp->processEvents(); - } - QByteArray response_data = reply->readAll(); - QJsonDocument json = QJsonDocument::fromJson(response_data); - - if (json["target_commitish"].toString().length() != 0) { - if (json["target_commitish"].toString().endsWith(current_version) == 0) { - qDebug() << "Latest Version: " << json["target_commitish"].toString(); - qDebug() << "Update Available. Please update ASAP."; - QProcess notifier; - notifier.setProcessChannelMode(QProcess::ForwardedChannels); - notifier.start("notify-send", - QStringList() << "KittehPlayer" - << "New update avalable!" - << "--icon=KittehPlayer"); - notifier.waitForFinished(); - } - } else { - qDebug() << "Couldn't check for new version."; - } -#endif - app.setOrganizationName("KittehPlayer"); app.setOrganizationDomain("namedkitten.pw"); app.setApplicationName("KittehPlayer"); QSettings settings; + +#ifdef GIT_COMMIT_HASH + bool checkForUpdates = + settings.value("Backend/checkForUpdatesOnLaunch", false).toBool(); + for (int i = 1; i < argc; ++i) { + if (!qstrcmp(argv[i], "--no-update-check")) { + checkForUpdates = false; + } + } + + if (checkForUpdates) { + QString current_version = QString(GIT_COMMIT_HASH); + qDebug() << "Current Version: " << current_version; + + QNetworkRequest request(QUrl("https://api.github.com/repos/NamedKitten/" + "KittehPlayer/releases/tags/continuous")); + + QNetworkAccessManager nam; + QNetworkReply* reply = nam.get(request); + + while (!reply->isFinished()) { + qApp->processEvents(); + } + QByteArray response_data = reply->readAll(); + QJsonDocument json = QJsonDocument::fromJson(response_data); + + if (json["target_commitish"].toString().length() != 0) { + if (json["target_commitish"].toString().endsWith(current_version) == 0) { + qDebug() << "Latest Version: " << json["target_commitish"].toString(); + qDebug() << "Update Available. Please update ASAP."; + QProcess notifier; + notifier.setProcessChannelMode(QProcess::ForwardedChannels); + notifier.start("notify-send", + QStringList() << "KittehPlayer" + << "New update avalable!" + << "--icon=KittehPlayer"); + notifier.waitForFinished(); + } + } else { + qDebug() << "Couldn't check for new version."; + } + } +#endif + QString backendSetting = settings.value("Backend/backend", "").toString(); if (backendSetting.length() == 0) { #ifndef DISABLE_MpvPlayerBackend diff --git a/src/qml/main.qml b/src/qml/main.qml index d73a4c9..4e0cd8a 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -38,6 +38,7 @@ Window { id: backendSettings category: "Backend" property string backend: "mpv" + property bool checkForUpdatesOnLaunch: true } Settings {