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[])
86 QByteArray imModule = qgetenv(
"QT_IM_MODULE");
87 qDebug(log) <<
"QT_IM_MODULE set to:" << imModule;
89 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
99#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) \
100 && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)))
107 QString szPlatform = qEnvironmentVariable(
"QT_QPA_PLATFORM");
108 if(szPlatform.isEmpty()
109 || -1 != szPlatform.indexOf(QRegularExpression(
"wayland.*")))
110 qputenv(
"QT_QPA_PLATFORM",
"xcb");
111 qInfo(log) <<
"QT_QPA_PLATFORM:" << szPlatform <<
"\nCurrent Qt Platform is:"
112 << qEnvironmentVariable(
"QT_QPA_PLATFORM")
113 <<
"; This can be modified with the environment variables QT_QPA_PLATFORM:\n"
114 <<
"export QT_QPA_PLATFORM=xcb\n Optional: xcb; vnc";
116#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
117 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
119#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
120 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();
143 QStringList permissions;
144 permissions <<
"android.permission.WRITE_EXTERNAL_STORAGE"
145 <<
"android.permission.READ_EXTERNAL_STORAGE"
146 <<
"android.permission.INTERNET"
147 <<
"android.permission.WAKE_LOCK";
148 RabbitCommon::CTools::AndroidRequestPermission(permissions);
150 QSharedPointer<QTranslator> tApp =
151 RabbitCommon::CTools::Instance()->InstallTranslator(
"RabbitRemoteControlApp");
153 app.setApplicationDisplayName(QObject::tr(
"Rabbit Remote Control"));
154 app.setOrganizationName(QObject::tr(
"Kang Lin Studio"));
158 QScopedPointer<CFrmUpdater> pUpdater(
new CFrmUpdater());
159#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
160 if(qEnvironmentVariable(
"SNAP").isEmpty()
161 && qEnvironmentVariable(
"FLATPAK_ID").isEmpty())
163 if(qgetenv(
"SNAP").isEmpty()
164 && qgetenv(
"FLATPAK_ID").isEmpty())
168 pUpdater->setAttribute(Qt::WA_DeleteOnClose,
false);
169 QIcon icon = QIcon::fromTheme(
"app");
171 auto sizeList = icon.availableSizes();
172 if(!sizeList.isEmpty()) {
173 QPixmap p = icon.pixmap(*sizeList.begin());
174 pUpdater->SetTitle(p.toImage());
177 if(app.arguments().length() > 1) {
179 pUpdater->GenerateUpdateJson();
180 pUpdater->GenerateUpdateXml();
182 qCritical(log) <<
"Generate update fail";
184 qInfo(log) << app.applicationName() +
" " + app.applicationVersion()
185 +
" " + QObject::tr(
"Generate update json file End");
189 qCritical(log) <<
"new CFrmUpdater() fail";
213 }
catch (std::exception &e) {
214 qCritical(log) <<
"exception:" << e.what();
216 qCritical(log) <<
"exception:";
226 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
229 qInfo(log) << app.applicationName() +
" " + app.applicationVersion() +
" " +
"End";
231 RabbitCommon::CTools::Instance()->Clean();
int Initial()
For time-consuming operations.