packages feed

open-browser 0.1.2.0 → 0.1.3.0

raw patch · 3 files changed

+49/−6 lines, 3 filesdep +Win32PVP ok

version bump matches the API change (PVP)

Dependencies added: Win32

API changes (from Hackage documentation)

Files

lib/Web/Browser.hs view
@@ -1,16 +1,25 @@+{-# 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-    | "linux"  `isInfixOf` os = openBrowserLinux-    | "darwin" `isInfixOf` os = openBrowserOSX-    | otherwise               = error "unsupported platform"+    | any (`isInfixOf` os) ["linux", "bsd"] = openBrowserLinux+    | "darwin"  `isInfixOf` os              = openBrowserOSX+    | otherwise                             = error "unsupported platform"+#endif
+ lib/Web/Browser/Windows.hs view
@@ -0,0 +1,30 @@+{-# 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 ccall "ShellExecuteW"+    c_ShellExecute :: HANDLE  -- _In_opt_+                   -> LPCTSTR -- _In_opt_+                   -> LPCTSTR -- _In_+                   -> LPCTSTR -- _In_opt_+                   -> LPCTSTR -- _In_opt_+                   -> INT     -- _In_+                   -> IO (HINSTANCE)
open-browser.cabal view
@@ -1,8 +1,8 @@ name:                       open-browser-version:                    0.1.2.0+version:                    0.1.3.0 synopsis:                   Open a web browser from Haskell. description:                Open a web browser from Haskell.-                            Currently only Linux and OS X are supported.+                            Currently BSD, Linux, OS X and Windows are supported. license:                    BSD3 license-file:               LICENSE author:                     rightfold@@ -18,10 +18,14 @@  library     exposed-modules:        Network.Browser, Web.Browser-    other-modules:          Web.Browser.Linux, Web.Browser.OSX+    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  executable example     main-is:                Main.hs