Add logging in debug build and force graphics API
This commit is contained in:
3 files changed
+69
-7
No files matched your search
+3
-2
@@ -54,11 +54,12 @@ list(APPEND SOURCES src/asteria.rc)
|
|||||||
qt_add_executable(asteria-qt ${SOURCES})
|
qt_add_executable(asteria-qt ${SOURCES})
|
||||||
|
|
||||||
set_target_properties(asteria-qt PROPERTIES
|
set_target_properties(asteria-qt PROPERTIES
|
||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE $<NOT:$<CONFIG:Debug>>
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_options(asteria-qt PRIVATE -mwindows)
|
target_link_options(asteria-qt PRIVATE
|
||||||
|
$<$<NOT:$<CONFIG:Debug>>:-mwindows>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_include_directories(asteria-qt PRIVATE src)
|
target_include_directories(asteria-qt PRIVATE src)
|
||||||
|
|||||||
+66
-4
@@ -1,17 +1,63 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QIcon>
|
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QQuickStyle>
|
#include <QQuickStyle>
|
||||||
|
#include <QQuickWindow>
|
||||||
|
#include <QSGRendererInterface>
|
||||||
|
|
||||||
#include "backend/BookController.h"
|
#include "backend/BookController.h"
|
||||||
#include "backend/ReadingModel.h"
|
#include "backend/ReadingModel.h"
|
||||||
#include "backend/AppState.h"
|
#include "backend/AppState.h"
|
||||||
|
|
||||||
|
void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
|
{
|
||||||
|
QString timestamp = QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd hh:mm:ss.zzz"));
|
||||||
|
|
||||||
|
QString level;
|
||||||
|
switch (type) {
|
||||||
|
case QtDebugMsg: level = QStringLiteral("DEBUG"); break;
|
||||||
|
case QtInfoMsg: level = QStringLiteral("INFO"); break;
|
||||||
|
case QtWarningMsg: level = QStringLiteral("WARNING"); break;
|
||||||
|
case QtCriticalMsg: level = QStringLiteral("CRITICAL"); break;
|
||||||
|
case QtFatalMsg: level = QStringLiteral("FATAL"); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString source;
|
||||||
|
if (context.category && qstrcmp(context.category, "default") != 0) {
|
||||||
|
source = QString::fromUtf8(context.category);
|
||||||
|
} else if (context.file) {
|
||||||
|
QString fileName = QFileInfo(QString::fromUtf8(context.file)).fileName();
|
||||||
|
source = QStringLiteral("%1:%2").arg(fileName).arg(context.line);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString formattedMsg;
|
||||||
|
if (source.isEmpty()) {
|
||||||
|
formattedMsg = QStringLiteral("%1 [%2] %3").arg(timestamp, level, msg);
|
||||||
|
} else {
|
||||||
|
formattedMsg = QStringLiteral("%1 [%2] [%3] %4").arg(timestamp, level, source, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream(stdout, QIODevice::WriteOnly) << formattedMsg << Qt::endl;
|
||||||
|
|
||||||
|
if (type == QtFatalMsg) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
qInstallMessageHandler(myMessageHandler);
|
||||||
|
|
||||||
|
// Select graphics API per platform
|
||||||
|
#if defined(Q_OS_MACOS)
|
||||||
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::Metal);
|
||||||
|
#else
|
||||||
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::Vulkan);
|
||||||
|
#endif
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
QApplication::setApplicationName(QStringLiteral("Asteria"));
|
QApplication::setApplicationName(QStringLiteral("Asteria"));
|
||||||
QApplication::setOrganizationName(QStringLiteral("Asteria"));
|
QApplication::setOrganizationName(QStringLiteral("Asteria"));
|
||||||
@@ -34,8 +80,7 @@ int main(int argc, char *argv[])
|
|||||||
appState.restore();
|
appState.restore();
|
||||||
bookController.setAppState(&appState);
|
bookController.setAppState(&appState);
|
||||||
|
|
||||||
const QStringList args = QCoreApplication::arguments();
|
if (const QStringList args = QCoreApplication::arguments(); args.size() > 1) {
|
||||||
if (args.size() > 1) {
|
|
||||||
const QString& filePath = args.at(1);
|
const QString& filePath = args.at(1);
|
||||||
if (QFileInfo::exists(filePath))
|
if (QFileInfo::exists(filePath))
|
||||||
appState.setLastFilePath(filePath);
|
appState.setLastFilePath(filePath);
|
||||||
@@ -53,7 +98,24 @@ int main(int argc, char *argv[])
|
|||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
engine.load(url);
|
engine.load(url);
|
||||||
|
|
||||||
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&]() {
|
if (const auto *window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0))) {
|
||||||
|
const auto api = window->rendererInterface()->graphicsApi();
|
||||||
|
const char *apiName = [api]() {
|
||||||
|
switch (api) {
|
||||||
|
case QSGRendererInterface::OpenGL: return "OpenGL";
|
||||||
|
case QSGRendererInterface::Vulkan: return "Vulkan";
|
||||||
|
case QSGRendererInterface::Direct3D11: return "Direct3D 11";
|
||||||
|
case QSGRendererInterface::Direct3D12: return "Direct3D 12";
|
||||||
|
case QSGRendererInterface::Metal: return "Metal";
|
||||||
|
case QSGRendererInterface::Software: return "Software";
|
||||||
|
case QSGRendererInterface::Null: return "Null";
|
||||||
|
default: return "Unknown";
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
qInfo("Rendering API: %s", apiName);
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&bookController, &appState, &readingModel]() {
|
||||||
if (bookController.hasBook()) {
|
if (bookController.hasBook()) {
|
||||||
appState.setLastFilePath(bookController.currentFilePath());
|
appState.setLastFilePath(bookController.currentFilePath());
|
||||||
appState.setLastChapter(readingModel.currentChapter());
|
appState.setLastChapter(readingModel.currentChapter());
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ ApplicationWindow {
|
|||||||
property bool sidebarOpen: appState.sidebarOpen
|
property bool sidebarOpen: appState.sidebarOpen
|
||||||
onSidebarOpenChanged: appState.sidebarOpen = sidebarOpen
|
onSidebarOpenChanged: appState.sidebarOpen = sidebarOpen
|
||||||
property string currentPage: "starter"
|
property string currentPage: "starter"
|
||||||
property string pageFlipMode: appState.pageFlipMode
|
|
||||||
property bool _restoringState: false
|
property bool _restoringState: false
|
||||||
|
|
||||||
onCurrentPageChanged: appState.lastPage = currentPage
|
onCurrentPageChanged: appState.lastPage = currentPage
|
||||||
|
|||||||
Reference in new issue
Block a user