commit 8a6cbead7ed2307a8a83946dcdecec19daff36f1
parent eed11a1a793d285f9cf8274fb98f3173b4657d02
Author: Andrew Laack <andrew@laack.co>
Date: Tue, 22 Sep 2026 21:25:35 -0500
Added opening urls for non-gemini protocl links (like http)
Diffstat:
4 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/include/utils.hpp b/include/utils.hpp
@@ -13,3 +13,4 @@ std::vector<std::string> stringToList(std::string input);
Line* lineToLine(std::string input, std::optional<uri> prior, int linkCount);
std::string urlEncode(const std::string& value);
std::string getNewTab();
+void openUrl(const std::string& url);
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -1,8 +1,10 @@
#include "../include/browser.hpp"
+#include <unistd.h>
#include "../include/site.hpp"
#include "../include/gemini-client.hpp"
#include "../include/utils.hpp"
#include <cstddef>
+#include <cstdlib>
#include <optional>
#include <utility>
#include <vector>
@@ -141,13 +143,16 @@ std::optional<uri> Browser::getPriorUri() {
}
void Browser::followLinkNumber(int linkToFollow) {
-
if(links.size() > linkToFollow-1 && linkToFollow-1 > 0) {
std::size_t pos = links[linkToFollow-1];
if(lines.size() > pos && pos > 0) {
Line* ptr = lines[pos];
Link* ptrLnk = dynamic_cast<Link*>(ptr);
- goToSite(ptrLnk->getLinkDestination().to_string(), true);
+ if(ptrLnk->getLinkDestination().to_string().find("gemini://") == -1) {
+ openUrl(ptrLnk->getLinkDestination().to_string());
+ } else {
+ goToSite(ptrLnk->getLinkDestination().to_string(), true);
+ }
}
}
diff --git a/src/main.cpp b/src/main.cpp
@@ -300,6 +300,9 @@ int main(int argc, char** argv) {
b.followLinkNumber(std::stoi(locationToGo));
} catch (...) {
if(locationToGo != "") {
+ if(locationToGo.find("gemini://") == -1) {
+ locationToGo = "gemini://" + locationToGo;
+ }
b.goToSite(locationToGo, true);
}
}
diff --git a/src/utils.cpp b/src/utils.cpp
@@ -10,6 +10,18 @@
#include <sstream>
#include <string>
#include <vector>
+#include <spawn.h>
+#include <sys/wait.h>
+
+extern char** environ;
+
+void openUrl(const std::string& url) {
+ pid_t pid;
+ char* argv[] = {(char*)"xdg-open", (char*)url.c_str(), nullptr};
+ if (posix_spawnp(&pid, "xdg-open", nullptr, nullptr, argv, environ) == 0) {
+ waitpid(pid, nullptr, 0);
+ }
+}
bool isPrefixed(std::string input, std::string prefix) {
return std::string(input).find(prefix) == 0;