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() DirectMpvPlayerBackend::~DirectMpvPlayerBackend()
{ {
printf("Shutting down...\n"); printf("Shutting down...\n");
qApp->quit();
exit(0);
printf("MPV terminated.\n"); printf("MPV terminated.\n");
} }

View file

@ -129,7 +129,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
, mpv{ mpv_create() } , mpv{ mpv_create() }
, mpv_gl(nullptr) , mpv_gl(nullptr)
{ {
mpvLogger->set_pattern("%^[%d-%m-%Y %T.%e][%l][%n]%v%$"); mpvLogger->set_pattern("[%n]%v%$");
if (!mpv) if (!mpv)
throw std::runtime_error("could not create mpv context"); throw std::runtime_error("could not create mpv context");
@ -395,10 +395,12 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
break; break;
} }
case Enums::Commands::ForcePause: { case Enums::Commands::ForcePause: {
command(QVariantList() << "set" << "pause" << "yes"); command(QVariantList() << "set"
<< "pause"
<< "yes");
break; break;
} }
@ -563,17 +565,17 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
} }
case MPV_EVENT_LOG_MESSAGE: { case MPV_EVENT_LOG_MESSAGE: {
if (m_logging) { if (m_logging) {
struct mpv_event_log_message* msg = struct mpv_event_log_message* msg =
(struct mpv_event_log_message*)event->data; (struct mpv_event_log_message*)event->data;
QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text); QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text);
QString msgLevel = QString(msg->level); QString msgLevel = QString(msg->level);
if (msgLevel.startsWith("d")) { if (msgLevel.startsWith("d")) {
mpvLogger->debug("{}", logMsg.toUtf8().constData()); mpvLogger->debug("{}", logMsg.toUtf8().constData());
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) { } else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
mpvLogger->info("{}", logMsg.toUtf8().constData()); mpvLogger->info("{}", logMsg.toUtf8().constData());
}
} }
}
break; break;
} }

View file

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

View file

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

View file

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