taffybar-2.1.0: src/System/Taffybar/Widget/Generic/ChannelWidget.hs
module System.Taffybar.Widget.Generic.ChannelWidget where
import Control.Concurrent
import Control.Monad
import Control.Monad.IO.Class
import GI.Gtk
channelWidgetNew :: (MonadIO m, IsWidget w) => w -> Chan a -> (a -> IO ()) -> m w
channelWidgetNew widget channel updateWidget = do
void $ onWidgetRealize widget $ do
ourChan <- dupChan channel
processingThreadId <- forkIO $ forever $
readChan ourChan >>= updateWidget
void $ onWidgetUnrealize widget $ killThread processingThreadId
widgetShowAll widget
return widget