aboutsummaryrefslogtreecommitdiffhomepage
path: root/Main.hs
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-02-28 21:53:04 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-02-28 21:53:04 -0700
commit0f4a73c745602fc2a3f837e7c6e829eff44de68a (patch)
tree9cf389724f2adc9ba5cb07954856f9211c04a49b /Main.hs
parent7ac129947a5ec83e6ab6cd0650c91f3955d09047 (diff)
downloadsscan-0f4a73c745602fc2a3f837e7c6e829eff44de68a.tar.gz
put command into scansess & rework
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs35
1 files changed, 26 insertions, 9 deletions
diff --git a/Main.hs b/Main.hs
index 8838823..d7ac33a 100644
--- a/Main.hs
+++ b/Main.hs
@@ -23,18 +23,18 @@ along with sscan. If not, see <http://www.gnu.org/licenses/>.
{-# LANGUAGE OverloadedStrings #-}
-import Control.Concurrent (forkFinally)
+import Control.Concurrent (forkIO)
import Control.Monad (void)
import Lens.Micro ((&), (.~), (^.))
import System.Directory (getHomeDirectory, removeDirectoryRecursive)
import System.FilePath ((</>))
-import System.IO.Temp (createTempDirectory)
+import System.IO.Temp (withSystemTempDirectory)
import Types.State
import UI
--- processScanSessDir :: ScanSess -> IO ()
--- processScanSessDir ss@(ScanSess d n) =
+processScanSessDir :: St -> IO ()
+processScanSessDir = undefined
-- -- rather than do any error handling here, we write a logfile to
-- -- the outdir for user inspection
-- void $ forkFinally process $ \_ -> nukeScanSessDir ss
@@ -57,14 +57,31 @@ makeInitialState = do
, _stDPI = 300
, _stOutFormat = PDF
, _stOutdir = home </> "tmp"
- , _stCommand = Quit
}
-uiLoop :: St -> IO ()
-uiLoop st = runTheApp st >>= \newSt -> do
- undefined
+scanPage :: FilePath -> IO ()
+scanPage dir = undefined
-main = makeInitialState >>= uiLoop
+processCommand :: St -> IO ()
+processCommand st = case st^.stScanSess of
+ Nothing -> return () -- quit sscan
+ Just (ScanSess command pages maybeDir) -> case maybeDir of
+ Nothing -> withSystemTempDirectory "sscan" $ \dir ->
+ processCommand (setScanSessDir dir st)
+ Just dir -> case command of
+ Abort -> newSession
+ NextPage -> scanPage dir >> presentUI (incrementPages st)
+ FinalPage -> scanPage dir
+ >> finaliseSession (incrementPages st) >> newSession
+ Finalise -> finaliseSession st >> newSession
+ where
+ newSession = presentUI $ resetScanSess st
+ finaliseSession = forkIO . processScanSessDir
+
+presentUI :: St -> IO ()
+presentUI st = runTheApp st >>= processCommand
+
+main = makeInitialState >>= presentUI
-- TODO scanning should happen in main. We use withTempDir to setup a
-- session, and then fire up brick again. add additional state