~alcinnz/rhapsode

481a10883a504949f9121712f299200295688ad1 — Adrian Cochrane 3 years ago b294801
Drop outdated dependencies.
5 files changed, 19 insertions(+), 24 deletions(-)

M rhapsode.cabal
M src/Input.hs
M src/Links.hs
M src/Render.hs
M src/Types.hs
M rhapsode.cabal => rhapsode.cabal +1 -2
@@ 65,8 65,7 @@ library
        network-uri,
        stylist >= 2.4 && <3, css-syntax, xml-conduit-stylist >= 2.3 && <3, scientific,
        async, hurl >= 2, filepath, temporary,
        file-embed >= 0.0.9 && < 0.1, time,
        text-trie >= 0.2.5, parallel >= 1, strict >= 0.4
        file-embed >= 0.0.9 && < 0.1, time, parallel >= 1
  
  -- Directories containing source files.
  hs-source-dirs:      src

M src/Input.hs => src/Input.hs +3 -5
@@ 15,6 15,7 @@ import           Network.URI
import           Network.URI.Fetch
import           Network.URI.Charset
import qualified Data.Map as M
import qualified Data.Set as Set
import           Data.List (intercalate)
import           Data.Time.Clock



@@ 30,9 31,6 @@ import System.Directory
import System.FilePath ((</>))
import Data.FileEmbed

-- For history
import qualified Data.Trie.Text as Trie

-- For C API
import Types
import Data.HTML2CSS (html2css)


@@ 136,7 134,7 @@ pageForDoc uri doc = do
    return Page {Types.url = uri, html = doc, css = styles,
        -- These fields are all blank, to be filled in later by logHistory & parseDocument'
        pageTitle = "", pageMIME = "", apps = [],
        backStack = [], forwardStack = [], visitedURLs = Trie.empty}
        backStack = [], forwardStack = [], visitedURLs = Set.empty}

logHistory hist ret@Page {Types.url = url', html = doc} = do
    dir <- getXdgDirectory XdgData "rhapsode"


@@ 147,7 145,7 @@ logHistory hist ret@Page {Types.url = url', html = doc} = do
        "=>", uriToStr' url', show now, title
      ]

    return ret { pageTitle = title, visitedURLs = Trie.insert (Txt.pack $ uriToStr' url') () hist}
    return ret { pageTitle = title, visitedURLs = Set.insert (Txt.pack $ uriToStr' url') hist}
  where
    getTitle (XML.Element "title" _ childs) = Txt.concat [txt | XML.NodeContent txt <- childs]
    getTitle (XML.Element "h1" _ childs) = Txt.concat [txt | XML.NodeContent txt <- childs]

M src/Links.hs => src/Links.hs +4 -6
@@ 22,11 22,9 @@ import System.FilePath
import System.IO (hPrint, stderr) -- For error reporting

-- For suggestions.gmni
import Data.Trie.Text (Trie)
import qualified Data.Trie.Text as Trie
import qualified Data.Set as Set
import Data.List (nub, intercalate)
import Control.Concurrent (forkIO)
import qualified System.IO.Strict as Strict

data Link = Link {
    label :: Text,


@@ 168,11 166,11 @@ updateSuggestions page = do
    let path = dir </> "suggestions.gmni"
    exists <- doesFileExist path
    suggestions <- if not exists then return [] else do
        file <- Strict.readFile path
        return [line' | line <- lines file, line'@(_:uri':_) <- [words line], not (pack uri' `Trie.member` visitedURLs page)]
        file <- Prelude.readFile path
        return [line' | line <- lines file, line'@(_:uri':_) <- [words line], not (pack uri' `Set.member` visitedURLs page)]

    let suggestions' = suggestions ++ nub [["=>", uri', domain] | link <- links,
            let uri' = uriToString id (href link) "", not (pack uri' `Trie.member` visitedURLs page)]
            let uri' = uriToString id (href link) "", not (pack uri' `Set.member` visitedURLs page)]

    createDirectoryIfMissing True dir
    Prelude.writeFile path $ unlines $ map unwords suggestions'

M src/Render.hs => src/Render.hs +3 -3
@@ 36,7 36,7 @@ import           System.IO.Temp
import           Control.Exception (catch)

--- For psuedoclasses
import qualified Data.Trie.Text as Trie
import qualified Data.Set as Set
import qualified Data.CSS.Syntax.Selector as CSSSel

-- Internal Rhapsode Subcomponents


@@ 124,8 124,8 @@ targetSel ('#':'.':anchor) =
targetSel ('#':id) = [CSSTok.Hash CSSTok.HUnrestricted $ Txt.pack id]
targetSel _ = []

testVisited :: Trie.Trie () -> URI -> String -> Bool
testVisited hist base val = uriToText url `Trie.member` hist
testVisited :: Set.Set Text -> URI -> String -> Bool
testVisited hist base val = uriToText url `Set.member` hist
  where
    url = fromMaybe nullURI (parseURIReference val) `relativeTo` base
    uriToText uri = pack $ uriToString id uri ""

M src/Types.hs => src/Types.hs +8 -8
@@ 11,13 11,13 @@ import Network.URI
import Network.URI.Fetch (Application(..))

-- For the in-memory history log
import Data.Trie.Text (Trie)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.Text (Text(..))
import qualified Data.Text as Txt
import qualified Data.Trie.Text as Trie
import System.Directory
import System.FilePath ((</>))
import Control.Parallel (par)
import qualified System.IO.Strict as Strict

import Foreign.Ptr
import Foreign.StablePtr


@@ 34,22 34,22 @@ data Page = Page {
    backStack :: [(String, URI)],
    forwardStack :: [(String, URI)],
    -- Probably don't need an MVar here, but let's be safe!
    visitedURLs :: Trie ()
    visitedURLs :: Set Text
}

foreign export ccall c_initialReferer :: IO (StablePtr Page)

loadVisited :: IO (Trie ())
loadVisited :: IO (Set Text)
loadVisited = do
    dir <- getXdgDirectory XdgData "rhapsode"
    let path = dir </> "history.gmni"
    exists <- doesFileExist path

    if exists then do
        file <- Strict.readFile path -- Can't leave this file locked when I'll shortly append to it!
        let hist = Trie.fromList [(Txt.pack uri, ()) | _:uri:_ <- map words $ lines file]
        file <- Prelude.readFile path -- Can't leave this file locked when I'll shortly append to it!
        let hist = length file `seq` Set.fromList [Txt.pack uri | _:uri:_ <- map words $ lines file]
        hist `par` return hist
    else return Trie.empty
    else return Set.empty

c_initialReferer = do
    cwd <- getCurrentDirectory