16#include <QSplashScreen>
18#include <QLoggingCategory>
19#include <QApplication>
23#include <QSharedPointer>
25#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
26 #include <QRegularExpression>
28#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
29 #include <QRandomGenerator>
31#if defined(Q_OS_ANDROID) && ((QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)))
35#include "RabbitCommonTools.h"
38#include "FrmUpdater.h"
41 #include "QUIWidget/QUIWidget.h"
44#include "StatsAppUsage.h"
45#include "mainwindow.h"
47static Q_LOGGING_CATEGORY(log,
"App")
50void InitAndroidVirtualKeyboard()
53 qputenv(
"QT_IM_MODULE",
"qtvirtualkeyboard");
74int main(
int argc,
char *argv[])
87 QByteArray imModule = qgetenv(
"QT_IM_MODULE");
88 qDebug(log) <<
"QT_IM_MODULE set to:" << imModule;
90 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
101#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) \
102 && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)))
110 QString szPlatform = qEnvironmentVariable(
"QT_QPA_PLATFORM");
111 if(szPlatform.isEmpty()
112 || -1 != szPlatform.indexOf(QRegularExpression(
"wayland.*")))
113 qputenv(
"QT_QPA_PLATFORM",
"xcb");
114 qInfo(log) <<
"QT_QPA_PLATFORM:" << szPlatform <<
"\nCurrent Qt Platform is:"
115 << qEnvironmentVariable(
"QT_QPA_PLATFORM")
116 <<
"; This can be modified with the environment variables QT_QPA_PLATFORM:\n"
117 <<
"export QT_QPA_PLATFORM=xcb\n Optional: xcb; vnc";
120#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
121 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
124 QApplication::setApplicationVersion(RabbitRemoteControl_VERSION);
125 QApplication::setApplicationName(
"RabbitRemoteControl");
126#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
127 QApplication::setDesktopFileName(QLatin1String(
"io.github.KangLin.RabbitRemoteControl.desktop"));
130 QApplication app(argc, argv);
132 QInputMethod *inputMethod = app.inputMethod();
133 qDebug(log) <<
"Input method available:" << (inputMethod !=
nullptr);
135 qDebug(log) <<
"Input method locale:" << inputMethod->locale();
137 RabbitCommon::CTools::Instance()->Init();
139 qInfo(log) << app.applicationName() +
" " + app.applicationVersion()
140 +
" " + QObject::tr(
"Start") +
" ......"
141 <<
"\n" << app.arguments();
144#if defined(Q_OS_ANDROID)
146 #if QT_VERSION > QT_VERSION_CHECK(6, 2, 0)
147 QNativeInterface::QAndroidApplication::hideSplashScreen();
148 #elif QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
149 QtAndroid::hideSplashScreen();
152 QStringList permissions;
153 permissions <<
"android.permission.WRITE_EXTERNAL_STORAGE"
154 <<
"android.permission.READ_EXTERNAL_STORAGE"
155 <<
"android.permission.INTERNET"
156 <<
"android.permission.WAKE_LOCK"
157 <<
"android.permission.REQUEST_INSTALL_PACKAGES"
158 <<
"android.permission.ACCESS_NETWORK_STATE"
159 <<
"android.permission.BLUETOOTH"
160 <<
"android.permission.ACCESS_FINE_LOCATION"
161 <<
"android.permission.VIBRATE"
162 <<
"android.permission.CAMERA"
163 <<
"android.permission.CALL_PHONE"
164 <<
"android.permission.WAKE_LOCK"
165 <<
"android.permission.DEVICE_POWER";
166 RabbitCommon::CTools::AndroidRequestPermission(permissions);
169 QSharedPointer<QTranslator> tApp =
170 RabbitCommon::CTools::Instance()->InstallTranslator(
"RabbitRemoteControlApp");
172 app.setApplicationDisplayName(QObject::tr(
"Rabbit Remote Control"));
173 app.setOrganizationName(QObject::tr(
"Kang Lin Studio"));
175 ShowMessageInSplashScreen(QObject::tr(
"Start") +
" ......");
179 QScopedPointer<CFrmUpdater> pUpdater(
new CFrmUpdater());
180#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
181 if(qEnvironmentVariable(
"SNAP").isEmpty()
182 && qEnvironmentVariable(
"FLATPAK_ID").isEmpty())
184 if(qgetenv(
"SNAP").isEmpty()
185 && qgetenv(
"FLATPAK_ID").isEmpty())
189 pUpdater->setAttribute(Qt::WA_DeleteOnClose,
false);
192 auto sizeList = icon.availableSizes();
193 if(!sizeList.isEmpty()) {
194 QPixmap p = icon.pixmap(*sizeList.begin());
195 pUpdater->SetTitle(p.toImage());
199 CFrmUpdater::ErrCode err = CFrmUpdater::ErrCode::Success;
201 ShowMessageInSplashScreen(QObject::tr(
"Generate update json file ......"));
202 err = pUpdater->GenerateUpdateJson();
203 pUpdater->GenerateUpdateXml();
205 qCritical(log) <<
"Generate update fail";
207 qInfo(log) << app.applicationName() +
" " + app.applicationVersion()
208 +
" " + QObject::tr(
"Generate update json file End");
209 if(CFrmUpdater::ErrCode::Arguments == err)
213 qCritical(log) <<
"new CFrmUpdater() fail";
225 ShowMessageInSplashScreen(QObject::tr(
"Create main window ......"));
234 ShowMessageInSplashScreen();
237 }
catch (std::exception &e) {
238 qCritical(log) <<
"exception:" << e.what();
240 qCritical(log) <<
"app exec exception";
251 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
254 qInfo(log) << app.applicationName() +
" " + app.applicationVersion() +
" " +
"End";
256 RabbitCommon::CTools::Instance()->Clean();
MainWindow(QWidget *parent=nullptr)
int Initial()
For time-consuming operations.