Add util::open_url

This commit is contained in:
Nikita Lisitsa 2022-12-18 18:14:43 +03:00
parent 3d2c03c1b4
commit 7d55b374e4
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,10 @@
#pragma once
#include <string>
namespace psemek::util
{
void open_url(std::string url);
}

View file

@ -0,0 +1,32 @@
#include <psemek/util/open_url.hpp>
#include <cstdlib>
#include <thread>
namespace psemek::util
{
static void ignore(int) {}
static void do_open_url(std::string url)
{
if (!url.starts_with("http"))
url = "https://" + url;
#ifdef WIN32
url = "start " + url;
ignore(std::system(url.data()));
#endif
#ifdef __linux__
url = "xdg-open " + url;
ignore(std::system(url.data()));
#endif
}
void open_url(std::string url)
{
do_open_url(std::move(url));
}
}