diff --git a/src/QBar/Server.hs b/src/QBar/Server.hs index f6c5be96346084534cc129928fb78349b2569b4c..81756a7eb22346adabd32c59cb4e877c755ac62a 100644 --- a/src/QBar/Server.hs +++ b/src/QBar/Server.hs @@ -157,6 +157,16 @@ installSignalHandlers = do hPutStrLn stderr "SIGCONT received" updateBar' bar +renderInitialBlocks :: MainOptions -> Handle -> Filter -> IO C8.ByteString +renderInitialBlocks options handle blockFilter = do + date <- dateBlockOutput + let initialBlocks = [date] + -- Attach spinner indicator when verbose flag is set + let initialBlocks' = if indicator options then initialBlocks <> [createBlock "*"] else initialBlocks + -- Render initial time block so the bar is not empty after startup + renderLine options handle blockFilter initialBlocks' "" + + runBarConfiguration :: BarIO () -> MainOptions -> IO () runBarConfiguration generateBarConfig options = do -- Create IORef to contain the active filter @@ -166,12 +176,6 @@ runBarConfiguration generateBarConfig options = do putStrLn "{\"version\":1,\"click_events\":true}" putStrLn "[" - date <- dateBlockOutput - let initialBlocks = [date] - - -- Attach spinner indicator when verbose flag is set - let initialBlocks' = if indicator options then initialBlocks <> [createBlock "*"] else initialBlocks - (requestBarUpdate, barUpdateEvent) <- createBarUpdateChannel -- Create channel to send new block producers to render loop @@ -186,9 +190,8 @@ runBarConfiguration generateBarConfig options = do handleActiveFilter = activeFilter } + initialOutput <- renderInitialBlocks options handle initialBlockFilter - -- Render initial time block so the bar is not empty after startup - initialOutput <- renderLine options handle initialBlockFilter initialBlocks' "" -- Fork stdin handler void $ forkFinally (runReaderT (handleStdin options actionList) bar) (\result -> hPutStrLn stderr $ "handleStdin failed: " <> show result) @@ -221,6 +224,7 @@ runBarConfiguration generateBarConfig options = do -- Evaluate config generateBarConfig + createCommandChan :: IO CommandChan createCommandChan = newTChanIO