shrub/pkg/arvo/app/launch.hoon

161 lines
3.9 KiB
Plaintext
Raw Normal View History

2019-11-21 02:39:46 +03:00
/- launch
2020-03-12 03:33:48 +03:00
/+ *server, default-agent, dbug
/= index /app/launch/index
/* index-js %js /app/launch/js/index/js
/* index-css %css /app/launch/css/index/css
/* home-png %png /app/launch/img/home/png
/* favicon-png %png /app/launch/img/favicon/png
2019-11-21 02:39:46 +03:00
::
=/ as-octs as-octs:mimes:html
=/ script (as-octs index-js)
=/ style (as-octs index-css)
::
2020-04-23 08:51:34 +03:00
=/ launch-png=(map @t octs)
=- (~(run by -) as-octs:mimes:html)
%- ~(gas by *(map @t @))
:~ [%'Home' home-png]
[%'Favicon' favicon-png]
2019-11-21 02:39:46 +03:00
==
::
|%
+$ versioned-state
$% state-zero
==
+$ state-zero
$: %0
tiles=(set tile:launch)
data=tile-data:launch
path-to-tile=(map path @tas)
==
::
+$ card card:agent:gall
--
::
=| state-zero
=* state -
2020-03-12 03:33:48 +03:00
%- agent:dbug
2019-11-21 02:39:46 +03:00
^- agent:gall
|_ bol=bowl:gall
+* this .
def ~(. (default-agent this %|) bol)
++ on-init
^- (quip card _this)
:_ this
[%pass / %arvo %e %connect [~ /] %launch]~
::
++ on-save !>(state)
::
++ on-load
|= old=vase
`this(state !<(state-zero old))
::
++ on-poke
|= [mar=mark vas=vase]
^- (quip card _this)
?+ mar (on-poke:def mar vas)
::
%launch-action
=/ act !<(action:launch vas)
=/ beforedata (~(get by data) name.act)
=/ newdata
?~ beforedata
(~(put by data) name.act [*json url.act])
(~(put by data) name.act [jon.u.beforedata url.act])
=/ new-tile `tile:launch`[`@tas`name.act `path`subscribe.act]
:- [%pass subscribe.act %agent [our.bol name.act] %watch subscribe.act]~
%= this
tiles (~(put in tiles) new-tile)
data newdata
path-to-tile (~(put by path-to-tile) subscribe.act name.act)
==
::
%handle-http-request
=+ !<([eyre-id=@ta =inbound-request:eyre] vas)
:_ this
%+ give-simple-payload:app eyre-id
%+ require-authorization:app inbound-request
|= =inbound-request:eyre
^- simple-payload:http
=/ request-line (parse-request-line url.request.inbound-request)
=/ name=@t
=/ back-path (flop site.request-line)
?~ back-path
''
i.back-path
?+ site.request-line
not-found:gen
::
~
=/ hym=manx
%- index
^- marl
%+ turn ~(tap by data)
|= [key=@tas [jon=json url=@t]]
^- manx
;script@"{(trip url)}";
(manx-response:gen hym)
::
[%'~launch' %css %index ~] :: styling
(css-response:gen style)
::
[%'~launch' %js %index ~] :: javascript
(js-response:gen script)
::
[%'~launch' %img *] :: images
2020-04-23 08:51:34 +03:00
=/ img=(unit octs) (~(get by launch-png) name)
2019-11-21 02:39:46 +03:00
?~ img
not-found:gen
2020-04-23 08:51:34 +03:00
(png-response:gen u.img)
2019-11-21 02:39:46 +03:00
::
[%'~modulo' %session ~]
=/ session-js
%- as-octt:mimes:html
;: weld
"window.ship = '{+:(scow %p our.bol)}';"
"window.urb = new Channel();"
==
(js-response:gen session-js)
==
==
::
++ on-watch
|= pax=path
^- (quip card _this)
?: ?=([%http-response *] pax)
[~ this]
?. ?=([%main *] pax)
(on-watch:def pax)
=/ data=json
%- pairs:enjs:format
%+ turn ~(tap by data)
|= [key=@tas [jon=json url=@t]]
[key jon]
:_ this
[%give %fact ~ %json !>(data)]~
::
++ on-leave on-leave:def
++ on-peek on-peek:def
++ on-fail on-fail:def
++ on-agent
|= [wir=wire sin=sign:agent:gall]
^- (quip card _this)
?. ?=(%fact -.sin)
(on-agent:def wir sin)
?. ?=(%json p.cage.sin)
(on-agent:def wir sin)
::
=/ jon=json !<(json q.cage.sin)
=/ name=@tas (~(got by path-to-tile) wir)
=/ dat=(unit [json url=@t]) (~(get by data) name)
?~ dat [~ this]
:_ this(data (~(put by data) name [jon url.u.dat]))
[%give %fact ~[/main] %json !>((frond:enjs:format name jon))]~
2019-11-21 02:39:46 +03:00
::
++ on-arvo
|= [wir=wire sin=sign-arvo]
^- (quip card:agent:gall _this)
?. ?=(%bound +<.sin)
(on-arvo:def wir sin)
[~ this]
--