17#include <QLoggingCategory>
18#include <QApplication>
22#include <QSharedPointer>
23#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
24 #include <QRegularExpression>
25 #include <QRandomGenerator>
27#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
28 #include <QRandomGenerator>
30#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
34#include "RabbitCommonTools.h"
37#include "FrmUpdater.h"
40 #include "QUIWidget/QUIWidget.h"
43#include "StatsAppUsage.h"
44#include "mainwindow.h"
46static Q_LOGGING_CATEGORY(log,
"App.Main")
49void InitAndroidVirtualKeyboard()
52 qputenv(
"QT_IM_MODULE",
"qtvirtualkeyboard");
73int main(
int argc,
char *argv[])
82 QByteArray imModule = qgetenv(
"QT_IM_MODULE");
83 qDebug(log) <<
"QT_IM_MODULE set to:" << imModule;
85 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
95#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) \
96 && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)))
103 QString szPlatform = qEnvironmentVariable(
"QT_QPA_PLATFORM");
104 if(szPlatform.isEmpty()
105 || -1 != szPlatform.indexOf(QRegularExpression(
"wayland.*")))
106 qputenv(
"QT_QPA_PLATFORM",
"xcb");
107 qInfo(log) <<
"QT_QPA_PLATFORM:" << szPlatform <<
"\nCurrent Qt Platform is:"
108 << qEnvironmentVariable(
"QT_QPA_PLATFORM")
109 <<
"; This can be modified with the environment variables QT_QPA_PLATFORM:\n"
110 <<
"export QT_QPA_PLATFORM=xcb\n Optional: xcb; vnc";
112#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
113 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
115#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
116 QtAndroid::hideSplashScreen();
123 QApplication::setApplicationVersion(RabbitRemoteControl_VERSION);
124 QApplication::setApplicationName(
"RabbitRemoteControl");
125#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
126 QApplication::setDesktopFileName(QLatin1String(
"io.github.KangLin.RabbitRemoteControl.desktop"));
129 QApplication app(argc, argv);
131 QInputMethod *inputMethod = app.inputMethod();
132 qDebug(log) <<
"Input method available:" << (inputMethod !=
nullptr);
134 qDebug(log) <<
"Input method locale:" << inputMethod->locale();
136 RabbitCommon::CTools::Instance()->Init();
138 qInfo(log) << app.applicationName() +
" " + app.applicationVersion()
139 +
" " + QObject::tr(
"Start") +
" ......"
140 <<
"\n" << app.arguments();
142 QSharedPointer<QTranslator> tApp =
143 RabbitCommon::CTools::Instance()->InstallTranslator(
"RabbitRemoteControlApp");
145 app.setApplicationDisplayName(QObject::tr(
"Rabbit Remote Control"));
146 app.setOrganizationName(QObject::tr(
"Kang Lin Studio"));
150 QScopedPointer<CFrmUpdater> pUpdater(
new CFrmUpdater());
151#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
152 if(qEnvironmentVariable(
"SNAP").isEmpty()
153 && qEnvironmentVariable(
"FLATPAK_ID").isEmpty())
155 if(qgetenv(
"SNAP").isEmpty()
156 && qgetenv(
"FLATPAK_ID").isEmpty())
160 pUpdater->setAttribute(Qt::WA_DeleteOnClose,
false);
161 QIcon icon = QIcon::fromTheme(
"app");
163 auto sizeList = icon.availableSizes();
164 if(!sizeList.isEmpty()) {
165 QPixmap p = icon.pixmap(*sizeList.begin());
166 pUpdater->SetTitle(p.toImage());
169 if(app.arguments().length() > 1) {
171 pUpdater->GenerateUpdateJson();
172 pUpdater->GenerateUpdateXml();
174 qCritical(log) <<
"Generate update fail";
176 qInfo(log) << app.applicationName() +
" " + app.applicationVersion()
177 +
" " + QObject::tr(
"Generate update json file End");
181 qCritical(log) <<
"new CFrmUpdater() fail";
214 }
catch (std::exception &e) {
215 qCritical(log) <<
"exception:" << e.what();
217 qCritical(log) <<
"exception:";
226 RabbitCommon::CTools::Instance()->Clean();
228 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
233 qInfo(log) << app.applicationName() +
" " + app.applicationVersion() +
" " +
"End";
int Initial()
For time-consuming operations