From e7cee21543398234962f8f5cf3a022f3e2c15052 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 6 Nov 2020 07:26:36 +0200 Subject: Link context menu item to bypass proxy IssueID #25 --- src/app.c | 15 +++++++++++++- src/app.h | 1 + src/ui/documentwidget.c | 52 ++++++++++++++++++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 3a86150f..354d34d6 100644 --- a/src/app.c +++ b/src/app.c @@ -880,6 +880,18 @@ static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { return iFalse; } +iBool willUseProxy_App(const iRangecc scheme) { + iApp *d = &app_; + if (!isEmpty_String(&d->prefs.httpProxy) && (equalCase_Rangecc(scheme, "http") || + equalCase_Rangecc(scheme, "https"))) { + return iTrue; + } + if (!isEmpty_String(&d->prefs.gopherProxy) && equalCase_Rangecc(scheme, "gopher")) { + return iTrue; + } + return iFalse; +} + iBool handleCommand_App(const char *cmd) { iApp *d = &app_; if (equal_Command(cmd, "prefs.dialogtab")) { @@ -996,7 +1008,8 @@ iBool handleCommand_App(const char *cmd) { else if (equal_Command(cmd, "proxy.http")) { setCStr_String(&d->prefs.httpProxy, suffixPtr_Command(cmd, "address")); return iTrue; - } else if (equal_Command(cmd, "downloads")) { + } + else if (equal_Command(cmd, "downloads")) { setCStr_String(&d->prefs.downloadDir, suffixPtr_Command(cmd, "path")); return iTrue; } diff --git a/src/app.h b/src/app.h index bf310d98..9c4bb669 100644 --- a/src/app.h +++ b/src/app.h @@ -64,6 +64,7 @@ iBool forceLineWrap_App (void); iBool forceSoftwareRender_App(void); enum iColorTheme colorTheme_App (void); const iString * schemeProxy_App (iRangecc scheme); +iBool willUseProxy_App (const iRangecc scheme); iGmCerts * certs_App (void); iVisited * visited_App (void); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 423dee6d..13f21df6 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1906,20 +1906,44 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e init_Array(&items, sizeof(iMenuItem)); if (d->contextLink) { const iString *linkUrl = linkUrl_GmDocument(d->doc, d->contextLink->linkId); - pushBackN_Array( - &items, - (iMenuItem[]){ - { "Open Link in New Tab", - 0, - 0, - format_CStr("!open newtab:1 url:%s", cstr_String(linkUrl)) }, - { "Open Link in Background Tab", - 0, - 0, - format_CStr("!open newtab:2 url:%s", cstr_String(linkUrl)) }, - { "---", 0, 0, NULL }, - { "Copy Link", 0, 0, "document.copylink" } }, - 4); + const iRangecc scheme = urlScheme_String(linkUrl); + if (willUseProxy_App(scheme) || equalCase_Rangecc(scheme, "gemini")) { + /* Regular Gemini links. */ + pushBackN_Array( + &items, + (iMenuItem[]){ + { "Open Link in New Tab", + 0, + 0, + format_CStr("!open newtab:1 url:%s", cstr_String(linkUrl)) }, + { "Open Link in Background Tab", + 0, + 0, + format_CStr("!open newtab:2 url:%s", cstr_String(linkUrl)) } }, + 2); + } + else if (!willUseProxy_App(scheme)) { + pushBack_Array( + &items, + &(iMenuItem){ "Open Link in Default Browser", + 0, + 0, + format_CStr("!open url:%s", cstr_String(linkUrl)) }); + } + if (willUseProxy_App(scheme)) { + pushBackN_Array(&items, + (iMenuItem[]){ { "---", 0, 0, NULL }, + { "Open Link in Default Browser", + 0, + 0, + format_CStr("!open noproxy:1 url:%s", + cstr_String(linkUrl)) } }, + 2); + } + pushBackN_Array(&items, + (iMenuItem[]){ { "---", 0, 0, NULL }, + { "Copy Link", 0, 0, "document.copylink" } }, + 2); } else { if (!isEmpty_Range(&d->selectMark)) { -- cgit v1.2.3