Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
qbar
Commits
85467aaf
Commit
85467aaf
authored
4 years ago
by
Mr. Snow Ball / projects
Browse files
Options
Downloads
Patches
Plain Diff
Refactor qubesMonitorPropertyBlock: extract pipeBlockWithEvents
parent
eb829644
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/QBar/Blocks/Qubes.hs
+18
-13
18 additions, 13 deletions
src/QBar/Blocks/Qubes.hs
with
18 additions
and
13 deletions
src/QBar/Blocks/Qubes.hs
+
18
−
13
View file @
85467aaf
...
@@ -43,10 +43,10 @@ diskUsageQubesBlock = runPollBlock $ forever $ do
...
@@ -43,10 +43,10 @@ diskUsageQubesBlock = runPollBlock $ forever $ do
((
unit
,
factor
)
:
_
)
->
T
.
pack
(
show
$
size
`
div
`
factor
)
<>
unit
((
unit
,
factor
)
:
_
)
->
T
.
pack
(
show
$
size
`
div
`
factor
)
<>
unit
_
->
T
.
pack
(
show
size
)
<>
" bytes"
_
->
T
.
pack
(
show
size
)
<>
" bytes"
qubesMonitorPropertyBlock
::
BL
.
ByteString
->
Block
pipeBlockWithEvents
::
forall
a
.
Producer
a
(
P
.
SafeT
IO
)
()
->
(
Either
BlockEvent
a
->
BarIO
(
Maybe
BlockOutput
))
->
Block
qubesMonitorPropertyBlock
name
=
do
pipeBlockWithEvents
prod
block
=
do
(
output
,
input
)
<-
liftIO
$
spawn
$
newest
1
(
output
,
input
)
<-
liftIO
$
spawn
$
newest
1
forkSafeEffect
$
qubesMonitorProperty
qubesEvents
name
>->
P
.
map
Right
>->
toOutput
output
forkSafeEffect
$
prod
>->
P
.
map
Right
>->
toOutput
output
toExitBlock
$
fromInput
input
>->
forever
(
update
output
)
toExitBlock
$
fromInput
input
>->
forever
(
update
output
)
where
where
forkSafeEffect
::
MonadIO
m
=>
Effect
(
P
.
SafeT
IO
)
()
->
m
()
forkSafeEffect
::
MonadIO
m
=>
Effect
(
P
.
SafeT
IO
)
()
->
m
()
...
@@ -57,20 +57,25 @@ qubesMonitorPropertyBlock name = do
...
@@ -57,20 +57,25 @@ qubesMonitorPropertyBlock name = do
toExitBlock
=
fmap
(
const
ExitBlock
)
toExitBlock
=
fmap
(
const
ExitBlock
)
decode
=
decodeUtf8With
lenientDecode
update
::
Output
(
Either
(
BlockOutput
,
BlockEvent
)
a
)
->
Pipe
(
Either
(
BlockOutput
,
BlockEvent
)
a
)
(
BlockState
,
BlockUpdateReason
)
BarIO
()
update
output
=
await
>>=
\
case
update
output
=
await
>>=
\
case
Right
prop
->
update'
prop
Right
prop
->
update'
$
Right
prop
Left
blockOutput
->
do
Left
(
blockOutput
,
event
)
->
do
let
state
=
Just
(
blockOutput
,
Nothing
)
let
state
=
Just
(
blockOutput
,
Nothing
)
yield
(
invalidateBlockState
state
,
EventUpdate
)
yield
(
invalidateBlockState
state
,
EventUpdate
)
prop
<-
liftIO
(
qubesGetProperty
name
)
update'
$
Left
event
update'
prop
where
where
update'
::
Either
BlockEvent
a
->
P
.
Pipe
b
BlockUpdate
BarIO
()
update'
prop
=
do
update'
prop
=
do
let
QubesPropertyInfo
{
propValue
,
propIsDefault
}
=
prop
Just
blockOutput
<-
lift
$
block
prop
let
blockOutput
=
mkBlockOutput
$
normalText
$
decode
propValue
<>
(
if
propIsDefault
then
" (D)"
else
""
)
pushBlockUpdate'
(
handleClick
blockOutput
)
blockOutput
pushBlockUpdate'
(
handleClick
blockOutput
)
blockOutput
handleClick
blockOutput
_
=
do
handleClick
blockOutput
event
=
do
forkEffect
$
yield
(
Left
blockOutput
)
>->
toOutput
output
forkEffect
$
yield
(
Left
(
blockOutput
,
event
))
>->
toOutput
output
qubesMonitorPropertyBlock
::
BL
.
ByteString
->
Block
qubesMonitorPropertyBlock
name
=
pipeBlockWithEvents
(
qubesMonitorProperty
qubesEvents
name
)
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
""
)
decode
=
decodeUtf8With
lenientDecode
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment