r468 - trunk
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Jan 25 02:08:25 EST 2008
Author: icculus
Date: 2008-01-25 02:08:25 -0500 (Fri, 25 Jan 2008)
New Revision: 468
Modified:
trunk/docs.txt
trunk/lua_glue.c
trunk/mojosetup.c
trunk/platform.h
trunk/platform_unix.c
trunk/platform_windows.c
Log:
Support for launching a web browser.
Modified: trunk/docs.txt
===================================================================
--- trunk/docs.txt 2008-01-25 06:24:21 UTC (rev 467)
+++ trunk/docs.txt 2008-01-25 07:08:25 UTC (rev 468)
@@ -848,6 +848,19 @@
Write debug info to the installation log, if logging settings permit.
+ MojoSetup.launchbrowser(url)
+
+ Launch a web browser to view the URL (url). This will try to launch a
+ new window/tab of the user's preferred handler for the url. Launching
+ "http://" URLs are probably always safe, other protocols, like "ftp://"
+ may or may not work, depending on what the platform offers.
+
+ Returns true if the browser launched, false otherwise. We can't know
+ if the URL actually loaded or rendered, just if the browser launched.
+ The hope is that the browser will inform the user if there's a problem
+ loading the URL.
+
+
MojoSetup.msgbox(title, str)
Show (str) to the user with a GUI message box, and wait until they click
Modified: trunk/lua_glue.c
===================================================================
--- trunk/lua_glue.c 2008-01-25 06:24:21 UTC (rev 467)
+++ trunk/lua_glue.c 2008-01-25 07:08:25 UTC (rev 468)
@@ -596,11 +596,17 @@
static int luahook_ticks(lua_State *L)
{
- lua_pushnumber(L, MojoPlatform_ticks());
- return 1;
+ return retvalNumber(L, MojoPlatform_ticks());
} // luahook_ticks
+static int luahook_launchbrowser(lua_State *L)
+{
+ const char *url = luaL_checkstring(L, 1);
+ return retvalBoolean(L, MojoPlatform_launchBrowser(url));
+} // luahook_launchbrowser
+
+
static int luahook_msgbox(lua_State *L)
{
if (GGui != NULL)
@@ -1592,6 +1598,7 @@
set_cfunc(luaState, luahook_ticks, "ticks");
set_cfunc(luaState, luahook_format, "format");
set_cfunc(luaState, luahook_fatal, "fatal");
+ set_cfunc(luaState, luahook_launchbrowser, "launchbrowser");
set_cfunc(luaState, luahook_msgbox, "msgbox");
set_cfunc(luaState, luahook_promptyn, "promptyn");
set_cfunc(luaState, luahook_promptynan, "promptynan");
Modified: trunk/mojosetup.c
===================================================================
--- trunk/mojosetup.c 2008-01-25 06:24:21 UTC (rev 467)
+++ trunk/mojosetup.c 2008-01-25 07:08:25 UTC (rev 468)
@@ -14,6 +14,9 @@
#include "lua_glue.h"
#include "fileio.h"
+#define TEST_LAUNCH_BROWSER_CODE 0
+int MojoSetup_testLaunchBrowserCode(int argc, char **argv);
+
#define TEST_ARCHIVE_CODE 0
int MojoSetup_testArchiveCode(int argc, char **argv);
@@ -717,6 +720,10 @@
return 0;
} // if
+ #if TEST_LAUNCH_BROWSER_CODE
+ return MojoSetup_testLaunchBrowserCode(argc, argv);
+ #endif
+
#if TEST_ARCHIVE_CODE
return MojoSetup_testArchiveCode(argc, argv);
#endif
@@ -738,6 +745,19 @@
+#if TEST_LAUNCH_BROWSER_CODE
+int MojoSetup_testLaunchBrowserCode(int argc, char **argv)
+{
+ int i;
+ printf("Testing browser launching code...\n\n");
+ for (i = 1; i < argc; i++)
+ {
+ const boolean rc = MojoPlatform_launchBrowser(argv[i]);
+ printf("Launch '%s': %s\n", argv[i], rc ? "success" : "failure");
+ } // for
+ return 0;
+} // MojoSetup_testLaunchBrowserCode
+#endif
#if TEST_ARCHIVE_CODE
Modified: trunk/platform.h
===================================================================
--- trunk/platform.h 2008-01-25 06:24:21 UTC (rev 467)
+++ trunk/platform.h 2008-01-25 07:08:25 UTC (rev 468)
@@ -225,6 +225,12 @@
void *MojoPlatform_dlsym(void *lib, const char *sym);
void MojoPlatform_dlclose(void *lib);
+// Launch the user's preferred browser to view the URL (url).
+// Returns true if the browser launched, false otherwise. We can't know
+// if the URL actually loaded, just if the browser launched. The hope is that
+// the browser will inform the user if there's a problem loading the URL.
+boolean MojoPlatform_launchBrowser(const char *url);
+
#if !SUPPORT_MULTIARCH
#define MojoPlatform_switchBin(img, len)
#else
Modified: trunk/platform_unix.c
===================================================================
--- trunk/platform_unix.c 2008-01-25 06:24:21 UTC (rev 467)
+++ trunk/platform_unix.c 2008-01-25 07:08:25 UTC (rev 468)
@@ -932,6 +932,20 @@
} // MojoPlatform_dlclose
+boolean MojoPlatform_launchBrowser(const char *url)
+{
+#if PLATFORM_MACOSX
+ CFURLRef cfurl = CFURLCreateWithBytes(NULL, (const UInt8 *) url,
+ strlen(url), kCFStringEncodingUTF8, NULL);
+ const OSStatus err = LSOpenCFURLRef(cfurl, NULL);
+ CFRelease(cfurl);
+ return (err == noErr);
+#else
+ return false; // !!! FIXME: write me.
+#endif
+} // MojoPlatform_launchBrowser
+
+
#if SUPPORT_MULTIARCH
void MojoPlatform_switchBin(const uint8 *img, size_t len)
{
Modified: trunk/platform_windows.c
===================================================================
--- trunk/platform_windows.c 2008-01-25 06:24:21 UTC (rev 467)
+++ trunk/platform_windows.c 2008-01-25 07:08:25 UTC (rev 468)
@@ -635,6 +635,15 @@
} // MojoPlatform_istty
+boolean MojoPlatform_launchBrowser(const char *url)
+{
+ // msdn says:
+ // "Returns a value greater than 32 if successful, or an error value that
+ // is less than or equal to 32 otherwise."
+ return (ShellExecuteA(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL) > 32);
+} // MojoPlatform_launchBrowser
+
+
void MojoPlatform_spawnTerminal(void)
{
// unsupported.
More information about the mojosetup-commits
mailing list