packages feed

monomer-flatpak-example-0.0.15.0: app/Util.hs

{-# LANGUAGE QuasiQuotes #-}

module Util
  ( getXdgDataDir,
    osPathToText,
  )
where

import Data.Text (Text, pack)
import GHC.IO.Encoding (utf8)
import System.Directory.OsPath (XdgDirectory (..), createDirectoryIfMissing, getXdgDirectory)
import System.OsPath (OsPath, decodeWith, osp)

getXdgDataDir :: IO OsPath
getXdgDataDir = do
  dir <- getXdgDirectory XdgData [osp|monomer-flatpak-example|]
  createDirectoryIfMissing True dir
  pure dir

osPathToText :: OsPath -> Text
osPathToText path =
  case decodeWith utf8 utf8 path of
    Left err -> pack (show err)
    Right fp -> pack fp