Browse Source

redirect plain text requests to default search provider

CPP-GTK4
yggverse 4 months ago
parent
commit
44ceb06db5
  1. 50
      src/app/browser/main/tab/page.cpp

50
src/app/browser/main/tab/page.cpp

@ -193,38 +193,42 @@ void Page::navigation_reload(
G_URI_FLAGS_NONE, G_URI_FLAGS_NONE,
NULL // @TODO GError * NULL // @TODO GError *
); );
// Try auto prepend default scheme on fail // On parse fail
if (uri == NULL) if (uri == NULL)
{ {
uri = g_uri_parse( // Request contain host substring
Glib::ustring::sprintf( if (Glib::Regex::match_simple(
"gemini://%s", R"regex(^[^\/\s]+\.[\w]{2,})regex",
pageNavigation->get_request_text() pageNavigation->get_request_text().c_str()
).c_str(), )) {
G_URI_FLAGS_NONE, // Append default scheme
NULL // @TODO GError * pageNavigation->set_request_text(
); Glib::ustring::sprintf(
"gemini://%s",
// Still not parsed, redirect to search provider pageNavigation->get_request_text()
if (uri == NULL) )
{ );
// @TODO
} }
// URI parsed, redirect // Plain text given, build search request to default provider
else else
{ {
// Redirect to fixed URI
pageNavigation->set_request_text( pageNavigation->set_request_text(
g_uri_to_string( Glib::ustring::sprintf(
uri "gemini://tlgs.one/search?%s", // @TODO settings
) g_uri_escape_string(
); pageNavigation->get_request_text().c_str(),
NULL,
navigation_reload( true
false )
).c_str()
); );
} }
// Redirect @TODO limit attempts
navigation_reload(
false
);
} }
// Reset page data // Reset page data

Loading…
Cancel
Save