[Launcher] Refactored launcher.
This commit is contained in:
parent
1dea7dfff9
commit
c73fed905a
|
@ -140,8 +140,7 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent)
|
|||
DirectMpvPlayerBackend::~DirectMpvPlayerBackend()
|
||||
{
|
||||
printf("Shutting down...\n");
|
||||
|
||||
exit(0);
|
||||
qApp->quit();
|
||||
printf("MPV terminated.\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -563,17 +565,17 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
}
|
||||
|
||||
case MPV_EVENT_LOG_MESSAGE: {
|
||||
if (m_logging) {
|
||||
struct mpv_event_log_message* msg =
|
||||
(struct mpv_event_log_message*)event->data;
|
||||
QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text);
|
||||
QString msgLevel = QString(msg->level);
|
||||
if (msgLevel.startsWith("d")) {
|
||||
mpvLogger->debug("{}", logMsg.toUtf8().constData());
|
||||
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
|
||||
mpvLogger->info("{}", logMsg.toUtf8().constData());
|
||||
}
|
||||
if (m_logging) {
|
||||
struct mpv_event_log_message* msg =
|
||||
(struct mpv_event_log_message*)event->data;
|
||||
QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text);
|
||||
QString msgLevel = QString(msg->level);
|
||||
if (msgLevel.startsWith("d")) {
|
||||
mpvLogger->debug("{}", logMsg.toUtf8().constData());
|
||||
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
|
||||
mpvLogger->info("{}", logMsg.toUtf8().constData());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
80
src/main.cpp
80
src/main.cpp
|
@ -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,46 +107,43 @@ 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
|
||||
}
|
||||
backendString = backendSetting;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!qstrcmp(argv[i], "--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->warn("direct-mpv: Old deprecated opengl-cb API for "
|
||||
"backwards compatibility.");
|
||||
launcherLogger->warn(QString("The default is: " + defaultBackend)
|
||||
.toUtf8()
|
||||
.constData());
|
||||
exit(0);
|
||||
}
|
||||
} else if (arguments[0] == "no-update-check") {
|
||||
checkForUpdates = false;
|
||||
} else if (arguments[0] == "update") {
|
||||
Utils::updateAppImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launcherLogger->info("Using backend={}", backendString.toUtf8().constData());
|
||||
|
||||
Utils::SetDPMS(false);
|
||||
|
||||
QString newpath =
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue