From 885801c5ca7e19ead63880112ebc672d7e2c787a Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Tue, 16 Jan 2018 13:17:47 -0500 Subject: [PATCH] Fix copying to clipboard from JS scripts --- interface/src/scripting/WindowScriptingInterface.cpp | 5 +++++ libraries/networking/src/AddressManager.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index e36b84ac96..e50eb06355 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -411,6 +411,11 @@ int WindowScriptingInterface::getY() { } void WindowScriptingInterface::copyToClipboard(const QString& text) { + if (QThread::currentThread() != qApp->thread()) { + QMetaObject::invokeMethod(this, "copyToClipboard", Q_ARG(QString, text)); + return; + } + qDebug() << "Copying"; QApplication::clipboard()->setText(text); } diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 21815e065a..e317f0f250 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -761,11 +762,21 @@ void AddressManager::refreshPreviousLookup() { } void AddressManager::copyAddress() { + if (QThread::currentThread() != qApp->thread()) { + QMetaObject::invokeMethod(this, "copyAddress"); + return; + } + // assume that the address is being copied because the user wants a shareable address QApplication::clipboard()->setText(currentShareableAddress().toString()); } void AddressManager::copyPath() { + if (QThread::currentThread() != qApp->thread()) { + QMetaObject::invokeMethod(this, "copyPath"); + return; + } + QApplication::clipboard()->setText(currentPath()); }