Desktop OpenURL Loonix
This commit is contained in:
24
include/Desktop.hpp
Normal file
24
include/Desktop.hpp
Normal 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());
|
||||
}
|
||||
}
|
2
main.cpp
2
main.cpp
@@ -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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user