diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-04 15:57:39 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-04 15:57:39 +0300 |
commit | d11e15acc10026e36d8dc0665be2002821d2579b (patch) | |
tree | d68b1b75d1a4bb1f2f05dd9f64e3c43e61c0b23f | |
parent | 137d5b32a4b8d29e9a9578a1fb47c673290647be (diff) |
Open HTTP in default browser
On macOS and Linux.
-rw-r--r-- | src/app.c | 24 | ||||
-rw-r--r-- | src/app.h | 2 |
2 files changed, 26 insertions, 0 deletions
@@ -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 | |||
428 | void 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 | } | ||
@@ -38,3 +38,5 @@ void postCommandf_App (const char *command, ...); | |||
38 | iLocalDef void postCommandString_App(const iString *command) { | 38 | iLocalDef void postCommandString_App(const iString *command) { |
39 | postCommand_App(cstr_String(command)); | 39 | postCommand_App(cstr_String(command)); |
40 | } | 40 | } |
41 | |||
42 | void openInDefaultBrowser_App (const iString *url); | ||