mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-27 03:30:20 +00:00
Fix launching Okular by opening a document from the file browser
Summary: There's two issues here: - Activity::onCreate triggered before the C++ side was loaded, so the call to C++ failed (causing a crash). So delay that until we are ready. - The static instance of URIHandler in the header caused it to duplicate into each translation unit, causing main.cpp to not see what android.cpp wrote into it. Subscribers: okular-devel Tags: #okular Differential Revision: https://phabricator.kde.org/D18399
This commit is contained in:
parent
1fd9c052a6
commit
a9540cf3ce
|
@ -40,9 +40,7 @@ public class OpenFileActivity extends QtActivity
|
|||
FileClass.openUri(uri.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
public void handleViewIntent() {
|
||||
final Intent bundleIntent = getIntent();
|
||||
if (bundleIntent == null)
|
||||
return;
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
*************************************************************************************/
|
||||
|
||||
#include "android.h"
|
||||
#include <QtAndroid>
|
||||
#include <QAndroidJniObject>
|
||||
#include <QAndroidJniEnvironment>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
URIHandler URIHandler::handler;
|
||||
static AndroidInstance* s_instance = nullptr;
|
||||
|
||||
void AndroidInstance::openFile(const QString &title, const QStringList &mimes)
|
||||
|
@ -44,6 +46,11 @@ void AndroidInstance::openFile(const QString &title, const QStringList &mimes)
|
|||
}
|
||||
}
|
||||
|
||||
void AndroidInstance::handleViewIntent()
|
||||
{
|
||||
QtAndroid::androidActivity().callMethod<void>("handleViewIntent", "()V");
|
||||
}
|
||||
|
||||
void Java_org_kde_something_FileClass_openUri(JNIEnv *env,
|
||||
jobject /*obj*/,
|
||||
jstring uri)
|
||||
|
@ -54,7 +61,7 @@ void Java_org_kde_something_FileClass_openUri(JNIEnv *env,
|
|||
if (s_instance)
|
||||
s_instance->openUri(QUrl(uriString));
|
||||
else
|
||||
handler.openUri(uriString);
|
||||
URIHandler::handler.openUri(uriString);
|
||||
env->ReleaseStringUTFChars(uri, utf);
|
||||
|
||||
}
|
||||
|
|
|
@ -30,16 +30,17 @@ public:
|
|||
}
|
||||
|
||||
QString m_lastUrl;
|
||||
static URIHandler handler;
|
||||
};
|
||||
|
||||
static URIHandler handler;
|
||||
|
||||
class AndroidInstance : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_SCRIPTABLE void openFile(const QString &title, const QStringList &mimes);
|
||||
|
||||
static void handleViewIntent();
|
||||
|
||||
Q_SIGNALS:
|
||||
void openUri(const QUrl &uri);
|
||||
};
|
||||
|
|
|
@ -49,8 +49,9 @@ int main(int argc, char *argv[])
|
|||
QQmlApplicationEngine engine;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
AndroidInstance::handleViewIntent();
|
||||
qmlRegisterSingletonType<QObject>("org.kde.okular.app", 2, 0, "AndroidInstance", [](QQmlEngine*, QJSEngine*) -> QObject* { return new AndroidInstance; });
|
||||
const QString uri = handler.m_lastUrl;
|
||||
const QString uri = URIHandler::handler.m_lastUrl;
|
||||
#else
|
||||
qmlRegisterSingletonType<QObject>("org.kde.okular.app", 2, 0, "AndroidInstance", [](QQmlEngine*, QJSEngine*) -> QObject* { return new QObject; });
|
||||
const QString uri = parser.positionalArguments().count() == 1
|
||||
|
|
Loading…
Reference in a new issue