open-browser-0.2.1.0/0000755000000000000000000000000012642677742012501 5ustar0000000000000000open-browser-0.2.1.0/LICENSE0000644000000000000000000000275412642677742013516 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.2.1.0/open-browser.cabal0000644000000000000000000000277112642677742016116 0ustar0000000000000000name: open-browser version: 0.2.1.0 synopsis: Open a web browser from Haskell. description: Open a web browser from Haskell. Currently BSD, Linux, OS X and Windows are supported. license: BSD3 license-file: LICENSE author: rightfold homepage: https://github.com/rightfold/open-browser maintainer: rightfold@gmail.com bug-reports: https://github.com/rightfold/open-browser/issues category: Web build-type: Simple cabal-version: >=1.10 tested-with: GHC >= 7.6 source-repository head type: git location: https://github.com/rightfold/open-browser.git library exposed-modules: Web.Browser other-modules: Web.Browser.Linux, Web.Browser.OSX hs-source-dirs: lib default-language: Haskell2010 build-depends: base >= 4 && < 5, process >= 1 && < 2 if os(windows) build-depends: Win32 other-modules: Web.Browser.Windows if arch(i386) cpp-options: "-DWINDOWS_CCONV=stdcall" else cpp-options: "-DWINDOWS_CCONV=ccall" executable example main-is: Main.hs hs-source-dirs: example default-language: Haskell2010 build-depends: base >= 4 && < 5, open-browser open-browser-0.2.1.0/Setup.hs0000644000000000000000000000005612642677742014136 0ustar0000000000000000import Distribution.Simple main = defaultMain open-browser-0.2.1.0/lib/0000755000000000000000000000000012642677742013247 5ustar0000000000000000open-browser-0.2.1.0/lib/Web/0000755000000000000000000000000012642677742013764 5ustar0000000000000000open-browser-0.2.1.0/lib/Web/Browser.hs0000644000000000000000000000133012642677742015740 0ustar0000000000000000{-# LANGUAGE CPP #-} module Web.Browser ( openBrowser ) where #if defined(mingw32_HOST_OS) import Web.Browser.Windows (openBrowserWindows) #else import Data.List (isInfixOf) import System.Info (os) import Web.Browser.Linux (openBrowserLinux) import Web.Browser.OSX (openBrowserOSX) #endif -- |'openBrowser' opens a URL in the user's preferred web browser. Returns -- whether or not the operation succeeded. openBrowser :: String -> IO Bool #if defined(mingw32_HOST_OS) openBrowser = openBrowserWindows #else openBrowser | any (`isInfixOf` os) ["linux", "bsd"] = openBrowserLinux | "darwin" `isInfixOf` os = openBrowserOSX | otherwise = error "unsupported platform" #endif open-browser-0.2.1.0/lib/Web/Browser/0000755000000000000000000000000012642677742015407 5ustar0000000000000000open-browser-0.2.1.0/lib/Web/Browser/Linux.hs0000644000000000000000000000063712642677742017050 0ustar0000000000000000module Web.Browser.Linux ( openBrowserLinux ) where import System.Exit (ExitCode(..)) import System.Process (rawSystem) 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 open-browser-0.2.1.0/lib/Web/Browser/OSX.hs0000644000000000000000000000055712642677742016423 0ustar0000000000000000module Web.Browser.OSX ( openBrowserOSX ) where import System.Exit (ExitCode(..)) import System.Process (rawSystem) openBrowserOSX :: String -> IO Bool openBrowserOSX url = exitCodeToBool `fmap` rawSystem executable argv where (executable, argv) = ("open", [url]) exitCodeToBool ExitSuccess = True exitCodeToBool (ExitFailure _) = False open-browser-0.2.1.0/lib/Web/Browser/Windows.hs0000644000000000000000000000236412642677742017402 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE ForeignFunctionInterface #-} module Web.Browser.Windows ( openBrowserWindows ) where import System.Win32.Types (INT, HANDLE, HINSTANCE, LPCTSTR, handleToWord, nullPtr, withTString) openBrowserWindows :: String -> IO Bool openBrowserWindows url = withTString "open" $ \openStr -> withTString url $ \urlStr -> exitCodeToBool `fmap` c_ShellExecute nullPtr openStr urlStr nullPtr nullPtr 1 where exitCodeToBool hinst | handleToWord hinst > 32 = True | otherwise = False -- https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx foreign import WINDOWS_CCONV unsafe "windows.h ShellExecuteW" c_ShellExecute :: HANDLE -- _In_opt_ -> LPCTSTR -- _In_opt_ -> LPCTSTR -- _In_ -> LPCTSTR -- _In_opt_ -> LPCTSTR -- _In_opt_ -> INT -- _In_ -> IO HINSTANCE open-browser-0.2.1.0/example/0000755000000000000000000000000012642677742014134 5ustar0000000000000000open-browser-0.2.1.0/example/Main.hs0000644000000000000000000000017712642677742015361 0ustar0000000000000000module Main ( main ) where import Web.Browser (openBrowser) main :: IO () main = openBrowser "http://haskell.org/" >>= print