diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-07-10 19:40:54 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-07-10 21:26:01 +0200 |
commit | 6b5dca2f1f857387ee615a1bbf4ea5db94052dcd (patch) | |
tree | c791fd9907815690ca93a65507449dd8dd3b65c1 /src/Main.hs | |
parent | 6ae3c189fb26230e7c5cc39596a3637112529aa6 (diff) |
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/Main.hs b/src/Main.hs index 28b0731..b969ba9 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -28,8 +28,6 @@ import Erebos.Storable import Erebos.Storage import Erebos.Sync -import System.IO.Unsafe - import Text.Blaze.Html5 ((!)) import Text.Blaze.Html5 qualified as H import Text.Blaze.Html5.Attributes qualified as A @@ -41,15 +39,18 @@ import WebSocket main :: IO () main = error "unused" -{-# NOINLINE globalStorage #-} -globalStorage :: Storage -globalStorage = unsafePerformIO $ memoryStorage +data GlobalState = GlobalState + { globalStorage :: Storage + , globalHead :: Head LocalState + } -{-# NOINLINE globalHead #-} -globalHead :: Head LocalState -globalHead = unsafePerformIO $ do +initGlobalState :: IO GlobalState +initGlobalState = do + globalStorage <- memoryStorage identity <- createIdentity globalStorage Nothing Nothing - storeHead globalStorage $ LocalState { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] } + globalHead <- storeHead globalStorage $ LocalState + { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] } + return GlobalState {..} foreign export javascript setup :: IO () setup :: IO () @@ -74,6 +75,8 @@ setup = do "Peers" H.ul ! A.id "peer_list" $ return () + GlobalState {..} <- initGlobalState + nameElem <- js_document_getElementById (toJSString "name_text") _ <- watchHead globalHead $ \ls -> do js_set_textContent nameElem $ toJSString $ maybe "(Anonymous)" T.unpack $ idName $ finalOwner $ headLocalIdentity ls |