1
0
Fork 0

[Launcher] Added arg/setting to disable update check.

This commit is contained in:
NamedKitten 2018-12-06 10:36:13 +00:00
parent b6d5547453
commit 7b8beeb57b
2 changed files with 46 additions and 32 deletions

View file

@ -52,6 +52,7 @@ catchUnixSignals(std::initializer_list<int> quitSignals)
int int
main(int argc, char* argv[]) main(int argc, char* argv[])
{ {
#ifdef DISABLE_MpvPlayerBackend #ifdef DISABLE_MpvPlayerBackend
Enums::Backends backend = Enums::Backends::DirectMpvBackend; Enums::Backends backend = Enums::Backends::DirectMpvBackend;
#else #else
@ -63,43 +64,55 @@ main(int argc, char* argv[])
catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP }); catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP });
#endif #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.setOrganizationName("KittehPlayer");
app.setOrganizationDomain("namedkitten.pw"); app.setOrganizationDomain("namedkitten.pw");
app.setApplicationName("KittehPlayer"); app.setApplicationName("KittehPlayer");
QSettings settings; 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(); QString backendSetting = settings.value("Backend/backend", "").toString();
if (backendSetting.length() == 0) { if (backendSetting.length() == 0) {
#ifndef DISABLE_MpvPlayerBackend #ifndef DISABLE_MpvPlayerBackend

View file

@ -38,6 +38,7 @@ Window {
id: backendSettings id: backendSettings
category: "Backend" category: "Backend"
property string backend: "mpv" property string backend: "mpv"
property bool checkForUpdatesOnLaunch: true
} }
Settings { Settings {