module System.Taffybar.Widget.DiskIOMonitor ( dioMonitorNew ) where
import Control.Monad.IO.Class
import qualified GI.Gtk
import System.Taffybar.Information.DiskIO ( getDiskTransfer )
import System.Taffybar.Widget.Generic.PollingGraph ( GraphConfig, pollingGraphNew )
dioMonitorNew
:: MonadIO m
=> GraphConfig
-> Double
-> String
-> m GI.Gtk.Widget
dioMonitorNew :: forall (m :: * -> *).
MonadIO m =>
GraphConfig -> Double -> String -> m Widget
dioMonitorNew GraphConfig
cfg Double
pollSeconds =
GraphConfig -> Double -> IO [Double] -> m Widget
forall (m :: * -> *).
MonadIO m =>
GraphConfig -> Double -> IO [Double] -> m Widget
pollingGraphNew GraphConfig
cfg Double
pollSeconds (IO [Double] -> m Widget)
-> (String -> IO [Double]) -> String -> m Widget
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO [Double]
probeDisk
probeDisk :: String -> IO [Double]
probeDisk :: String -> IO [Double]
probeDisk String
disk = do
[Double]
transfer <- String -> IO [Double]
getDiskTransfer String
disk
let top :: Double
top = (Double -> Double -> Double) -> Double -> [Double] -> Double
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Double -> Double -> Double
forall a. Ord a => a -> a -> a
max Double
1.0 [Double]
transfer
[Double] -> IO [Double]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Double] -> IO [Double]) -> [Double] -> IO [Double]
forall a b. (a -> b) -> a -> b
$ (Double -> Double) -> [Double] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
map (Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
top) [Double]
transfer