refactor:remove gui.hs

This commit is contained in:
Marko Andjelic 2026-01-27 21:38:28 +00:00
commit 83a767968b
2 changed files with 0 additions and 73 deletions

View file

@ -1,66 +0,0 @@
{-# LANGUAGE OverloadedStrings, OverloadedLabels #-}
module Gui (runReader) where
import qualified GI.Gtk as Gtk
import qualified GI.Gio as Gio
import qualified GI.Gdk as Gdk
import qualified GI.WebKit as WebKit
import Data.IORef (newIORef, readIORef, writeIORef)
import Control.Monad.Reader (runReaderT)
import Text.HTML.TagSoup (renderTags)
import EpubParser (EpubEnv, resolveSpine, getChapter)
runReader :: EpubEnv -> IO ()
runReader env = do
app <- Gtk.applicationNew (Just "com.svitak.reader") []
_ <- Gtk.on app #activate $ do
window <- Gtk.applicationWindowNew app
Gtk.windowSetTitle window (Just "Svitak")
Gtk.windowSetDefaultSize window 800 600
-- Web View
webView <- WebKit.webViewNew
Gtk.windowSetChild window (Just webView)
-- Book Data
spine <- runReaderT resolveSpine env
currentChapterIndex <- newIORef 0
let loadChapter index = do
let maxIdx = length spine - 1
-- index to valid range
let safeIdx = max 0 (min index maxIdx)
-- Update state
writeIORef currentChapterIndex safeIdx
let filename = spine !! safeIdx
tags <- runReaderT (getChapter filename) env
WebKit.webViewLoadHtml webView (renderTags tags) (Just "file:///")
loadChapter 0
-- Keyboard Input
keyController <- Gtk.eventControllerKeyNew
Gtk.widgetAddController window keyController
_ <- Gtk.on keyController #keyPressed $ \keyval _ _ -> do
currentIndex <- readIORef currentChapterIndex
case keyval of
Gdk.KEY_Right -> do
loadChapter (currentIndex + 1)
return True
Gdk.KEY_Left -> do
loadChapter (currentIndex - 1)
return True
_ -> return False
#present window
_ <- Gio.applicationRun app Nothing
pure ()

View file

@ -44,12 +44,6 @@ maintainer: oijrewgoijreg@eaoigjoirejg.com
-- copyright:
build-type: Simple
-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README.
extra-doc-files: CHANGELOG.md
-- Extra source files to be distributed with the package, such as examples, or a tutorial module.
-- extra-source-files:
common warnings
ghc-options: -Wall
@ -58,7 +52,6 @@ executable svitak
main-is: Main.hs
other-modules: EpubParser,
Gui,
UI,
Persistence