Desktop OpenURL Loonix

This commit is contained in:
2025-06-23 14:20:12 -04:00
parent 37a919be15
commit 29c3125614
2 changed files with 26 additions and 0 deletions

24
include/Desktop.hpp Normal file
View File

@@ -0,0 +1,24 @@
//
// Created by maxine on 6/23/25.
//
#pragma once
#include <regex>
#include <cstdlib>
namespace Desktop::Browser {
const std::regex URLPattern("((http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~#?&//=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)");
int OpenURL(std::string url) {
if (url.empty())
throw std::invalid_argument("No url provided");
if(!regex_match(url, URLPattern))
throw std::invalid_argument("Invalid url");
std::string cmd = "xdg-open " + url;
return std::system(cmd.c_str());
}
}

View File

@@ -1,4 +1,5 @@
#include <Logging.hpp>
#include <Desktop.hpp>
int main() {
Mutil::Logging::LoggerObj lo;
@@ -13,4 +14,5 @@ int main() {
D("Something...");
std::cout << (char)0x1b << (char)0x5b << "33m" << "BULLOCKS" << '\n';
//std::cout << 0x1b5b << "33m" << "BALLS" << '\n';
Desktop::Browser::OpenURL("https://git.redacted.cc/maxine/mutil");
}