module System.Taffybar.Widgets.PollingGraph (
GraphHandle,
GraphConfig(..),
GraphDirection(..),
GraphStyle(..),
pollingGraphNew,
defaultGraphConfig
) where
import Control.Concurrent
import qualified Control.Exception.Enclosed as E
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
esample <- E.tryAny action
case esample of
Left _ -> return ()
Right sample -> graphAddSample h sample
threadDelay $ floor (pollSeconds * 1000000)
return ()
return da