From 64eb4d11e106d6ce94b8ad3867c34f4d62baecd7 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 3 Oct 2020 17:00:43 +1300 Subject: [PATCH] Add URL parameter to Window.openUrl() API function --- interface/src/scripting/WindowScriptingInterface.cpp | 12 ++++++++---- interface/src/scripting/WindowScriptingInterface.h | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 434adf0bc8..f4b0b958db 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -645,12 +645,16 @@ void WindowScriptingInterface::setActiveDisplayPlugin(int index) { qApp->setActiveDisplayPlugin(name); } -void WindowScriptingInterface::openWebBrowser() { +void WindowScriptingInterface::openWebBrowser(const QString& url) { if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "openWebBrowser", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "openWebBrowser", Q_ARG(const QString&, url)); return; } - + auto offscreenUi = DependencyManager::get(); - offscreenUi->load("Browser.qml"); + offscreenUi->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) { + if (!url.isEmpty()) { + newObject->setProperty("url", url); + } + }); } diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 28a725f3cb..9aecdd0154 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -616,10 +616,11 @@ public slots: void setActiveDisplayPlugin(int index); /**jsdoc - * Opens a web browser in a pop-up window. + * Opens an Interface web browser window. * @function Window.openWebBrowser + * @param {string} url="" - The URL of the web page to display. */ - void openWebBrowser(); + void openWebBrowser(const QString& url = ""); private slots: