From 7ea6452de0bbd0590b48ca6e837eb6f87a23de11 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 3 Oct 2020 16:06:38 +1300 Subject: [PATCH 1/6] Fix Interface crash when using About.openUrl() in script --- interface/src/AboutUtil.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/interface/src/AboutUtil.cpp b/interface/src/AboutUtil.cpp index 56cabce03d..b9bea2d85c 100644 --- a/interface/src/AboutUtil.cpp +++ b/interface/src/AboutUtil.cpp @@ -45,6 +45,16 @@ QString AboutUtil::getQtVersion() const { } void AboutUtil::openUrl(const QString& url) const { + auto abboutUtilInstance = AboutUtil::getInstance(); + if (!abboutUtilInstance) { + return; + } + + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(abboutUtilInstance, "openUrl", Q_ARG(const QString&, url)); + return; + } + auto tablet = DependencyManager::get()->getTablet("com.highfidelity.interface.tablet.system"); auto hmd = DependencyManager::get(); auto offscreenUi = DependencyManager::get(); From 86aa3c87092697befe753a09f78e3559bced1c71 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 3 Oct 2020 16:29:14 +1300 Subject: [PATCH 2/6] Make chat open links in internal Web browser instead of custom window --- .eslintrc.js | 1 + scripts/communityScripts/chat/FloofChat.js | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9900825b23..df606f0dc9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,6 +5,7 @@ module.exports = { "ecmaVersion": 5 }, "globals": { + "About": false, "Account": false, "Agent": false, "AnimationCache": false, diff --git a/scripts/communityScripts/chat/FloofChat.js b/scripts/communityScripts/chat/FloofChat.js index b558e52bf8..2d8094d83e 100644 --- a/scripts/communityScripts/chat/FloofChat.js +++ b/scripts/communityScripts/chat/FloofChat.js @@ -322,13 +322,7 @@ function onWebEventReceived(event) { gotoConfirm(event.url); } if (event.cmd === "URL") { - new OverlayWebWindow({ - title: 'Web', - source: event.url, - width: 900, - height: 700, - visible: true - }); + About.openUrl(event.url); } if (event.cmd === "EXTERNALURL") { Window.openUrl(event.url); From 64eb4d11e106d6ce94b8ad3867c34f4d62baecd7 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 3 Oct 2020 17:00:43 +1300 Subject: [PATCH 3/6] 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: From 3e94a034caa8e52fe4a7959ee3e5115899e4c747 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 3 Oct 2020 17:01:01 +1300 Subject: [PATCH 4/6] Use Window.openWebBrowser() instead of About.openUrl() in chat script --- scripts/communityScripts/chat/FloofChat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/communityScripts/chat/FloofChat.js b/scripts/communityScripts/chat/FloofChat.js index 2d8094d83e..1208a36e5f 100644 --- a/scripts/communityScripts/chat/FloofChat.js +++ b/scripts/communityScripts/chat/FloofChat.js @@ -322,7 +322,7 @@ function onWebEventReceived(event) { gotoConfirm(event.url); } if (event.cmd === "URL") { - About.openUrl(event.url); + Window.openWebBrowser(event.url); } if (event.cmd === "EXTERNALURL") { Window.openUrl(event.url); From cd7e1d0865e361c3cf5a9d7549b715ec6ea8b473 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 3 Oct 2020 17:01:46 +1300 Subject: [PATCH 5/6] Miscellaneous tidying --- interface/src/AboutUtil.h | 2 +- interface/src/scripting/WindowScriptingInterface.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/AboutUtil.h b/interface/src/AboutUtil.h index a602528154..8cc76dad1e 100644 --- a/interface/src/AboutUtil.h +++ b/interface/src/AboutUtil.h @@ -79,7 +79,7 @@ public: public slots: /**jsdoc - * Display a web page in an Interface browser window. + * Display a web page in an Interface browser window or the tablet. * @function About.openUrl * @param {string} url - The URL of the web page you want to view in Interface. */ diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index f4b0b958db..14a0d04023 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -650,7 +650,7 @@ void WindowScriptingInterface::openWebBrowser(const QString& url) { QMetaObject::invokeMethod(this, "openWebBrowser", Q_ARG(const QString&, url)); return; } - + auto offscreenUi = DependencyManager::get(); offscreenUi->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) { if (!url.isEmpty()) { From 081c0672bf67d167c8be89a02abb81751d2bf867 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 3 Oct 2020 17:05:28 +1300 Subject: [PATCH 6/6] Fix JSDoc --- interface/src/scripting/WindowScriptingInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 9aecdd0154..86d0f400ea 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -618,7 +618,7 @@ public slots: /**jsdoc * Opens an Interface web browser window. * @function Window.openWebBrowser - * @param {string} url="" - The URL of the web page to display. + * @param {string} [url=""] - The URL of the web page to display. */ void openWebBrowser(const QString& url = "");