skip to Main Content

I modified the first example in https://hackage.haskell.org/package/svg-builder with the following 2 little changes:

  1. Additional imports:
import Data.Text
import qualified Data.Text.Lazy.IO as TLIO
import Web.Browser(openBrowser)
  1. New main program that writes the svg data to a file and then opens the browser with this file:
main = do
  TLIO.writeFile "test.svg" $ renderText $ svg contents
  openBrowser "test.svg" >>= print

The openBrowser comes from https://hackage.haskell.org/package/open-browser

When I run this program, my Debian (11.6) opens the Gimp program and not the browser.
When I double click on the written file in Nautilus, then the browser opens.

Where and what do I have to tweak, so that the Haskell program also opens the browser?

2

Answers


  1. Chosen as BEST ANSWER

    After reading about the xdg-mime command I did:

    xdg-mime default firefox-esr.desktop image/svg+xml 
    

    and this solves the issue for the moment.


  2. Looking at the code for the Browser library you’re using, (at the time of writing):

    openBrowserLinux :: String -> IO Bool
    openBrowserLinux url = exitCodeToBool `fmap` rawSystem executable argv
        where (executable, argv) = ("sh", ["-c", "xdg-open "$0" 2>&1 > /dev/null", url])
              exitCodeToBool ExitSuccess     = True
              exitCodeToBool (ExitFailure _) = False
    

    It is calling out to xdg-open which according to the man page for xdg-open:

    xdg-open opens a file or URL in the user’s preferred application. If a URL is provided the URL will be opened in the user’s preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.

    To get this working on your system, you’ll need to update the default program that handles svg files to be your preferred browser.


    Getting this working in general is probably a larger task since the issue seems to be with the implementation in the library itself. You might want to bring it up with the library’s maintainers or consider looking for another library.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search