~alcinnz/hurl

ref: 7239e77a1a2e8cacf2e04e88eaf5da99137d4a22 hurl/src/Network/URI/XDG.hs -rw-r--r-- 723 bytes
7239e77a — Adrian Cochrane Support looking up icons by MIMEtype. 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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