16#include <QLoggingCategory>
17#include <QApplication>
21#include <QSharedPointer>
22#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
23 #include <QRegularExpression>
24 #include <QRandomGenerator>
26#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
27 #include <QRandomGenerator>
29#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
33#include "RabbitCommonTools.h"
36#include "FrmUpdater.h"
39 #include "QUIWidget/QUIWidget.h"
42#include "StatsAppUsage.h"
43#include "mainwindow.h"
45static Q_LOGGING_CATEGORY(log,
"App.Main")
47int main(
int argc,
char *argv[])
51 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
61#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) \
62 && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)))
69 QString szPlatform = qEnvironmentVariable(
"QT_QPA_PLATFORM");
70 if(szPlatform.isEmpty()
71 || -1 != szPlatform.indexOf(QRegularExpression(
"wayland.*")))
72 qputenv(
"QT_QPA_PLATFORM",
"xcb");
73 qInfo(log) <<
"QT_QPA_PLATFORM:" << szPlatform <<
"\nCurrent Qt Platform is:"
74 << qEnvironmentVariable(
"QT_QPA_PLATFORM")
75 <<
"; This can be modified with the environment variables QT_QPA_PLATFORM:\n"
76 <<
"export QT_QPA_PLATFORM=xcb\n Optional: xcb; vnc";
78#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
79 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
81#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
82 QtAndroid::hideSplashScreen();
89 QApplication::setApplicationVersion(RabbitRemoteControl_VERSION);
90 QApplication::setApplicationName(
"RabbitRemoteControl");
91#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
92 QApplication::setDesktopFileName(QLatin1String(
"io.github.KangLin.RabbitRemoteControl.desktop"));
95 QApplication app(argc, argv);
97 RabbitCommon::CTools::Instance()->Init();
99 qInfo(log) << app.applicationName() +
" " + app.applicationVersion()
100 +
" " + QObject::tr(
"Start") +
" ......"
101 <<
"\n" << app.arguments();
103 QSharedPointer<QTranslator> tApp =
104 RabbitCommon::CTools::Instance()->InstallTranslator(
"RabbitRemoteControlApp");
106 app.setApplicationDisplayName(QObject::tr(
"Rabbit Remote Control"));
107 app.setOrganizationName(QObject::tr(
"Kang Lin Studio"));
110 QSharedPointer<CFrmUpdater> pUpdate;
112 if(qEnvironmentVariable(
"SNAP").isEmpty()
113 && qEnvironmentVariable(
"FLATPAK_ID").isEmpty()) {
114 pUpdate = QSharedPointer<CFrmUpdater>(
new CFrmUpdater());
116 QIcon icon = QIcon::fromTheme(
"app");
119 auto sizeList = icon.availableSizes();
120 if(!sizeList.isEmpty()){
121 QPixmap p = icon.pixmap(*sizeList.begin());
122 pUpdate->SetTitle(p.toImage());
125 if(app.arguments().length() > 1) {
127 pUpdate->GenerateUpdateJson();
128 pUpdate->GenerateUpdateXml();
130 qCritical(log) <<
"Generate update fail";
132 qInfo(log) << app.applicationName() +
" " + app.applicationVersion()
133 +
" " + QObject::tr(
"Generate update json file End");
137 qCritical(log) <<
"new CFrmUpdater() fail";
146#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
147 randomInt = QRandomGenerator::global()->bounded(nMin, nMax);
149 qsrand(
static_cast<uint
>(QTime::currentTime().msec()));
150 randomInt = nMin + qrand() % (nMax - nMin + 1);
152 QTimer::singleShot(randomInt, [&](){
153 pStats =
new CStatsAppUsage(
"v" + QApplication::applicationVersion());
168 }
catch (std::exception &e) {
169 qCritical(log) <<
"exception:" << e.what();
171 qCritical(log) <<
"exception:";
180 RabbitCommon::CTools::Instance()->Clean();
182 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
187 qInfo(log) << app.applicationName() +
" " + app.applicationVersion() +
" " +
"End";
void slotInitial()
For time-consuming operations.