--------------------------------------------------------------------------------

-- For Unix-like operating systems that provide the xdg-open script on the PATH.

--------------------------------------------------------------------------------


module Web.Browser.OS
  ( openBrowser
  ) where

import           Control.Monad ( void )
import           System.Process
                   ( CreateProcess (..), StdStream (..), createProcess, proc )

-- https://ss64.com/bash/xdg-open.html

openBrowser ::
     String
     -- ^ URL or other item to try to open.

  -> IO ()
openBrowser :: String -> IO ()
openBrowser String
url = IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
 -> IO ())
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
-> IO ()
forall a b. (a -> b) -> a -> b
$ CreateProcess
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess (String -> [String] -> CreateProcess
proc String
"xdg-open" [String
url])
  { std_in = NoStream
  , std_out = NoStream
  , std_err = NoStream
  , close_fds = True
  }