diff --git a/src/QBar/Blocks/Qubes.hs b/src/QBar/Blocks/Qubes.hs index aff5b6a0666b77945ff0046a9aa74b3fa06b76c2..50e67ac04eeeb9e6588f9f8033f091f2826e4d03 100644 --- a/src/QBar/Blocks/Qubes.hs +++ b/src/QBar/Blocks/Qubes.hs @@ -3,7 +3,7 @@ module QBar.Blocks.Qubes where import QBar.BlockHelper import QBar.BlockOutput import QBar.Core -import QBar.Qubes.AdminAPI (qubesUsageOfDefaultPool, qubesMonitorProperty, qubesGetProperty, qubesEvents, QubesPropertyInfo (..), qubesListVMsP, QubesVMState (..), vmState) +import QBar.Qubes.AdminAPI (qubesUsageOfDefaultPool, qubesMonitorProperty, qubesGetProperty, qubesEvents, QubesPropertyInfo (..), qubesListVMs, qubesListVMsP, QubesVMState (..), vmState) import Control.Concurrent.Async import Control.Monad.Reader (runReaderT) @@ -79,13 +79,12 @@ pipeBlockWithEvents prod block = do qubesMonitorPropertyBlock :: BL.ByteString -> Block qubesMonitorPropertyBlock name = pipeBlockWithEvents (qubesMonitorProperty qubesEvents name >> exitBlock) handle where - handle = handle' <=< either (const $ liftIO $ qubesGetProperty name) return - handle' QubesPropertyInfo {propValue, propIsDefault} = return $ Just $ mkBlockOutput $ normalText $ decode propValue <> (if propIsDefault then " (D)" else "") + handle = fmap handle' . either (const $ liftIO $ qubesGetProperty name) return + handle' QubesPropertyInfo {propValue, propIsDefault} = Just $ mkBlockOutput $ normalText $ decode propValue <> (if propIsDefault then " (D)" else "") decode = decodeUtf8With lenientDecode qubesVMCountBlock :: Block -qubesVMCountBlock = qubesListVMsP >-> P.map countVMs >> exitBlock where - countVMs = wrap . format . M.size . M.filterWithKey isRunningVM +qubesVMCountBlock = pipeBlockWithEvents (qubesListVMsP >> exitBlock) $ fmap countVMs . either (const $ liftIO $ qubesListVMs) return where + countVMs = Just . format . M.size . M.filterWithKey isRunningVM isRunningVM name x = vmState x == VMRunning && name /= "dom0" format n = mkBlockOutput $ normalText $ T.pack (show n) <> " Qube" <> (if n /= 1 then "s" else "") - wrap x = (Just (x, Nothing), DefaultUpdate)