diff --git a/wpigui/src/main/native/cpp/wpigui_openurl.cpp b/wpigui/src/main/native/cpp/wpigui_openurl.cpp new file mode 100644 index 0000000000..b913cebf0e --- /dev/null +++ b/wpigui/src/main/native/cpp/wpigui_openurl.cpp @@ -0,0 +1,28 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include "wpigui_openurl.h" + +#if _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#include +#else +#include +#endif + +void wpi::gui::OpenURL(const std::string& url) { +#ifdef _WIN32 + ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL); +#else +#ifdef __APPLE__ + static constexpr const char* opencmd = "open"; +#else + static constexpr const char* opencmd = "xdg-open"; +#endif + execlp(opencmd, opencmd, url.c_str(), static_cast(nullptr)); +#endif +} diff --git a/wpigui/src/main/native/include/wpigui_openurl.h b/wpigui/src/main/native/include/wpigui_openurl.h new file mode 100644 index 0000000000..5de08283ae --- /dev/null +++ b/wpigui/src/main/native/include/wpigui_openurl.h @@ -0,0 +1,18 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#pragma once + +#include + +namespace wpi::gui { + +/** + * Opens a URL in the default browser. + * + * @param url URL to open + */ +void OpenURL(const std::string& url); + +} // namespace wpi::gui