Skip to content
Snippets Groups Projects
Commit 815cbe97 authored by Mr. Snow Ball / projects's avatar Mr. Snow Ball / projects :arrows_counterclockwise:
Browse files

Update Qubes property on click

parent 2865d49d
No related branches found
No related tags found
No related merge requests found
...@@ -3,13 +3,15 @@ module QBar.Blocks.Qubes where ...@@ -3,13 +3,15 @@ module QBar.Blocks.Qubes where
import QBar.BlockHelper import QBar.BlockHelper
import QBar.BlockOutput import QBar.BlockOutput
import QBar.Core import QBar.Core
import QBar.Qubes.AdminAPI (qubesUsageOfDefaultPool, qubesMonitorProperty, qubesEvents, QubesPropertyInfo (..)) import QBar.Qubes.AdminAPI (qubesUsageOfDefaultPool, qubesMonitorProperty, qubesGetProperty, qubesEvents, QubesPropertyInfo (..))
import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy as BL
import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy as T
import Data.Text.Lazy.Encoding (decodeUtf8With) import Data.Text.Lazy.Encoding (decodeUtf8With)
import Data.Text.Encoding.Error (lenientDecode) import Data.Text.Encoding.Error (lenientDecode)
import Pipes import Pipes as P
import Pipes.Concurrent as P
import qualified Pipes.Safe as P
diskIcon :: T.Text diskIcon :: T.Text
diskIcon = "💾\xFE0E" diskIcon = "💾\xFE0E"
...@@ -26,7 +28,9 @@ diskUsageQubesBlock = runPollBlock $ forever $ do ...@@ -26,7 +28,9 @@ diskUsageQubesBlock = runPollBlock $ forever $ do
createBlockOutput :: Int -> BlockOutput createBlockOutput :: Int -> BlockOutput
createBlockOutput free = createBlockOutput free =
mkBlockOutput $ chooseColor free $ formatSize free mkBlockOutput $ chooseColor free $ formatSize free
chooseColor _free = normalText --TODO chooseColor free = if free < 40 * 1024*1024*1024
then activeText
else normalText
sizeUnits = [ sizeUnits = [
("T", 1024*1024*1024*1024), ("T", 1024*1024*1024*1024),
("G", 1024*1024*1024), ("G", 1024*1024*1024),
...@@ -39,10 +43,23 @@ diskUsageQubesBlock = runPollBlock $ forever $ do ...@@ -39,10 +43,23 @@ diskUsageQubesBlock = runPollBlock $ forever $ do
_ -> T.pack (show size) <> " bytes" _ -> T.pack (show size) <> " bytes"
qubesMonitorPropertyBlock :: BL.ByteString -> Block qubesMonitorPropertyBlock :: BL.ByteString -> Block
qubesMonitorPropertyBlock name = fmap (const ExitBlock) (qubesMonitorProperty qubesEvents name) >-> forever update qubesMonitorPropertyBlock name = do
(output, input) <- liftIO $ spawn $ newest 1
forkSafeEffect $ qubesMonitorProperty qubesEvents name >-> toOutput output
toExitBlock $ fromInput input >-> forever (update output)
where where
update = do forkSafeEffect :: MonadIO m => Effect (P.SafeT IO) () -> m ()
QubesPropertyInfo {propValue, propIsDefault} <- await forkSafeEffect = void . liftIO . forkIO . P.runSafeT . runEffect
pushBlockUpdate' handleClick $ mkBlockOutput $ normalText $ decode propValue <> (if propIsDefault then " (D)" else "")
handleClick _ = return () --TODO forkEffect :: MonadIO m => Effect IO () -> m ()
forkEffect = void . liftIO . forkIO . runEffect
toExitBlock = fmap (const ExitBlock)
decode = decodeUtf8With lenientDecode decode = decodeUtf8With lenientDecode
update output = do
QubesPropertyInfo {propValue, propIsDefault} <- await
trace ("update: " <> show propValue) $ pushBlockUpdate' handleClick $ mkBlockOutput $ normalText $ decode propValue <> (if propIsDefault then " (D)" else "")
where
handleClick _ = forkEffect $ (liftIO (qubesGetProperty name) >>= yield) >-> toOutput output
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment