on 63c7b21 help sign in
22 lines 782 B history raw
1module Obelisk.ExecutableConfig (get) where
3import Control.Exception
4import Control.Monad
5import Control.Monad.Trans.Maybe
6import Data.ByteString as BS
7import Data.Text (Text)
8import qualified Data.Text as T
9import qualified Data.Text.IO as T
10import qualified Data.Text.Encoding as T
11import Language.Javascript.JSaddle.WKWebView
12import System.FilePath.Posix ((</>))
13import System.IO.Error
15get :: Text -> IO (Maybe Text)
16get name = fmap join $ mainBundleResourcePath >>= \mp -> forM mp $ \p ->
17 catchDoesNotExist $ T.readFile $ T.unpack (T.decodeUtf8 p) </> T.unpack name
19catchDoesNotExist :: IO a -> IO (Maybe a)
20catchDoesNotExist f = catchJust doesNotExist (Just <$> f) $ const $ return Nothing
21 where
22 doesNotExist e = if isDoesNotExistError e then Just () else Nothing