diff --git a/app/UI.hs b/app/UI.hs index 8dc2af1..7d5f114 100644 --- a/app/UI.hs +++ b/app/UI.hs @@ -32,6 +32,7 @@ updateUI window webView view = do handleAction :: TVar AppState -> Gtk.ApplicationWindow -> WebKit.WebView -> UserAction -> IO () handleAction stateTVar window webView action = do st <- atomically $ readTVar stateTVar + let totalChapters = length (cAllChapters st) case action of ZoomIn -> updateZoom stateTVar webView (zoomlvl st + 0.1) ZoomOut -> updateZoom stateTVar webView (max 0.1 (zoomlvl st - 0.1)) @@ -42,7 +43,9 @@ handleAction stateTVar window webView action = do LoadSpecific i -> i _ -> cIdx st - case prepareView st nextIdx of + let safeIdx = max 0 (min (totalChapters -1 ) nextIdx) + + case prepareView st safeIdx of Nothing -> pure () Just view -> do updateUI window webView view