From d11e15acc10026e36d8dc0665be2002821d2579b Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 4 Aug 2020 15:57:39 +0300 Subject: Open HTTP in default browser On macOS and Linux. --- src/app.c | 24 ++++++++++++++++++++++++ src/app.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/app.c b/src/app.c index 36e55970..47c0fce9 100644 --- a/src/app.c +++ b/src/app.c @@ -1,6 +1,7 @@ #include "app.h" #include "embedded.h" #include "gmcerts.h" +#include "gmutil.h" #include "history.h" #include "ui/command.h" #include "ui/window.h" @@ -337,6 +338,13 @@ iBool handleCommand_App(const char *cmd) { iWidget *root = d->window->root; if (equal_Command(cmd, "open")) { const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url"))); + iUrl parts; + init_Url(&parts, url); + if (equalCase_Rangecc(&parts.protocol, "http") || + equalCase_Rangecc(&parts.protocol, "https")) { + openInDefaultBrowser_App(url); + return iTrue; + } if (!argLabel_Command(cmd, "history")) { if (argLabel_Command(cmd, "redirect")) { replace_History(d->history, url); @@ -416,3 +424,19 @@ iBool handleCommand_App(const char *cmd) { } return iTrue; } + +void openInDefaultBrowser_App(const iString *url) { + iProcess *proc = new_Process(); +#if defined (iPlatformApple) + setArguments_Process(proc, + iClob(newStringsCStr_StringList("/usr/bin/open", cstr_String(url), NULL))); + start_Process(proc); +#elif defined(iPlatformLinux) + setArguments_Process(proc, + iClob(newStringsCStr_StringList("/usr/bin/x-www-browser", cstr_String(url), NULL))); + start_Process(proc); +#else + iAssert(iFalse); +#endif + iRelease(proc); +} diff --git a/src/app.h b/src/app.h index 5cb68920..cdfc387d 100644 --- a/src/app.h +++ b/src/app.h @@ -38,3 +38,5 @@ void postCommandf_App (const char *command, ...); iLocalDef void postCommandString_App(const iString *command) { postCommand_App(cstr_String(command)); } + +void openInDefaultBrowser_App (const iString *url); -- cgit v1.2.3