module System.Taffybar.Widgets.PollingGraph (
GraphHandle,
GraphConfig(..),
pollingGraphNew,
defaultGraphConfig
) where
import Control.Concurrent
import Control.Monad ( forever )
import Graphics.UI.Gtk
import System.Taffybar.Widgets.Graph
pollingGraphNew :: GraphConfig
-> Double
-> IO [Double]
-> IO Widget
pollingGraphNew cfg pollSeconds action = do
(da, h) <- graphNew cfg
_ <- on da realize $ do
_ <- forkIO $ forever $ do
sample <- action
graphAddSample h sample
threadDelay $ floor (pollSeconds * 1000000)
return ()
return da