open-browser-0.4.0.0/example/0000755000000000000000000000000014773054217014126 5ustar0000000000000000open-browser-0.4.0.0/lib/0000755000000000000000000000000014765644274013252 5ustar0000000000000000open-browser-0.4.0.0/lib/Web/0000755000000000000000000000000014773054217013756 5ustar0000000000000000open-browser-0.4.0.0/lib/unix-like/0000755000000000000000000000000014773054217015146 5ustar0000000000000000open-browser-0.4.0.0/lib/unix-like/open/0000755000000000000000000000000014765644274016120 5ustar0000000000000000open-browser-0.4.0.0/lib/unix-like/open/Web/0000755000000000000000000000000014765644274016635 5ustar0000000000000000open-browser-0.4.0.0/lib/unix-like/open/Web/Browser/0000755000000000000000000000000014773054217020247 5ustar0000000000000000open-browser-0.4.0.0/lib/unix-like/xdg-open/0000755000000000000000000000000014765644274016700 5ustar0000000000000000open-browser-0.4.0.0/lib/unix-like/xdg-open/Web/0000755000000000000000000000000014765644274017415 5ustar0000000000000000open-browser-0.4.0.0/lib/unix-like/xdg-open/Web/Browser/0000755000000000000000000000000014773054217021027 5ustar0000000000000000open-browser-0.4.0.0/lib/unsupported-os/0000755000000000000000000000000014765644274016261 5ustar0000000000000000open-browser-0.4.0.0/lib/unsupported-os/Web/0000755000000000000000000000000014765644274016776 5ustar0000000000000000open-browser-0.4.0.0/lib/unsupported-os/Web/Browser/0000755000000000000000000000000014773054217020410 5ustar0000000000000000open-browser-0.4.0.0/lib/windows/0000755000000000000000000000000014765644274014744 5ustar0000000000000000open-browser-0.4.0.0/lib/windows/Web/0000755000000000000000000000000014765644274015461 5ustar0000000000000000open-browser-0.4.0.0/lib/windows/Web/Browser/0000755000000000000000000000000014773054217017073 5ustar0000000000000000open-browser-0.4.0.0/lib/Web/Browser.hs0000644000000000000000000000456614773325065015752 0ustar0000000000000000{-# LANGUAGE LambdaCase #-} {-| Module : Web.Browser Description : Open a web browser from Haskell Copyright : (c) rightfold 2015 License : BSD3 Maintainer : public@pilgrem.com Open a web browser from Haskell. Supported operating systems are Windows, macOS, Linux and BSD. -} module Web.Browser ( openBrowser -- * Utilities , openBrowserWithExitCode ) where import Control.Exception ( Exception (..), SomeException, try) import System.Exit ( ExitCode (..) ) import qualified Web.Browser.OS as OS -- | Seeks to open the given item, silently. If the item is a URL or another -- item associated with a web browser (for example, it represents a local -- @.html@ file), seeks to open it in the user's preferred web browser. Returns -- whether or not the operation succeeded. -- -- No checks are performed on the nature or validity of the given item. -- -- Implemented using: -- -- * on Windows, the \'open\' operation provided by the Win32 API. For an item -- that represents a file, equivalent double-clicking on the file's icon; -- -- * on macOS, the \'open\' application, if it is on the user's PATH. For an -- item that represents a file, equivalent to double-clicking on the file's -- icon; and -- -- * on Linux, FreeBSD, OpenBSD or NetBSD, the \'xdg-open\' script, if it -- is on the user's PATH. -- -- On other operating systems, the operation always fails. -- -- @since 0.1.0.0 openBrowser :: String -- ^ URL or other item to try to open. -> IO Bool openBrowser url = tryOpenUrl >>= \case Left _ -> pure False Right (ec, _, _) -> pure $ ec == ExitSuccess where tryOpenUrl :: IO (Either SomeException (ExitCode, String, String)) tryOpenUrl = openBrowserWithExitCode url -- | Exported to help with debugging. As for 'openBrowser' but returns either an -- exception or, as a triple, the 'ExitCode' of the opening mechanism and any -- output to the standard output and standard error channels. On failure, the -- meaning of the exit code will depend on the operating system; for unsupported -- operating systems, it will be 'ExitFailure' @1@. -- -- @since 0.4.0.0 openBrowserWithExitCode :: Exception e => String -- ^ URL or other item to try to open. -> IO (Either e (ExitCode, String, String)) openBrowserWithExitCode url = try $ OS.openBrowserWithExitCode url open-browser-0.4.0.0/lib/windows/Web/Browser/OS.hs0000644000000000000000000000363314773054217017755 0ustar0000000000000000{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# HLINT ignore "Use camelCase" #-} {-# LANGUAGE ForeignFunctionInterface #-} -------------------------------------------------------------------------------- -- For Windows operating systems, making use of the Win32 API. -------------------------------------------------------------------------------- module Web.Browser.OS ( openBrowserWithExitCode ) where import System.Exit ( ExitCode (..) ) import System.Win32.Types ( HANDLE, HINSTANCE, INT, LPCWSTR, handleToWord, nullPtr, withTString ) type HWND = HANDLE -- https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow -- Activates and displays a window. If the window is minimized, maximized, or -- arranged, the system restores it to its original size and position. An -- application should specify this flag when displaying the window for the first -- time. sW_SHOWNORMAL :: INT sW_SHOWNORMAL = 1 openBrowserWithExitCode :: String -- ^ URL or other item to try to open. -> IO (ExitCode, String, String) openBrowserWithExitCode url = withTString "open" $ \openStr -> withTString url $ \urlStr -> exitcodeToExitCode <$> c_ShellExecute nullPtr openStr urlStr nullPtr nullPtr sW_SHOWNORMAL where exitcodeToExitCode hinst = let exitcode = fromIntegral $ handleToWord hinst in (if exitcode > 32 then ExitSuccess else ExitFailure exitcode, "", "") -- https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew foreign import ccall unsafe "windows.h ShellExecuteW" c_ShellExecute :: HWND -- [in, optional] hwnd -> LPCWSTR -- [in, optional] lpOperation -> LPCWSTR -- [in] lpFile -> LPCWSTR -- [in, optional] lpParameters -> LPCWSTR -- [in, optional] lpDirectory -> INT -- [in] nShowCmd -> IO HINSTANCE open-browser-0.4.0.0/lib/unix-like/open/Web/Browser/OS.hs0000644000000000000000000000121514773054217021123 0ustar0000000000000000-------------------------------------------------------------------------------- -- For Unix-like operating systems, such as macOS, that provide the open -- application on the PATH. -------------------------------------------------------------------------------- module Web.Browser.OS ( openBrowserWithExitCode ) where import System.Exit ( ExitCode (..) ) import System.Process ( readProcessWithExitCode ) -- https://ss64.com/mac/open.html openBrowserWithExitCode :: String -- ^ URL or other item to try to open. -> IO (ExitCode, String, String) openBrowserWithExitCode url = readProcessWithExitCode "open" [url] "" open-browser-0.4.0.0/lib/unix-like/xdg-open/Web/Browser/OS.hs0000644000000000000000000000120114773054217021676 0ustar0000000000000000-------------------------------------------------------------------------------- -- For Unix-like operating systems that provide the xdg-open script on the PATH. -------------------------------------------------------------------------------- module Web.Browser.OS ( openBrowserWithExitCode ) where import System.Exit ( ExitCode (..) ) import System.Process ( readProcessWithExitCode ) -- https://ss64.com/bash/xdg-open.html openBrowserWithExitCode :: String -- ^ URL or other item to try to open. -> IO (ExitCode, String, String) openBrowserWithExitCode url = readProcessWithExitCode "xdg-open" [url] "" open-browser-0.4.0.0/lib/unsupported-os/Web/Browser/OS.hs0000644000000000000000000000105614773054217021267 0ustar0000000000000000-------------------------------------------------------------------------------- -- For unsupported operating systems -------------------------------------------------------------------------------- module Web.Browser.OS ( openBrowserWithExitCode ) where import System.Exit ( ExitCode (..) ) openBrowserWithExitCode :: String -- ^ URL or other item to try to open. -> IO (ExitCode, String, String) openBrowserWithExitCode = -- Operation never succeeds const (pure (ExitFailure 1, "", "Unsupported operating system.")) open-browser-0.4.0.0/example/Main.hs0000644000000000000000000000217314773054217015351 0ustar0000000000000000{-# LANGUAGE LambdaCase #-} module Main ( main ) where import Control.Exception ( Exception (..), SomeException ) import System.Exit ( ExitCode (..) ) import Web.Browser ( openBrowser, openBrowserWithExitCode ) main :: IO () main = do openBrowser "https://haskell.org/" >>= \case True -> putStrLn "The operation succeeded!" False -> putStrLn "The operation failed!" blankLine putStrLn "Help with debugging:" putStrLn "Try a good URL:" tryOpenGoodUrl >>= reportResult blankLine putStrLn "Try a bad URL:" tryOpenBadUrl >>= reportResult where tryOpenGoodUrl :: IO (Either SomeException (ExitCode, String, String)) tryOpenGoodUrl = openBrowserWithExitCode "https://haskell.org/" tryOpenBadUrl :: IO (Either SomeException (ExitCode, String, String)) tryOpenBadUrl = openBrowserWithExitCode "example-bad-url" reportResult = \case Left e -> putStrLn $ "Exception: " <> displayException e Right (ec, out, err) -> do putStrLn $ "Exit code: " <> show ec putStrLn $ "Standard output: " <> out putStrLn $ "Standard error: " <> err blankLine = putStrLn "" open-browser-0.4.0.0/CHANGELOG.md0000644000000000000000000000436214773325020014302 0ustar0000000000000000# Changelog for `open-browser` All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). ## 0.4.0.0 - 2025-04-02 * On Unix-like operating systems, use Haskell to silence the opening application or script, rather than the `sh` shell on Linux and BSD. * Add utility `openBrowserWithExitCode`, to help with debugging failure. * Improve Haddock documentation. ## 0.3.0.1 - 2025-03-17 * On Windows, remove unnecessary dependency on `process`. * Improve Haddock documentation. ## 0.3.0.0 - 2025-03-16 * Make operating system-related choices at compilation. The function will never succeed on unsupported operating systems, rather than than throwing an `ErrorCall` exception. * Drop support for 32-bit Windows. ## 0.2.1.1 - 2025-03-15 * Add `CHANGELOG.md` and `README.md`. * Add `stack.yaml` and `stack.yaml.lock` to package description. * Example executable renamed `open-browser-example` (from `example`). * The building of the example executable now requires Cabal flag `example` (default: false). * URL in example executable updated to https://www.haskell.org/. ## 0.2.1.0 - 2016-01-05 * As released by rightfold on Hackage. This entry and prior change log is reconstructed. * Support GHC versions before GHC 8.0, by removing the Byte Order Mark from source files. * Add support for 32-bit Windows, by using the `stdcall` calling convention. ## 0.2.0.0 - 2015-07-31 * Remote deprecated `Network.Browser.openBrowser`. ## 0.1.4.0 - 2015-07-30 * On Linux and BSD, silence the `xdg-open` script using the `sh` shell. ## 0.1.3.0 - 2015-07-27 * Add support for BSD, using the `xdg-open` script. * Add support for Windows, using the Win32 API and the `ccall` calling convention. ## 0.1.2.0 - 2015-07-27 * `Web.Browser.openBrowser` added and `Network.Browser.openBrowser` deprecated. ## 0.1.1.0 - 2015-07-27 * Add support for Linux, using the `xdg-open` script. * On OS X, use the `open` application. ## 0.1.0.0 - 2015-07-25 * Initial version. Only OS X supported, using `open location` in an AppleScript. open-browser-0.4.0.0/README.md0000644000000000000000000000051414766114704013752 0ustar0000000000000000# open-browser A Haskell library that provides the function `openBrowser` that, given a URL or other item associated with a web browser, yields an IO action that seeks to open the item in the user's preferred web browser. Supported operating systems are Windows, macOS, Linux and BSD. Originally developed by rightfold. open-browser-0.4.0.0/stack.yaml0000644000000000000000000000004114773325203014453 0ustar0000000000000000snapshot: lts-23.17 # GHC 9.8.4 open-browser-0.4.0.0/stack.yaml.lock0000644000000000000000000000071014773325210015403 0ustar0000000000000000# This file was autogenerated by Stack. # You should not edit this file by hand. # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/topics/lock_files packages: [] snapshots: - completed: sha256: 2763632e4c4094ce12f5ae12b22f524cdc6453b6b19007ff164a37fd9d2ea829 size: 683819 url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/17.yaml original: lts-23.17 open-browser-0.4.0.0/LICENSE0000644000000000000000000000301214763641705013477 0ustar0000000000000000Copyright (c) 2015, rightfold All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of rightfold nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. open-browser-0.4.0.0/Setup.hs0000644000000000000000000000006014763641705014126 0ustar0000000000000000import Distribution.Simple main = defaultMain open-browser-0.4.0.0/open-browser.cabal0000644000000000000000000000357314773325114016106 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.38.0. -- -- see: https://github.com/sol/hpack name: open-browser version: 0.4.0.0 synopsis: Open a web browser from Haskell description: Open a web browser from Haskell. Windows, macOS, Linux and BSD are supported. category: Web homepage: https://github.com/mpilgrem/open-browser bug-reports: https://github.com/mpilgrem/open-browser/issues author: rightfold maintainer: public@pilgrem.com license: BSD3 license-file: LICENSE build-type: Simple tested-with: GHC >= 8.4 extra-source-files: CHANGELOG.md README.md stack.yaml stack.yaml.lock source-repository head type: git location: https://github.com/mpilgrem/open-browser flag example description: Build the example application manual: True default: False library hs-source-dirs: lib exposed-modules: Web.Browser build-depends: base ==4.* default-language: Haskell2010 if os(windows) other-modules: Web.Browser.OS hs-source-dirs: lib/windows build-depends: Win32 <3 else if os(darwin) other-modules: Web.Browser.OS hs-source-dirs: lib/unix-like/open build-depends: process >=1.2.0.0 && <2 else if os(linux) || os(freebsd) || os(openbsd) || os(netbsd) other-modules: Web.Browser.OS hs-source-dirs: lib/unix-like/xdg-open build-depends: process >=1.2.0.0 && <2 else other-modules: Web.Browser.OS hs-source-dirs: lib/unsupported-os executable open-browser-example main-is: Main.hs hs-source-dirs: example build-depends: base ==4.* , open-browser default-language: Haskell2010 if !flag(example) buildable: False