From 8eac489504589d23fe3108d9e59b4de4f1097bdb Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Tue, 12 Mar 2019 17:47:57 -0700 Subject: [PATCH] Added command palette, go event --- app/modulo.hoon | 68 ++++++++++++++++++++++++++++------------- app/modulo/index.html | 28 +++++++++++++++++ app/modulo/script.js | 62 +++++++++++++++++++++++++++++++++---- app/subapp.hoon | 22 ++++++++++++- app/subapp/index.html | 11 +++++++ app/subapp/script.js | 1 + app/subapp1.hoon | 22 ++++++++++++- app/subapp1/index.html | 11 +++++++ app/subapp1/script.js | 1 + lib/http.hoon | 35 +++++++++++++++++++++ mar/modulo/command.hoon | 7 +++++ sur/modulo.hoon | 1 + sys/vane/rver.hoon | 4 +-- 13 files changed, 240 insertions(+), 33 deletions(-) create mode 100644 app/modulo/index.html create mode 100644 app/subapp/index.html create mode 100644 app/subapp/script.js create mode 100644 app/subapp1/index.html create mode 100644 app/subapp1/script.js create mode 100644 lib/http.hoon diff --git a/app/modulo.hoon b/app/modulo.hoon index a09d609443..6945346e44 100644 --- a/app/modulo.hoon +++ b/app/modulo.hoon @@ -1,9 +1,9 @@ /- *modulo /+ *server -/= test-page +/= index /^ octs /; as-octs:mimes:html - /: /===/app/modulo/index /&html&/!hymn/ + /: /===/app/modulo/index /html/ /= modulo-js /^ octs /; as-octs:mimes:html @@ -35,6 +35,21 @@ == == :: +++ session-as-json + |= [cur=(unit [term @]) session=(map term @t) order=(list term)] + ^- json + ?~ cur + *json + %- pairs:enjs + :~ [%app %s -.u.cur] + [%url %s (~(got by session) -.u.cur)] + :- %list + :- %a + %+ turn order + |= [a=term] + [%s a] + == +:: -- :: |_ [bow=bowl:gall sta=state] @@ -56,17 +71,13 @@ :: ++ bound |= [wir=wire success=? binding=binding:http-server] - ~& [%bound success] [~ this] :: -++ session-as-json - ^- json - ?~ cur.sta - *json - %- pairs:enjs - :~ [%app %s -.u.cur.sta] - [%url %s (~(got by session.sta) u.cur.sta)] - == +++ peer-applist + |= [pax=path] + ^- (quip move _this) + :_ this + [ost.bow %diff %json (session-as-json cur.sta session.sta order.sta)]~ :: ++ session-js ^- octs @@ -76,9 +87,17 @@ %- crip ;: weld (trip 'window.onload = function() {') + "window.ship = '{(trip (rsh 3 1 (crip )))}';" " window.state = " - (en-json:html session-as-json) + (en-json:html (session-as-json cur.sta session.sta order.sta)) (trip '}();') + %- trip + ''' + document.onkeydown = (event) => { + if (!event.metaKey || event.keyCode !== 75) { return; } + window.parent.postMessage("commandPalette", "*"); + }; + ''' == :: +poke-handle-http-request: received on a new connection established :: @@ -88,7 +107,6 @@ ^- (quip move _this) :: =+ request-line=(parse-request-line url.request.inbound-request) - ~& [%request-line request-line] =/ name=@t =+ back-path=(flop site.request-line) ?~ back-path @@ -116,7 +134,7 @@ :~ ^- move :- ost.bow :* %http-response - [%start [200 ['content-type' 'text/html']~] [~ test-page] %.y] + [%start [200 ['content-type' 'text/html']~] [~ index] %.y] == == :: +poke-handle-http-cancel: received when a connection was killed @@ -132,7 +150,6 @@ |= bin=term ^- (quip move _this) =/ url (crip "~{(scow %tas bin)}") - ~& [%poke-mod-bind bin] ?: (~(has by session.sta) bin) [~ this] :- [`move`[ost.bow %connect / [~ /[url]] bin] ~] @@ -142,12 +159,15 @@ :: order.sta (weld order.sta ~[bin]) + :: + cur.sta + ?~ cur.sta `[bin 0] + cur.sta == :: ++ poke-modulo-unbind |= bin=term ^- (quip move _this) - ~& [%poke-mod-unbind bin] =/ url (crip "~{(scow %tas bin)}") ?. (~(has by session.sta) bin) [~ this] @@ -171,7 +191,6 @@ ++ poke-modulo-command |= com=command ^- (quip move _this) - ~& [%poke-mod-com com] =/ length (lent order.sta) ?~ cur.sta [~ this] @@ -180,20 +199,25 @@ =/ new-cur=(unit [term @]) ?- -.com %forward - ?: =(length +.u.cur.sta) + ?: =((dec length) +.u.cur.sta) `[(snag 0 order.sta) 0] - =/ ind +(-.u.cur.sta) + =/ ind +(+.u.cur.sta) `[(snag ind order.sta) ind] %back ?: =(0 +.u.cur.sta) =/ ind (dec length) `[(snag ind order.sta) ind] - =/ ind (dec -.u.cur.sta) + =/ ind (dec +.u.cur.sta) `[(snag ind order.sta) ind] + %go + =/ ind (find [app.com]~ order.sta) + ?~ ind + cur.sta + `[app.com u.ind] == :_ this(cur.sta new-cur) - %+ turn (prey:pubsub:userlib /sessions bow) + %+ turn (prey:pubsub:userlib /applist bow) |= [=bone ^] - [bone %diff %json session-as-json] + [bone %diff %json (session-as-json new-cur session.sta order.sta)] :: -- diff --git a/app/modulo/index.html b/app/modulo/index.html new file mode 100644 index 0000000000..bb31f4e43b --- /dev/null +++ b/app/modulo/index.html @@ -0,0 +1,28 @@ + + + + + + + + +
+ + + + diff --git a/app/modulo/script.js b/app/modulo/script.js index 30e0a89f65..e159b22348 100644 --- a/app/modulo/script.js +++ b/app/modulo/script.js @@ -1,6 +1,56 @@ -let iframe = document.createElement('iframe'); -iframe.setAttribute('src', window.state.url); -iframe.setAttribute('width', '100%;'); -iframe.setAttribute('height', '100%;'); -iframe.setAttribute('style', 'border-style: none !important;'); -document.body.appendChild(iframe); +function setFrame() { + let iframe = document.createElement('iframe'); + iframe.setAttribute('src', window.state.url); + iframe.setAttribute('width', '100%;'); + iframe.setAttribute('height', '100%;'); + iframe.setAttribute('style', 'border-style: none !important;'); + let inner = document.getElementById("frame"); + inner.innerHTML = ""; + inner.appendChild(iframe); + iframe.focus(); +} + +function doSub() { + window.urb.subscribe(window.ship, "modulo", "/applist", + (err) => { + console.log(err); + }, + (event) => { + console.log(event); + window.state = event; + setFrame(); + }, + () => { + doSub(); + } + ); +} + +window.addEventListener("message", (event) => { + let popup = document.getElementById("popup"); + let input = document.getElementById("input"); + + popup.style = "position:absolute; left: 0; top: 0; display:block; width: 100%; height: 100%; margin: 0 0; background-color:white;"; + input.style = ""; + input.addEventListener("keyup", (e) => { + if (e.keyCode !== 13) { return; } + window.urb.poke(window.ship, "modulo", "modulo-command", + { + go: input.value + }, + (json) => { + console.log(json); + }, + (err) => { + console.log(err); + } + ); + + }); + + +}); + +setFrame(); +doSub(); + diff --git a/app/subapp.hoon b/app/subapp.hoon index 212ee31c30..d717f8f2af 100644 --- a/app/subapp.hoon +++ b/app/subapp.hoon @@ -2,7 +2,12 @@ /= index /^ octs /; as-octs:mimes:html - /: /===/app/subapp/index /&html&/!hymn/ + /: /===/app/subapp/index /html/ +/= script + /^ octs + /; as-octs:mimes:html + /: /===/app/subapp/script /js/ + :: |% :: +move: output effect @@ -45,6 +50,21 @@ %- (require-authorization ost.bol move this) |= =inbound-request:http-server ^- (quip move _this) + =+ request-line=(parse-request-line url.request.inbound-request) + =/ name=@t + =+ back-path=(flop site.request-line) + ?~ back-path + 'World' + i.back-path + :: + ?: =(name 'script') + :_ this + :~ ^- move + :- ost.bol + :* %http-response + [%start [200 ['content-type' 'application/javascript']~] [~ script] %.y] + == + == :_ this :~ ^- move :- ost.bol diff --git a/app/subapp/index.html b/app/subapp/index.html new file mode 100644 index 0000000000..620833be05 --- /dev/null +++ b/app/subapp/index.html @@ -0,0 +1,11 @@ + + + + + + + + +

Jimmy

+ + diff --git a/app/subapp/script.js b/app/subapp/script.js new file mode 100644 index 0000000000..7f7060fbe8 --- /dev/null +++ b/app/subapp/script.js @@ -0,0 +1 @@ +console.log("subapp"); diff --git a/app/subapp1.hoon b/app/subapp1.hoon index b2cbdacb0d..dec7f692b6 100644 --- a/app/subapp1.hoon +++ b/app/subapp1.hoon @@ -2,7 +2,12 @@ /= index /^ octs /; as-octs:mimes:html - /: /===/app/subapp1/index /&html&/!hymn/ + /: /===/app/subapp1/index /html/ +/= script + /^ octs + /; as-octs:mimes:html + /: /===/app/subapp1/script /js/ + :: |% :: +move: output effect @@ -45,6 +50,21 @@ %- (require-authorization ost.bol move this) |= =inbound-request:http-server ^- (quip move _this) + =+ request-line=(parse-request-line url.request.inbound-request) + =/ name=@t + =+ back-path=(flop site.request-line) + ?~ back-path + 'World' + i.back-path + :: + ?: =(name 'script') + :_ this + :~ ^- move + :- ost.bol + :* %http-response + [%start [200 ['content-type' 'application/javascript']~] [~ script] %.y] + == + == :_ this :~ ^- move :- ost.bol diff --git a/app/subapp1/index.html b/app/subapp1/index.html new file mode 100644 index 0000000000..38f7f6c8c3 --- /dev/null +++ b/app/subapp1/index.html @@ -0,0 +1,11 @@ + + + + + + + + +

Is Great

+ + diff --git a/app/subapp1/script.js b/app/subapp1/script.js new file mode 100644 index 0000000000..5aca8cddb0 --- /dev/null +++ b/app/subapp1/script.js @@ -0,0 +1 @@ +console.log("subapp1"); diff --git a/lib/http.hoon b/lib/http.hoon new file mode 100644 index 0000000000..3326058c70 --- /dev/null +++ b/lib/http.hoon @@ -0,0 +1,35 @@ +:: +:::: /hoon/http/lib + :: + :: + :: +/? 310 +:: +=, mimes:html +=, html +|% +++ request + $: domain/(list cord) + end-point/path + req-type/$?($get {$post p/json}) + headers/math:eyre + queries/quay:eyre + == +++ send + |= {ost/bone pour-path/wire params/request} + :^ ost %them pour-path + `(unit hiss:eyre)`[~ (request-to-hiss params)] +:: +++ request-to-hiss + |= request ^- hiss:eyre + =- ~& hiss=- - + :- ^- parsed-url/purl:eyre + :+ :+ security=%.y + port=~ + host=[%.y [path=domain]] + endpoint=[extensions=~ point=end-point] :: ++pork, + q-strings=queries :: ++quay + ?@ req-type + [%get headers ~] + [%post headers ~ (as-octt:mimes:html (en-json p.req-type))] +-- diff --git a/mar/modulo/command.hoon b/mar/modulo/command.hoon index 5d9603cca1..d66ae147b2 100644 --- a/mar/modulo/command.hoon +++ b/mar/modulo/command.hoon @@ -1,7 +1,14 @@ /- *modulo +=, format |_ com=command ++ grab |% ++ noun command + ++ json + %- of:dejs + :~ forward+ul:dejs + back+ul:dejs + go+(su:dejs sym) + == -- -- diff --git a/sur/modulo.hoon b/sur/modulo.hoon index aa3875958a..b0b21028d0 100644 --- a/sur/modulo.hoon +++ b/sur/modulo.hoon @@ -2,5 +2,6 @@ +$ command $% [%forward ~] [%back ~] + [%go app=term] == -- diff --git a/sys/vane/rver.hoon b/sys/vane/rver.hoon index 5a6f43862d..0312dffe6e 100644 --- a/sys/vane/rver.hoon +++ b/sys/vane/rver.hoon @@ -627,9 +627,7 @@ } }; - export function newChannel() { - return new Channel; - } + window.urb = new Channel(); ''' :: +format-ud-as-integer: prints a number for consumption outside urbit ::