Added Platform::openURL to open a URL cross-platform

This commit is contained in:
Ralph Wessel
2024-10-30 22:54:17 +00:00
parent cc6c884f47
commit 51ed951d7d
3 changed files with 25 additions and 2 deletions
@@ -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
@@ -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
@@ -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);
};