Files
amnezia-client/client/main.cpp
T

101 lines
3.0 KiB
C++
Raw Normal View History

2020-11-23 16:20:25 +03:00
#include <QApplication>
#include <QFontDatabase>
#include <QCommandLineParser>
#include <QMessageBox>
#include <QTranslator>
2021-03-06 14:59:55 +03:00
#include <QTimer>
2021-03-14 21:19:11 +03:00
#include <QLoggingCategory>
2021-07-28 16:13:29 +07:00
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "ui/uilogic.h"
2021-08-09 00:41:52 +07:00
#include <QDebug>
2020-11-23 16:20:25 +03:00
2020-12-04 00:45:21 +03:00
#include "debug.h"
#include "defines.h"
2021-07-28 16:13:29 +07:00
#define QAPPLICATION_CLASS QGuiApplication
2021-02-24 13:38:23 -08:00
#include "singleapplication.h"
2021-07-28 16:13:29 +07:00
#undef QAPPLICATION_CLASS
2020-11-23 16:20:25 +03:00
2021-02-24 23:40:57 +03:00
#ifdef Q_OS_WIN
#include "Windows.h"
#endif
2020-12-26 15:03:51 +03:00
static void loadTranslator()
{
QTranslator* translator = new QTranslator;
if (translator->load(QLocale(), QString("amneziavpn"), QLatin1String("_"), QLatin1String(":/translations"))) {
qApp->installTranslator(translator);
}
}
2020-11-23 16:20:25 +03:00
int main(int argc, char *argv[])
{
2021-03-14 21:19:11 +03:00
QLoggingCategory::setFilterRules(QStringLiteral("qtc.ssh=false"));
2020-11-23 16:20:25 +03:00
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
2021-02-24 23:40:57 +03:00
#ifdef Q_OS_WIN
AllowSetForegroundWindow(ASFW_ANY);
#endif
2021-03-06 14:59:55 +03:00
SingleApplication app(argc, argv, true, SingleApplication::Mode::User | SingleApplication::Mode::SecondaryNotification);
2021-02-24 23:40:57 +03:00
2021-03-06 14:59:55 +03:00
if (!app.isPrimary()) {
QTimer::singleShot(1000, &app, [&](){
app.quit();
});
return app.exec();
}
2021-02-24 23:40:57 +03:00
#ifdef Q_OS_WIN
AllowSetForegroundWindow(0);
#endif
2020-11-23 16:20:25 +03:00
2020-12-26 15:03:51 +03:00
loadTranslator();
2020-11-23 16:20:25 +03:00
QFontDatabase::addApplicationFont(":/fonts/Lato-Black.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-BlackItalic.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-BoldItalic.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-Italic.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-Light.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-LightItalic.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-Thin.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-ThinItalic.ttf");
2020-12-04 00:45:21 +03:00
app.setApplicationName(APPLICATION_NAME);
app.setOrganizationName(ORGANIZATION_NAME);
app.setApplicationDisplayName(APPLICATION_NAME);
2020-11-23 16:20:25 +03:00
QCommandLineParser parser;
2020-12-04 00:45:21 +03:00
parser.setApplicationDescription(APPLICATION_NAME);
2020-11-23 16:20:25 +03:00
parser.addHelpOption();
parser.addVersionOption();
2021-05-11 17:04:04 +03:00
QCommandLineOption c_autostart {{"a", "autostart"}, "System autostart"};
parser.addOption(c_autostart);
parser.process(app);
2020-12-16 06:02:22 +03:00
if (!Debug::init()) {
2020-12-26 15:03:51 +03:00
qWarning() << "Initialization of debug subsystem failed";
2020-11-23 16:20:25 +03:00
}
2021-01-09 19:55:16 +03:00
app.setQuitOnLastWindowClosed(false);
2021-07-28 16:13:29 +07:00
UiLogic uiLogic;
QQmlApplicationEngine engine;
2021-08-09 00:41:52 +07:00
UiLogic::declareQML();
2021-07-28 16:13:29 +07:00
const QUrl url(QStringLiteral("qrc:/ui/qml/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.rootContext()->setContextProperty("UiLogic", &uiLogic);
engine.load(url);
2021-02-24 23:40:57 +03:00
2020-11-23 16:20:25 +03:00
return app.exec();
}