From 51ed951d7d5d1b6a7082ff59ecdba4fe10169cab Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Wed, 30 Oct 2024 22:54:17 +0000 Subject: [PATCH] Added Platform::openURL to open a URL cross-platform --- .../Interface/Browser/Bridge/Base/OpenUrl.cpp | 6 ++++-- SpeckleLib/Speckle/Environment/Platform.cpp | 16 ++++++++++++++++ SpeckleLib/Speckle/Environment/Platform.h | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Base/OpenUrl.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Base/OpenUrl.cpp index ddfe254..985655a 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Base/OpenUrl.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Base/OpenUrl.cpp @@ -1,6 +1,9 @@ #include "Connector/Interface/Browser/Bridge/Base/OpenUrl.h" +#include "Speckle/Environment/Platform.h" + using namespace connector::interfac::browser::bridge; +using namespace speckle::environment; using namespace speckle::utility; /*-------------------------------------------------------------------- @@ -17,6 +20,5 @@ OpenUrl::OpenUrl() : BridgeMethod{"OpenUrl", [&](const SendArgs& args) { url: The URL to open --------------------------------------------------------------------*/ void OpenUrl::run(const String& url) const { - std::string command = "start " + url; - system(command.c_str()); + platform()->openURL(url); } //OpenUrl::run diff --git a/SpeckleLib/Speckle/Environment/Platform.cpp b/SpeckleLib/Speckle/Environment/Platform.cpp index 9f0cee1..3cc5163 100644 --- a/SpeckleLib/Speckle/Environment/Platform.cpp +++ b/SpeckleLib/Speckle/Environment/Platform.cpp @@ -27,6 +27,22 @@ void Platform::writeToConsole(const active::utility::String& message) { } //Platform::writeToConsole +/*-------------------------------------------------------------------- + Open a URL + + URL: The URL to open + --------------------------------------------------------------------*/ +void Platform::openURL(const active::utility::String& URL) { +#if WINDOWS + std::system((String{"start "} + URL).data()); +#elif __APPLE__ + std::system((String{"open "} + URL).data()); +#elif __linux__ + std::system((String{"xdg-open"} + url).data()); +#endif +} //Platform::openURL + + /*-------------------------------------------------------------------- Get an object representing the parent process/application diff --git a/SpeckleLib/Speckle/Environment/Platform.h b/SpeckleLib/Speckle/Environment/Platform.h index 3014dfb..6c6dacb 100644 --- a/SpeckleLib/Speckle/Environment/Platform.h +++ b/SpeckleLib/Speckle/Environment/Platform.h @@ -18,6 +18,11 @@ namespace speckle::environment { @param message The message to write */ void writeToConsole(const active::utility::String& message); + /*! + Open a URL + @param URL The URL to open + */ + void openURL(const active::utility::String& URL); };