mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[wpigui] Add OpenURL (#4273)
This function opens a URL using the default browser.
This commit is contained in:
28
wpigui/src/main/native/cpp/wpigui_openurl.cpp
Normal file
28
wpigui/src/main/native/cpp/wpigui_openurl.cpp
Normal file
@@ -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 <Windows.h>
|
||||
#include <shellapi.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#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<const char*>(nullptr));
|
||||
#endif
|
||||
}
|
||||
18
wpigui/src/main/native/include/wpigui_openurl.h
Normal file
18
wpigui/src/main/native/include/wpigui_openurl.h
Normal file
@@ -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 <string>
|
||||
|
||||
namespace wpi::gui {
|
||||
|
||||
/**
|
||||
* Opens a URL in the default browser.
|
||||
*
|
||||
* @param url URL to open
|
||||
*/
|
||||
void OpenURL(const std::string& url);
|
||||
|
||||
} // namespace wpi::gui
|
||||
Reference in New Issue
Block a user