module Network.URI.XDG(HandlersConfig, loadHandlers, canDispatchMIME, dispatchURIByMIME) where
import Network.URI (URI(..))
import Network.URI.XDG.DesktopEntry
import Network.URI.XDG.MimeApps
canDispatchMIME :: HandlersConfig -> String -> Bool
canDispatchMIME config mime = not $ null $ queryHandlers config mime
dispatchURIByMIME :: [String] -> HandlersConfig -> URI -> String -> IO (Maybe String)
dispatchURIByMIME locales config uri mime =
queryHandlers config mime `mapFirstM` launchApp locales uri
mapFirstM :: [a] -> (a -> IO (Maybe b)) -> IO (Maybe b)
mapFirstM (x:xs) cb = do
item <- cb x
case item of
Just _ -> return item
Nothing -> mapFirstM xs cb
mapFirstM [] _ = return Nothing