Skip to content

Commit

Permalink
print: Hack to forward Hex House print requests to folk0
Browse files Browse the repository at this point in the history
  • Loading branch information
osnr committed Nov 21, 2023
1 parent 0f21d31 commit 9c40b91
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions virtual-programs/print.folk
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,27 @@ proc nextId {} {
set id
}

proc remotePrintRequest {remoteNode clause} {
::websocket::open "ws://$remoteNode.local:4273/ws" [list apply {{clause sock type msg} {
if {$type eq "connect"} {
::websocket::send $sock text [list apply {{clause} {
Assert {*}$clause
after 5000 [list Retract {*}$clause]
Step
}} $clause]
after 10000 [list ::websocket::close $sock]
}
}} $clause]
}

if {![info exists ::printjobs]} {set ::printjobs [dict create]}
When /someone/ wishes to print /code/ with job id /jobid/ {
if {$::thisNode eq "folk-beads" || $::thisNode eq "folk-convivial"} {
# HACK: Forward the print request to folk0.
remotePrintRequest "folk0" [list $::thisNode wishes to print $code with job id $jobid]
return
}

puts "Wish to print jobid $jobid"
if {[dict exists $::printjobs $jobid]} {return}

Expand Down Expand Up @@ -205,6 +224,12 @@ When /someone/ wishes to print /code/ with job id /jobid/ {
exec lpr $::env(HOME)/folk-printed-programs/$id.pdf
}
When /someone/ wishes to print program /id/ with code /code/ with job id /jobid/ {
if {$::thisNode eq "folk-beads" || $::thisNode eq "folk-convivial"} {
# HACK: Forward the print request to folk0.
remotePrintRequest "folk0" [list $::thisNode wishes to print program $id with code $code with job id $jobid]
return
}

puts "Wish to print jobid $jobid"
if {[dict exists $::printjobs $jobid]} {return}

Expand Down

0 comments on commit 9c40b91

Please sign in to comment.