forked from HelloVolla/android-launcher-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
97 lines (81 loc) · 4.63 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <QtGui>
#include <QtQuick>
#include <QtAndroidExtras/QtAndroid>
#include "fileio.h"
#ifdef Q_OS_ANDROID
#include "AndroidNative/systemdispatcher.h"
#include "AndroidNative/environment.h"
#include "AndroidNative/debug.h"
#include "AndroidNative/mediascannerconnection.h"
#include <QtAndroidExtras/QAndroidJniObject>
#include <QtAndroidExtras/QAndroidJniEnvironment>
const QVector<QString> permissions({"android.permission.READ_CONTACTS",
"android.permission.READ_SMS",
"android.permission.SEND_SMS",
"android.permission.READ_CALL_LOG",
"android.permission.WRITE_CALL_LOG",
"android.permission.WRITE_SMS",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.SET_WALLPAPER",
"android.permission.CALL_PHONE",
"android.permission.WRITE_APN_SETTINGS",
"android.permission.MANAGE_APP_OPS_MODES",
"android.permission.CHANGE_COMPONENT_ENABLED_STATE",
"android.permission.QUERY_ALL_PACKAGES"});
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
Q_UNUSED(vm);
qDebug("NativeInterface::JNI_OnLoad()");
// It must call this function within JNI_OnLoad to enable System Dispatcher
AndroidNative::SystemDispatcher::registerNatives();
return JNI_VERSION_1_6;
}
#endif
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
app.setOrganizationName("Hallo Welt Systeme UG");
app.setOrganizationDomain("volla.online");
app.setApplicationName("Volla Launcher");
QTranslator myappTranslator;
if (myappTranslator.load(QLocale(), QLatin1String("Volla"), QLatin1String("_"), QLatin1String(":/i18n/")) != 1) {
qDebug() << "FAILED TO LOAD TRANSLATOR for LOCALE" << QLocale();
}
app.installTranslator(&myappTranslator);
qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.worker.ContactWorker");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.worker.MessageWorker");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.worker.CallWorker");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.worker.WallpaperWorker");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.worker.AppWorker");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.worker.ShortcutsWorker");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.parser.ArticleParser");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.LayoutUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.AppUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.CalendarUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.MessageUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.CallUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.VibrationUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.ShortcutUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.util.SignalUtil");
AndroidNative::SystemDispatcher::instance()->loadClass("com.volla.launcher.worker.SignalWorker");
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
QtAndroid::hideSplashScreen();
for (const QString &permission : permissions){
auto result = QtAndroid::checkPermission(permission);
if (result == QtAndroid::PermissionResult::Denied){
auto resultHash = QtAndroid::requestPermissionsSync(QStringList({permission}));
if(resultHash[permission] == QtAndroid::PermissionResult::Denied)
return 0;
}
}
return app.exec();
}