diff --git a/libs/util/include/psemek/util/open_url.hpp b/libs/util/include/psemek/util/open_url.hpp new file mode 100644 index 00000000..34196746 --- /dev/null +++ b/libs/util/include/psemek/util/open_url.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace psemek::util +{ + + void open_url(std::string url); + +} diff --git a/libs/util/source/open_url.cpp b/libs/util/source/open_url.cpp new file mode 100644 index 00000000..fb0b3732 --- /dev/null +++ b/libs/util/source/open_url.cpp @@ -0,0 +1,32 @@ +#include + +#include +#include + +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)); + } + +}