2018-10-27 16:11:29 +01:00
|
|
|
#ifdef QRC_SOURCE_PATH
|
|
|
|
#include "runtimeqml/runtimeqml.h"
|
|
|
|
#endif
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
#include "MpvPlayerBackend.h"
|
2018-11-07 11:10:38 +00:00
|
|
|
#include "utils.hpp"
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2018-10-13 15:38:31 +01:00
|
|
|
#include <QApplication>
|
2018-10-23 11:37:51 +01:00
|
|
|
#include <QProcessEnvironment>
|
2018-11-06 07:39:42 +00:00
|
|
|
#include <QQmlApplicationEngine>
|
2018-11-07 11:10:38 +00:00
|
|
|
#include <QtCore>
|
2018-11-07 07:42:47 +00:00
|
|
|
#include <stdbool.h>
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-10-31 07:53:38 +00:00
|
|
|
#ifdef WIN32
|
2018-10-30 16:16:53 +00:00
|
|
|
#include "setenv_mingw.hpp"
|
|
|
|
#endif
|
|
|
|
|
2018-11-16 09:10:26 +00:00
|
|
|
#ifdef GIT_COMMIT_HASH
|
|
|
|
#include <QJsonDocument>
|
2018-11-16 09:16:04 +00:00
|
|
|
#include <QSequentialIterable>
|
|
|
|
#include <QtNetwork>
|
2018-11-16 09:10:26 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-11-11 13:43:18 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2018-11-16 09:16:04 +00:00
|
|
|
void
|
|
|
|
catchUnixSignals(std::initializer_list<int> quitSignals)
|
|
|
|
{
|
|
|
|
auto handler = [](int sig) -> void { QCoreApplication::quit(); };
|
|
|
|
|
|
|
|
sigset_t blocking_mask;
|
|
|
|
sigemptyset(&blocking_mask);
|
|
|
|
for (auto sig : quitSignals)
|
|
|
|
sigaddset(&blocking_mask, sig);
|
|
|
|
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler = handler;
|
|
|
|
sa.sa_mask = blocking_mask;
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
|
|
|
for (auto sig : quitSignals)
|
|
|
|
sigaction(sig, &sa, nullptr);
|
2018-11-11 13:43:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-16 09:16:04 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
2018-10-13 15:38:31 +01:00
|
|
|
{
|
2018-11-06 07:39:42 +00:00
|
|
|
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
|
|
|
|
QApplication app(argc, argv);
|
2018-11-11 13:43:18 +00:00
|
|
|
#ifdef __linux__
|
2018-11-16 09:16:04 +00:00
|
|
|
catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP });
|
2018-11-11 13:43:18 +00:00
|
|
|
#endif
|
2018-11-16 09:10:26 +00:00
|
|
|
|
|
|
|
#ifdef GIT_COMMIT_HASH
|
2018-11-16 09:16:04 +00:00
|
|
|
QString current_version = QString(GIT_COMMIT_HASH);
|
|
|
|
qDebug() << "Current Version: " << current_version;
|
2018-11-16 09:10:26 +00:00
|
|
|
|
2018-11-16 09:16:04 +00:00
|
|
|
QNetworkRequest request(QUrl("https://api.github.com/repos/NamedKitten/"
|
|
|
|
"KittehPlayer/releases/tags/continuous"));
|
|
|
|
QNetworkAccessManager nam;
|
|
|
|
QNetworkReply* reply = nam.get(request);
|
2018-11-16 09:10:26 +00:00
|
|
|
|
2018-11-16 09:16:04 +00:00
|
|
|
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.";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qDebug() << "Couldn't check for new version.";
|
|
|
|
}
|
2018-11-16 09:10:26 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
app.setOrganizationName("KittehPlayer");
|
|
|
|
app.setOrganizationDomain("namedkitten.pw");
|
|
|
|
app.setApplicationName("KittehPlayer");
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (!qstrcmp(argv[i], "--update")) {
|
2018-11-16 09:16:04 +00:00
|
|
|
QString program =
|
|
|
|
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
|
|
|
"/usr/bin/appimageupdatetool";
|
2018-11-06 07:39:42 +00:00
|
|
|
QProcess updater;
|
|
|
|
updater.setProcessChannelMode(QProcess::ForwardedChannels);
|
2018-11-16 09:16:04 +00:00
|
|
|
updater.start(program,
|
|
|
|
QStringList()
|
|
|
|
<< QProcessEnvironment::systemEnvironment().value(
|
|
|
|
"APPIMAGE", ""));
|
2018-11-06 07:39:42 +00:00
|
|
|
updater.waitForFinished();
|
|
|
|
exit(0);
|
2018-10-23 11:37:51 +01:00
|
|
|
}
|
2018-11-06 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 11:10:38 +00:00
|
|
|
SetDPMS(false);
|
2018-11-06 07:39:42 +00:00
|
|
|
|
2018-11-16 09:16:04 +00:00
|
|
|
QString newpath =
|
|
|
|
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
|
|
|
"/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
|
2018-11-06 07:39:42 +00:00
|
|
|
setenv("PATH", newpath.toUtf8().constData(), 1);
|
2018-10-23 23:56:24 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2018-11-07 11:10:38 +00:00
|
|
|
QApplication::setAttribute(Qt::AA_NativeWindows);
|
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
qmlRegisterType<MpvPlayerBackend>("player", 1, 0, "PlayerBackend");
|
|
|
|
std::setlocale(LC_NUMERIC, "C");
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
QQmlApplicationEngine engine;
|
2018-10-27 16:11:29 +01:00
|
|
|
#ifdef QRC_SOURCE_PATH
|
2018-11-06 07:39:42 +00:00
|
|
|
RuntimeQML* rt = new RuntimeQML(&engine, QRC_SOURCE_PATH "/qml.qrc");
|
2018-10-27 16:11:29 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
rt->setAutoReload(true);
|
|
|
|
rt->setMainQmlFilename("main.qml");
|
|
|
|
rt->reload();
|
2018-10-27 16:11:29 +01:00
|
|
|
#else
|
2018-11-06 07:39:42 +00:00
|
|
|
engine.load(QUrl(QStringLiteral("qrc:///player/main.qml")));
|
2018-10-27 16:11:29 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
return app.exec();
|
2018-10-13 15:38:31 +01:00
|
|
|
}
|