1
0
Fork 0

[Launcher] Refactored launcher.

This commit is contained in:
NamedKitten 2018-12-18 16:22:17 +00:00
parent 1dea7dfff9
commit c73fed905a
5 changed files with 71 additions and 55 deletions

View file

@ -140,8 +140,7 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent)
DirectMpvPlayerBackend::~DirectMpvPlayerBackend()
{
printf("Shutting down...\n");
exit(0);
qApp->quit();
printf("MPV terminated.\n");
}

View file

@ -129,7 +129,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
, mpv{ mpv_create() }
, mpv_gl(nullptr)
{
mpvLogger->set_pattern("%^[%d-%m-%Y %T.%e][%l][%n]%v%$");
mpvLogger->set_pattern("[%n]%v%$");
if (!mpv)
throw std::runtime_error("could not create mpv context");
@ -398,7 +398,9 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
case Enums::Commands::ForcePause: {
command(QVariantList() << "set" << "pause" << "yes");
command(QVariantList() << "set"
<< "pause"
<< "yes");
break;
}

View file

@ -47,12 +47,14 @@ enum class Commands : int
ForcePause = 23,
};
Q_ENUM_NS(Commands)
enum class Backends : int
{
MpvBackend = 0,
DirectMpvBackend = 1
};
Q_ENUM_NS(Backends)
}
#endif

View file

@ -1,8 +1,8 @@
#include "logger.h"
#include <QObject>
#include <QString>
#include <QSettings>
#include <QString>
#include <iostream>
std::shared_ptr<spdlog::logger>
@ -10,7 +10,8 @@ initLogger(std::string name)
{
QSettings settings("KittehPlayer", "KittehPlayer");
QString logFile = settings.value("Logging/logFile", "/tmp/KittehPlayer.log").toString();
QString logFile =
settings.value("Logging/logFile", "/tmp/KittehPlayer.log").toString();
std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
@ -18,9 +19,7 @@ initLogger(std::string name)
logFile.toUtf8().constData()));
auto console =
std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks));
console->set_pattern("%^[%d-%m-%Y %T.%e][%l][%n] %v%$");
console->error(logFile.toUtf8().constData());
console->set_pattern("[%l][%n] %v%$");
spdlog::register_logger(console);
return spdlog::get(name);

View file

@ -89,11 +89,12 @@ main(int argc, char* argv[])
auto launcherLogger = initLogger("launcher");
launcherLogger->info("Starting up!");
QString backendString;
Enums::Backends backend;
QString defaultBackend;
#ifdef DISABLE_MpvPlayerBackend
Enums::Backends backend = Enums::Backends::DirectMpvBackend;
defaultBackend = "direct-mpv";
#else
Enums::Backends backend = Enums::Backends::MpvBackend;
defaultBackend = "mpv";
#endif
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
QApplication app(argc, argv);
@ -106,45 +107,42 @@ main(int argc, char* argv[])
catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP });
#endif
QSettings settings;
QString backendString =
settings.value("Backend/backend", defaultBackend).toString();
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) {
QtConcurrent::run(Utils::checkForUpdates);
}
QString backendSetting = settings.value("Backend/backend", "").toString();
if (backendSetting.length() == 0) {
QString arg = QString(argv[i]);
if (arg.startsWith("--")) {
QStringList arguments =
arg.right(arg.length() - QString("--").length()).split(QRegExp("="));
if (arguments.length() > 0) {
if (arguments[0] == "backend") {
if (arguments.length() > 1 && arguments[1].length() > 0) {
backendString = arguments[1];
} else {
launcherLogger->warn("Available Backends:");
#ifndef DISABLE_MpvPlayerBackend
settings.setValue("Backend/backend", "mpv");
#else
settings.setValue("Backend/backend", "direct-mpv");
launcherLogger->warn("mpv: MPV new Render API backend.");
#endif
launcherLogger->warn("direct-mpv: Old deprecated opengl-cb API for "
"backwards compatibility.");
launcherLogger->warn(QString("The default is: " + defaultBackend)
.toUtf8()
.constData());
exit(0);
}
backendString = backendSetting;
for (int i = 1; i < argc; ++i) {
if (!qstrcmp(argv[i], "--update")) {
} else if (arguments[0] == "no-update-check") {
checkForUpdates = false;
} else if (arguments[0] == "update") {
Utils::updateAppImage();
} else if (!qstrcmp(argv[i], "--backend=mpv") || backendSetting == "mpv") {
backend = Enums::Backends::MpvBackend;
backendString = QString("mpv");
} else if (!qstrcmp(argv[i], "--backend=direct-mpv") ||
backendSetting == "direct-mpv") {
backendString = QString("direct-mpv");
backend = Enums::Backends::DirectMpvBackend;
}
}
launcherLogger->info("Using backend={}", backendString.toUtf8().constData());
}
}
Utils::SetDPMS(false);
@ -165,6 +163,18 @@ main(int argc, char* argv[])
qmlRegisterType<UtilsClass>("player", 1, 0, "Utils");
if (backendString == "mpv") {
backend = Enums::Backends::MpvBackend;
} else if (backendString == "direct-mpv") {
backend = Enums::Backends::DirectMpvBackend;
} else {
launcherLogger->error("Invalid backend {}.",
backendString.toUtf8().constData());
exit(0);
}
launcherLogger->info("Using backend={}", backendString.toUtf8().constData());
switch (backend) {
case Enums::Backends::MpvBackend: {
#ifndef DISABLE_MpvPlayerBackend
@ -189,5 +199,9 @@ main(int argc, char* argv[])
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
if (checkForUpdates) {
QtConcurrent::run(Utils::checkForUpdates);
}
return app.exec();
}