Add util::open_url
This commit is contained in:
parent
3d2c03c1b4
commit
7d55b374e4
2 changed files with 42 additions and 0 deletions
10
libs/util/include/psemek/util/open_url.hpp
Normal file
10
libs/util/include/psemek/util/open_url.hpp
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace psemek::util
|
||||||
|
{
|
||||||
|
|
||||||
|
void open_url(std::string url);
|
||||||
|
|
||||||
|
}
|
||||||
32
libs/util/source/open_url.cpp
Normal file
32
libs/util/source/open_url.cpp
Normal 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue