tUse system web browser to open URLs on Mac - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 187d33f098152ae37fcd70ff1bec45f4c2bb8b60
 (DIR) parent 4f094716ada1246cf9fb320593932bcd68526cd3
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Sun, 15 Nov 2020 01:26:56 -0800
       
       Use system web browser to open URLs on Mac
       
       Ignore the WebBrowser config file parameter on Mac;
       instead, use the system's default web browser. Closes #51.
       
       Diffstat:
         M ChangeLog                           |       2 +-
         M configure.ac                        |       4 ++++
         M doc/configfile.html                 |       3 ++-
         M src/Makefile.am                     |       8 +++++++-
         M src/gtkport/gtkport.c               |       8 +++++++-
         A src/mac_helpers.h                   |      33 +++++++++++++++++++++++++++++++
         A src/mac_helpers.m                   |      35 +++++++++++++++++++++++++++++++
       
       7 files changed, 89 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/ChangeLog b/ChangeLog
       t@@ -15,7 +15,7 @@ SVN
              variable instead, as per
              https://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Environment)
            - The default web browser on Linux has changed from 'mozilla' to
       -      'firefox'.
       +      'firefox'; on Mac the system-configured default browser is used.
            - Add sound support on Mac.
            - Add 64-bit Windows binaries.
            - Fix for a DOS against the server using the REQUESTJET message type
 (DIR) diff --git a/configure.ac b/configure.ac
       t@@ -59,10 +59,14 @@ AC_ARG_WITH(sdl,
        [ USE_SDL="$withval" ], [ USE_SDL="probe" ])
        
        if test "$host_vendor" = "apple" ; then
       +  APPLE=yes
       +  AC_DEFINE(APPLE, 1, [Are we building on an Apple Mac?])
          default_cocoa="yes"
        else
       +  APPLE=no
          default_cocoa="no"
        fi
       +AM_CONDITIONAL(APPLE, test "$APPLE" = "yes")
        
        AC_ARG_WITH(cocoa,
        [  --without-cocoa         do not support Cocoa (Mac) sound output],
 (DIR) diff --git a/doc/configfile.html b/doc/configfile.html
       t@@ -185,7 +185,8 @@ foreground. Only supported on Unix systems.</dd>
        <dt><b>WebBrowser=<i>/usr/bin/firefox</i></b></dt>
        <dd>Sets the program used to display website URLs. This is used only by the
        Unix version, as under Windows the standard mechanism for associating file
       -types with applications is used.</dd>
       +types with applications is used, and on MacOS the system-configured default
       +web browser is used.</dd>
        
        <dt><b>ConfigVerbose=<i>FALSE</i></b></dt>
        <dd>Prints extra feedback information when processing the config. file if set
 (DIR) diff --git a/src/Makefile.am b/src/Makefile.am
       t@@ -5,7 +5,6 @@ MYLINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD)
        else
        MYLINK = $(CCLD)
        endif
       -LINK = $(MYLINK) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
        
        if GUI_CLIENT
        GUISUBDIR = gui_client
       t@@ -32,6 +31,13 @@ dopewars_SOURCES = admin.c admin.h AIPlayer.c AIPlayer.h util.c util.h \
                           serverside.c serverside.h sound.c sound.h \
                           tstring.c tstring.h winmain.c winmain.h
        AM_CPPFLAGS= -I../intl -I${srcdir} -I.. @GLIB_CFLAGS@ @GTK_CFLAGS@ @LIBCURL_CPPFLAGS@
       +if APPLE
       +dopewars_SOURCES += mac_helpers.m
       +MACLDFLAGS = -framework AppKit
       +else
       +MACLDFLAGS =
       +endif
       +LINK = $(MYLINK) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) $(MACLDFLAGS) -o $@
        DEFS       = @DEFS@
        PIXDIR     = ${DESTDIR}${datadir}/pixmaps
        DOPEDIR    = ${DESTDIR}${bindir}
 (DIR) diff --git a/src/gtkport/gtkport.c b/src/gtkport/gtkport.c
       t@@ -41,6 +41,10 @@
        #include "gtkport.h"
        #include "nls.h"
        
       +#ifdef APPLE
       +#include "mac_helpers.h"
       +#endif
       +
        #if CYGWIN
        #include "unicodewrap.h"
        const gchar *GTK_STOCK_OK = N_("_OK");
       t@@ -5641,7 +5645,9 @@ static void gtk_url_set_cursor(GtkWidget *widget, GtkWidget *label)
        
        void DisplayHTML(GtkWidget *parent, const gchar *bin, const gchar *target)
        {
       -#ifdef HAVE_FORK
       +#ifdef APPLE
       +  mac_open_url(target);
       +#elif defined(HAVE_FORK)
          char *args[3];
          pid_t pid;
          int status;
 (DIR) diff --git a/src/mac_helpers.h b/src/mac_helpers.h
       t@@ -0,0 +1,33 @@
       +/************************************************************************
       + * mac_helpers.h  Helper functions for Mac builds                       *
       + * Copyright (C)  1998-2020  Ben Webb                                   *
       + *                Email: benwebb@users.sf.net                           *
       + *                WWW: https://dopewars.sourceforge.io/                 *
       + *                                                                      *
       + * This program is free software; you can redistribute it and/or        *
       + * modify it under the terms of the GNU General Public License          *
       + * as published by the Free Software Foundation; either version 2       *
       + * of the License, or (at your option) any later version.               *
       + *                                                                      *
       + * This program is distributed in the hope that it will be useful,      *
       + * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
       + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
       + * GNU General Public License for more details.                         *
       + *                                                                      *
       + * You should have received a copy of the GNU General Public License    *
       + * along with this program; if not, write to the Free Software          *
       + * Foundation, Inc., 59 Temple Place - Suite 330, Boston,               *
       + *                   MA  02111-1307, USA.                               *
       + ************************************************************************/
       +
       +#ifndef __DP_MAC_HELPERS_H__
       +#define __DP_MAC_HELPERS_H__
       +
       +#ifdef HAVE_CONFIG_H
       +#include <config.h>
       +#endif
       +
       +/* Open the given URL using the system-configured web browser */
       +void mac_open_url(const char *url);
       +
       +#endif /* __DP_MAC_HELPERS_H__ */
 (DIR) diff --git a/src/mac_helpers.m b/src/mac_helpers.m
       t@@ -0,0 +1,35 @@
       +/************************************************************************
       + * mac_helpers.m  Helper functions for Mac builds                       *
       + * Copyright (C)  1998-2020  Ben Webb                                   *
       + *                Email: benwebb@users.sf.net                           *
       + *                WWW: https://dopewars.sourceforge.io/                 *
       + *                                                                      *
       + * This program is free software; you can redistribute it and/or        *
       + * modify it under the terms of the GNU General Public License          *
       + * as published by the Free Software Foundation; either version 2       *
       + * of the License, or (at your option) any later version.               *
       + *                                                                      *
       + * This program is distributed in the hope that it will be useful,      *
       + * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
       + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
       + * GNU General Public License for more details.                         *
       + *                                                                      *
       + * You should have received a copy of the GNU General Public License    *
       + * along with this program; if not, write to the Free Software          *
       + * Foundation, Inc., 59 Temple Place - Suite 330, Boston,               *
       + *                   MA  02111-1307, USA.                               *
       + ************************************************************************/
       +
       +#ifdef HAVE_CONFIG_H
       +#include <config.h>
       +#endif
       +
       +#import <AppKit/AppKit.h>
       +
       +#include "mac_helpers.h"
       +
       +void mac_open_url(const char *url)
       +{
       +  NSString *urlstr = [[NSString alloc] initWithUTF8String:url];
       +  [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlstr]];
       +}