summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-04 15:57:39 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-04 15:57:39 +0300
commitd11e15acc10026e36d8dc0665be2002821d2579b (patch)
treed68b1b75d1a4bb1f2f05dd9f64e3c43e61c0b23f
parent137d5b32a4b8d29e9a9578a1fb47c673290647be (diff)
Open HTTP in default browser
On macOS and Linux.
-rw-r--r--src/app.c24
-rw-r--r--src/app.h2
2 files changed, 26 insertions, 0 deletions
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 @@
1#include "app.h" 1#include "app.h"
2#include "embedded.h" 2#include "embedded.h"
3#include "gmcerts.h" 3#include "gmcerts.h"
4#include "gmutil.h"
4#include "history.h" 5#include "history.h"
5#include "ui/command.h" 6#include "ui/command.h"
6#include "ui/window.h" 7#include "ui/window.h"
@@ -337,6 +338,13 @@ iBool handleCommand_App(const char *cmd) {
337 iWidget *root = d->window->root; 338 iWidget *root = d->window->root;
338 if (equal_Command(cmd, "open")) { 339 if (equal_Command(cmd, "open")) {
339 const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url"))); 340 const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url")));
341 iUrl parts;
342 init_Url(&parts, url);
343 if (equalCase_Rangecc(&parts.protocol, "http") ||
344 equalCase_Rangecc(&parts.protocol, "https")) {
345 openInDefaultBrowser_App(url);
346 return iTrue;
347 }
340 if (!argLabel_Command(cmd, "history")) { 348 if (!argLabel_Command(cmd, "history")) {
341 if (argLabel_Command(cmd, "redirect")) { 349 if (argLabel_Command(cmd, "redirect")) {
342 replace_History(d->history, url); 350 replace_History(d->history, url);
@@ -416,3 +424,19 @@ iBool handleCommand_App(const char *cmd) {
416 } 424 }
417 return iTrue; 425 return iTrue;
418} 426}
427
428void openInDefaultBrowser_App(const iString *url) {
429 iProcess *proc = new_Process();
430#if defined (iPlatformApple)
431 setArguments_Process(proc,
432 iClob(newStringsCStr_StringList("/usr/bin/open", cstr_String(url), NULL)));
433 start_Process(proc);
434#elif defined(iPlatformLinux)
435 setArguments_Process(proc,
436 iClob(newStringsCStr_StringList("/usr/bin/x-www-browser", cstr_String(url), NULL)));
437 start_Process(proc);
438#else
439 iAssert(iFalse);
440#endif
441 iRelease(proc);
442}
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, ...);
38iLocalDef void postCommandString_App(const iString *command) { 38iLocalDef void postCommandString_App(const iString *command) {
39 postCommand_App(cstr_String(command)); 39 postCommand_App(cstr_String(command));
40} 40}
41
42void openInDefaultBrowser_App (const iString *url);