moonlight-qt/app/main.cpp

65 lines
2.3 KiB
C++
Raw Normal View History

2018-07-04 21:16:25 +00:00
#include <QGuiApplication>
#include <QQmlApplicationEngine>
2018-04-28 22:39:50 +00:00
2018-06-24 05:16:59 +00:00
// Don't let SDL hook our main function, since Qt is already
2018-07-07 23:37:11 +00:00
// doing the same thing. This needs to be before any headers
// that might include SDL.h themselves.
2018-06-24 05:16:59 +00:00
#define SDL_MAIN_HANDLED
#include <SDL.h>
2018-07-07 23:37:11 +00:00
#include "gui/computermodel.h"
#include "gui/appmodel.h"
#include "streaming/session.hpp"
2018-04-28 22:39:50 +00:00
int main(int argc, char *argv[])
{
2018-07-04 21:16:25 +00:00
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
2018-05-06 04:59:30 +00:00
// This avoids using the default keychain for SSL, which may cause
// password prompts on macOS.
qputenv("QT_SSL_USE_TEMPORARY_KEYCHAIN", QByteArray("1"));
// Set these here to allow us to use the default QSettings constructor
QCoreApplication::setOrganizationName("Moonlight Game Streaming Project");
QCoreApplication::setOrganizationDomain("moonlight-stream.com");
QCoreApplication::setApplicationName("Moonlight");
// Register custom metatypes for use in signals
qRegisterMetaType<NvApp>("NvApp");
2018-07-04 21:16:25 +00:00
QGuiApplication app(argc, argv);
2018-07-04 23:40:21 +00:00
// Register our C++ types for QML
qmlRegisterType<ComputerModel>("ComputerModel", 1, 0, "ComputerModel");
qmlRegisterType<AppModel>("AppModel", 1, 0, "AppModel");
qmlRegisterUncreatableType<Session>("Session", 1, 0, "Session", "Session cannot be created from QML");
qmlRegisterSingletonType<ComputerManager>("ComputerManager", 1, 0,
"ComputerManager",
[](QQmlEngine*, QJSEngine*) -> QObject* {
return new ComputerManager();
});
2018-07-04 23:40:21 +00:00
2018-07-04 21:16:25 +00:00
// Load the main.qml file
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/gui/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
2018-04-28 22:39:50 +00:00
2018-06-24 05:16:59 +00:00
// Ensure that SDL is always initialized since we may need to use it
// for non-streaming purposes (like checking on audio devices)
SDL_SetMainReady();
if (SDL_Init(SDL_INIT_VIDEO |
SDL_INIT_AUDIO |
SDL_INIT_GAMECONTROLLER) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_Init() failed: %s",
SDL_GetError());
}
2018-07-04 21:16:25 +00:00
int err = app.exec();
2018-06-24 05:16:59 +00:00
SDL_Quit();
2018-06-24 05:16:59 +00:00
return err;
2018-04-28 22:39:50 +00:00
}