mirror of
https://github.com/quantum9Innovation/suntheme.git
synced 2024-11-24 17:33:52 -08:00
refactor: create getters module
group helper funcs for creating directory names and fetching network resources into a single module
This commit is contained in:
parent
b9750dafea
commit
13188fe64d
3 changed files with 25 additions and 20 deletions
17
app/Getters.hs
Normal file
17
app/Getters.hs
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Getters where
|
||||
|
||||
import Const (prog)
|
||||
|
||||
import System.FilePath ((</>))
|
||||
import System.Directory (XdgDirectory(XdgCache, XdgConfig), getXdgDirectory)
|
||||
import Control.Exception (SomeException, try)
|
||||
import Network.HTTP.Request (Response, get)
|
||||
|
||||
pathToCache :: String -> IO String
|
||||
pathToCache str = (</> str) <$> getXdgDirectory XdgCache prog
|
||||
|
||||
pathToConfig :: String -> IO String
|
||||
pathToConfig str = (</> str) <$> getXdgDirectory XdgConfig prog
|
||||
|
||||
fetch :: String -> IO (Either SomeException Response)
|
||||
fetch = try . get
|
26
app/Main.hs
26
app/Main.hs
|
@ -7,16 +7,17 @@ module Main where
|
|||
|
||||
import Pure (buildCmd, readLines)
|
||||
import Time (activateOnSunrise, sunriseNow, sunsetNow)
|
||||
import Const (darkModeScript, lightModeScript, prog, query)
|
||||
import Const (darkModeScript, lightModeScript, query)
|
||||
import Sugar (continue, crash, destruct, exec, killall)
|
||||
import Types (ResponseMsg(..), ResponseCode(..), genericErr, toResponseMsg)
|
||||
import Types (ResponseCode(..), ResponseMsg(..), genericErr, toResponseMsg)
|
||||
import Getters (fetch, pathToCache, pathToConfig)
|
||||
|
||||
import Data.List.Extra ((!?))
|
||||
import Data.ByteString.Char8 (unpack)
|
||||
import System.FilePath ((</>), takeDirectory)
|
||||
import System.Directory (XdgDirectory(XdgCache, XdgConfig), createDirectoryIfMissing, doesFileExist, getXdgDirectory)
|
||||
import Control.Exception (SomeException, catch, try)
|
||||
import Network.HTTP.Request (Response(responseBody, responseStatus), get)
|
||||
import System.FilePath (takeDirectory)
|
||||
import System.Directory (createDirectoryIfMissing, doesFileExist)
|
||||
import Control.Exception (SomeException, catch)
|
||||
import Network.HTTP.Request (Response(responseBody, responseStatus))
|
||||
|
||||
-- error handling
|
||||
-- refactor into modules
|
||||
|
@ -25,19 +26,6 @@ import Network.HTTP.Request (Response(responseBody, responseStatus), get)
|
|||
-- introduce liquid types and checking
|
||||
-- whitepaper!
|
||||
|
||||
pathToCache :: String -> IO String
|
||||
pathToCache str = do
|
||||
dir <- getXdgDirectory XdgCache prog
|
||||
return (dir </> str)
|
||||
|
||||
pathToConfig :: String -> IO String
|
||||
pathToConfig str = do
|
||||
dir <- getXdgDirectory XdgConfig prog
|
||||
return (dir </> str)
|
||||
|
||||
fetch :: String -> IO (Either SomeException Response)
|
||||
fetch = try . get
|
||||
|
||||
ping :: (Response -> IO ()) -> IO () -> IO ()
|
||||
ping run err = do
|
||||
res <- fetch query
|
||||
|
|
|
@ -62,7 +62,7 @@ executable suntheme
|
|||
main-is: Main.hs
|
||||
|
||||
-- Modules included in this executable, other than Main.
|
||||
other-modules: Types, Const, Pure, Time, Sugar
|
||||
other-modules: Types, Const, Pure, Time, Sugar, Getters
|
||||
|
||||
-- LANGUAGE extensions used by modules in this package.
|
||||
-- other-extensions:
|
||||
|
|
Loading…
Reference in a new issue