From 7d55b374e4330828fd6ed21a427bd4c5e97aeee1 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 18 Dec 2022 18:14:43 +0300 Subject: [PATCH] Add util::open_url --- libs/util/include/psemek/util/open_url.hpp | 10 +++++++ libs/util/source/open_url.cpp | 32 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 libs/util/include/psemek/util/open_url.hpp create mode 100644 libs/util/source/open_url.cpp 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)); + } + +}