forked from Stremio/stremio-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
116 lines (89 loc) · 3.6 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <QQmlApplicationEngine>
#include <QtWebEngine>
#include <QSysInfo>
#include <clocale>
#define APP_TITLE "Stremio - All You Can Watch"
#define DESKTOP true
#ifdef DESKTOP
#include <QtWidgets/QApplication>
typedef QApplication Application;
#include <QQmlEngine>
#include <QStandardPaths>
#include <QSystemTrayIcon>
#include "systemtray.h"
#include "mainapplication.h"
#include "stremioprocess.h"
#include "mpv.h"
#include "screensaver.h"
#include "razerchroma.h"
#include "qclipboardproxy.h"
#else
#include <QGuiApplication>
#endif
void InitializeParameters(QQmlApplicationEngine *engine, MainApp& app) {
QQmlContext *ctx = engine->rootContext();
SystemTray * systemTray = new SystemTray();
ctx->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
ctx->setContextProperty("appTitle", QString(APP_TITLE));
ctx->setContextProperty("autoUpdater", app.autoupdater);
// Set access to an object of class properties in QML context
ctx->setContextProperty("systemTray", systemTray);
#ifdef QT_DEBUG
ctx->setContextProperty("debug", true);
#else
ctx->setContextProperty("debug", false);
#endif
}
int main(int argc, char **argv)
{
#ifdef _WIN32
// Default to ANGLE (DirectX), because that seems to eliminate so many issues on Windows
// Also, according to the docs here: https://wiki.qt.io/Qt_5_on_Windows_ANGLE_and_OpenGL, ANGLE is also preferrable
// We do not need advanced OpenGL features but we need more universal support
Application::setAttribute(Qt::AA_UseOpenGLES);
auto winVer = QSysInfo::windowsVersion();
if(winVer <= QSysInfo::WV_WINDOWS7 && winVer != QSysInfo::WV_None) {
qputenv("QT_ANGLE_PLATFORM", "d3d9");
}
#endif
// This is really broken on Linux
#ifndef Q_OS_LINUX
Application::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
Application::setApplicationName("Stremio");
Application::setApplicationVersion(STREMIO_SHELL_VERSION);
Application::setOrganizationName("Smart Code ltd");
Application::setOrganizationDomain("stremio.com");
MainApp app(argc, argv, true);
#ifndef Q_OS_MACOS
if( app.isSecondary() ) {
if( app.arguments().count() > 1)
app.sendMessage( app.arguments().at(1).toUtf8() );
else
app.sendMessage( "SHOW" );
//app.sendMessage( app.arguments().join(' ').toUtf8() );
return 0;
}
#endif
app.setWindowIcon(QIcon(":/images/stremio_window.png"));
// Qt sets the locale in the QGuiApplication constructor, but libmpv
// requires the LC_NUMERIC category to be set to "C", so change it back.
std::setlocale(LC_NUMERIC, "C");
static QQmlApplicationEngine* engine = new QQmlApplicationEngine();
qmlRegisterType<Process>("com.stremio.process", 1, 0, "Process");
qmlRegisterType<ScreenSaver>("com.stremio.screensaver", 1, 0, "ScreenSaver");
qmlRegisterType<MpvObject>("com.stremio.libmpv", 1, 0, "MpvObject");
qmlRegisterType<RazerChroma>("com.stremio.razerchroma", 1, 0, "RazerChroma");
qmlRegisterType<ClipboardProxy>("com.stremio.clipboard", 1, 0, "Clipboard");
InitializeParameters(engine, app);
engine->load(QUrl(QStringLiteral("qrc:/main.qml")));
#ifndef Q_OS_MACOS
QObject::connect( &app, &SingleApplication::receivedMessage, &app, &MainApp::processMessage );
#endif
QObject::connect( &app, SIGNAL(receivedMessage(QVariant, QVariant)), engine->rootObjects().value(0),
SLOT(onAppMessageReceived(QVariant, QVariant)) );
int ret = app.exec();
delete engine;
engine = nullptr;
return ret;
}