From bbc88be95423289e0bdfb325a4914f4227154984 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Fri, 15 Nov 2024 13:29:50 +0100 Subject: [PATCH] clipboard support --- buildroot-v86/board/v86/rootfs_overlay/bin/js | 1 + .../board/v86/rootfs_overlay/etc/profile | 2 +- .../board/v86/rootfs_overlay/etc/profile.sh | 18 ++++++-- .../board/v86/rootfs_overlay/etc/profile.xrsh | 8 ++++ .../board/v86/rootfs_overlay/root/.profile | 5 --- .../v86/rootfs_overlay/root/bin/enter-ar | 2 + .../v86/rootfs_overlay/root/bin/enter-vr | 2 + .../board/v86/rootfs_overlay/root/bin/exit-ar | 2 + .../board/v86/rootfs_overlay/root/bin/exit-vr | 2 + .../v86/rootfs_overlay/root/bin/helloworld | 2 +- .../rootfs_overlay/root/bin/helloworld.awk | 2 +- .../v86/rootfs_overlay/root/bin/helloworld.js | 5 ++- .../rootfs_overlay/root/bin/helloworld.lua | 4 +- .../v86/rootfs_overlay/root/bin/helloworld.py | 6 ++- .../board/v86/rootfs_overlay/root/bin/upload | 13 ++++++ .../board/v86/rootfs_overlay/root/bin/watchfs | 6 +-- .../root/hook.d/clipboard/receive.awk | 1 + .../root/hook.d/clipboard/receive.js | 1 + .../root/hook.d/clipboard/receive.lua | 1 + .../root/hook.d/clipboard/receive.py | 1 + .../root/hook.d/clipboard/receive.sh | 14 ++++++ .../root/hook.d/{.mp4 => filetype/mp4}/play | 0 .../root/hook.d/filetype/txt/import-to-aframe | 6 +++ .../root/hook.d/mimetype/audio/mpeg | 1 + .../model/gltf-binary/import-to-aframe | 6 +++ .../model/gltf-binary/import-to-scene | 2 + .../mimetype/text/aframe/import-to-aframe | 5 +++ .../root/hook.d/mimetype/text/detect.aframe | 9 ++++ .../root/hook.d/mimetype/text/detect.html | 8 ++++ .../hook.d/mimetype/text/detect.javascript | 8 ++++ .../root/hook.d/mimetype/text/html/eval | 5 +++ .../hook.d/mimetype/text/import-to-aframe | 1 + .../root/hook.d/mimetype/text/javascript/eval | 5 +++ .../root/hook.d/mimetype/text/plain | 1 + .../root/hook.d/mimetype/video/mp4 | 1 + .../board/v86/rootfs_overlay/root/manual.md | 44 +++++++++++++++++-- 36 files changed, 178 insertions(+), 22 deletions(-) create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-ar create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-vr create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-ar create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-vr create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/bin/upload create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.awk create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.js create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.lua create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.py create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.sh rename buildroot-v86/board/v86/rootfs_overlay/root/hook.d/{.mp4 => filetype/mp4}/play (100%) create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/filetype/txt/import-to-aframe create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/audio/mpeg create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-aframe create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-scene create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/aframe/import-to-aframe create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.aframe create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.html create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.javascript create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/html/eval create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/import-to-aframe create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/javascript/eval create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/plain create mode 120000 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/video/mp4 diff --git a/buildroot-v86/board/v86/rootfs_overlay/bin/js b/buildroot-v86/board/v86/rootfs_overlay/bin/js index acbdcd4..3a41ff9 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/bin/js +++ b/buildroot-v86/board/v86/rootfs_overlay/bin/js @@ -22,6 +22,7 @@ OUTPUT=/mnt/run/$PID # com/isoterminal/feat/javascript.js writes output here touch $OUTPUT echo -n "PID=$PID; $javascript" > /dev/browser/js # todo watch file +sleep 0.1 cat $OUTPUT rm $OUTPUT diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile b/buildroot-v86/board/v86/rootfs_overlay/etc/profile index a08f1f6..eab8d0a 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/etc/profile +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile @@ -47,7 +47,7 @@ help_tips(){ } export TERM=xterm-256color -export PS1="\[\033[38;5;165m\]> \[\033[0m\]" +export PS1="\[\e[36m\]> \[\e\[0m\]" # aliases alias ls='ls -ha -w100' diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh index 7fbaa76..eb34d2e 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh @@ -1,12 +1,14 @@ hook(){ test -z "$1" && { echo "usage: hook [args]"; return 0; } + logger "$ hook $*" cmd=$1 shift test -d ~/hook.d/$cmd && { - find ~/hook.d/$cmd/ -type f -executable | while read hook; do + find -L ~/hook.d/$cmd/ -type f -executable -maxdepth 1 | while read hook; do + logger " |+ hook $hook $*" { $hook "$@" || true; } | awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1' done - } + } &> ~/hook.d/log.txt } alert(){ @@ -20,7 +22,11 @@ alert(){ confirm(){ test -z "$1" && { echo "usage: confirm "; return 0; } - read -p "$(printf "\033[0m")[?] $1 [y/n] $(printf "\033[0m")" y + if test -n "$BROWSER"; then + jsh confirm "$1" + else + read -p "$(printf "\033[0m")[?] $1 [y/n] $(printf "\033[0m")" y + fi test $y = y && echo true && return 0 test $y = y || echo false hook confirm $1 $y @@ -29,7 +35,11 @@ confirm(){ prompt(){ test -z "$1" && { echo "usage: prompt [answer_default]"; return 0; } test -n "$2" && answer="[$2] " && answer_fallback="$2" - read -p "$(printf "\033[0m")[?] $1: $answer $(printf "\033[0m")" answer + if test -n "$BROWSER"; then + jsh prompt "$1" "$answer_fallback" + else + read -p "$(printf "\033[0m")[?] $1: $answer $(printf "\033[0m")" answer + fi test -z "$answer" && answer="$answer_fallback" echo "$answer" hook prompt $1 $answer diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh index d496dd9..80770c9 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh @@ -9,6 +9,13 @@ test -d /dev/browser || { ln -fs /mnt/root /root } + setup_clipboard(){ + test -d /mnt/clipboard || { + mkdir /mnt/clipboard + echo "files appear here when dragdropping- or copy/pasting a file into the 3D scene (minimize in non-immersive mode)" > /mnt/clipboard/README.md + } + } + setup_links(){ ln -fs /etc/motd ~/.motd ln -fs /mnt/profile.browser ~/.profile.browser @@ -50,6 +57,7 @@ test -d /dev/browser || { move_root_to_9pfs setup_browser_dev + setup_clipboard setup_links setup_network setup_overlayfs diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/.profile b/buildroot-v86/board/v86/rootfs_overlay/root/.profile index 9c13f65..e76e75f 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/root/.profile +++ b/buildroot-v86/board/v86/rootfs_overlay/root/.profile @@ -1,8 +1,3 @@ -alias enterVR='js "document.querySelector(\"a-scene\").enterVR()"' -alias enterAR='js "document.querySelector(\"a-scene\").enterAR()"' -alias exitVR='js "document.querySelector(\"a-scene\").enterVR()"' -alias exitAR='js "document.querySelector(\"a-scene\").enterAR()"' - # (new)user friendlyness alias vi='echo -e "HINT: type :q (and press enter) to quit\n[press a key]";read;vi'; alias mg='echo -e "HINT: type Ctrl+c Ctrl-x to quit\n[press a key]";read;mg'; diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-ar b/buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-ar new file mode 100755 index 0000000..c2eb0d8 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-ar @@ -0,0 +1,2 @@ +#!/bin/js +document.querySelector("a-scene").enterAR() diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-vr b/buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-vr new file mode 100755 index 0000000..2de217b --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/enter-vr @@ -0,0 +1,2 @@ +#!/bin/js +document.querySelector("a-scene").enterVR() diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-ar b/buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-ar new file mode 100755 index 0000000..238069b --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-ar @@ -0,0 +1,2 @@ +#!/bin/js +document.querySelector("a-scene").exitAR() diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-vr b/buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-vr new file mode 100755 index 0000000..be8b86c --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/exit-vr @@ -0,0 +1,2 @@ +#!/bin/js +document.querySelector("a-scene").exitVR() diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld index 10546c2..e74b7d4 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld @@ -1,2 +1,2 @@ #!/bin/sh -echo hook.d/alert/yo: yo $* +echo "$@" diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.awk b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.awk index b12e508..bd1e05b 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.awk +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.awk @@ -1,4 +1,4 @@ #!/usr/bin/awk -f BEGIN{ - print "hook.d/alert/yo.awk: yo " ARGV[1] + print( ARGV[0] " " ARGV[1] " " ARGV[2] ) } diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.js b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.js index 4b0c500..f853370 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.js +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.js @@ -1,3 +1,4 @@ #!/bin/js -str = "hook.d/alert/yo.js yo"+args.slice(1).join(' ') -alert(str) +msg = args.join(' ') +console.log(msg) +//alert(msg) diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.lua b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.lua index f1ffb8e..93d0627 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.lua +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.lua @@ -1,2 +1,4 @@ #!/usr/bin/env lua -print("hook.d/alert/yo.lua: yo " .. args[1]) +local msg = table.concat( arg, " ") +print( msg ) -- to stdout +--os.execute( "logger '" .. msg .. "'") -- to logs (/var/logs/messages) diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.py b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.py index d713075..373d2c8 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.py +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/helloworld.py @@ -1,3 +1,7 @@ #!/usr/bin/env micropython import sys -print("hook.d/alert/yo.py: "+sys.argv[1]) +import os +msg = sys.argv[0] + ": " + " ".join(sys.argv) + +print(msg) # to stdout +#os.system("logger '"+ msg +"'") # to logs (/var/log/messages) diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/upload b/buildroot-v86/board/v86/rootfs_overlay/root/bin/upload new file mode 100755 index 0000000..b8cae1b --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/upload @@ -0,0 +1,13 @@ +#!/bin/js +// this allows opening a file upload popup, to upload to the clipboard. +// because not all input devices (handcontrols) present copy/paste contextmenus +// or file drag/drop functionality +// +const isoterminal = document.querySelector('[isoterminal]').components.isoterminal +const upload = isoterminal.vt100.upload +const scene = document.querySelector('a-scene') + +// trigger file input +scene.exitVR() +upload.click() +return "[i] files are uploaded in /mnt/clipboard\n" diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/watchfs b/buildroot-v86/board/v86/rootfs_overlay/root/bin/watchfs index 21e9157..7a25f2a 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/root/bin/watchfs +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/watchfs @@ -1,9 +1,9 @@ #!/bin/sh -infinite inotifyd echo /mnt/root | awk ' +infinite inotifyd echo /root | awk ' # listen for writes to rootdir and send them to DOM - /^[ne] \/mnt\/root index\.html/ { system("cat "$2"/"$3" | grep -vE \"^#!\" > /dev/browser/html") } - /^[ne] \/mnt\/root index\.js/ { system("cat "$2"/"$3" | grep -vE \"^#!\" > /dev/browser/js") } + /^[wne] \/root index\.html/ { system("cat "$2"/"$3" | grep -vE \"^#!\" > /dev/browser/html") } + /^[wne] \/root index\.js/ { system("cat "$2"/"$3" | grep -vE \"^#!\" > /dev/browser/js") } ' diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.awk b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.awk new file mode 120000 index 0000000..da3be58 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.awk @@ -0,0 +1 @@ +../../bin/helloworld.awk \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.js b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.js new file mode 120000 index 0000000..da68ab1 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.js @@ -0,0 +1 @@ +../../bin/helloworld.js \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.lua b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.lua new file mode 120000 index 0000000..082d2c0 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.lua @@ -0,0 +1 @@ +../../bin/helloworld.lua \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.py b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.py new file mode 120000 index 0000000..a97856a --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.py @@ -0,0 +1 @@ +../../bin/helloworld.py \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.sh b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.sh new file mode 100755 index 0000000..6d15934 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/clipboard/receive.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# usage: hook clipboard foo.mp3 [audio/mpeg] +# this forwards the hook to mimetype or filetype +source /etc/profile.sh + +file="$1" +ext="${file##*.}" +mimetype="$2" + +if test -n "$mimetype"; then + hook mimetype/"$mimetype" "$file" +else + hook filetype $ext "$file" +fi diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/.mp4/play b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/filetype/mp4/play similarity index 100% rename from buildroot-v86/board/v86/rootfs_overlay/root/hook.d/.mp4/play rename to buildroot-v86/board/v86/rootfs_overlay/root/hook.d/filetype/mp4/play diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/filetype/txt/import-to-aframe b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/filetype/txt/import-to-aframe new file mode 100755 index 0000000..60cac44 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/filetype/txt/import-to-aframe @@ -0,0 +1,6 @@ +#!/bin/sh +# usage: import-to-aframe + +str="$(cat "$1" | sed ':a;N;$!ba;s/\n/\\n/g' )" # escape linebreaks + +echo "" >> /root/index.html diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/audio/mpeg b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/audio/mpeg new file mode 120000 index 0000000..d7c90ad --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/audio/mpeg @@ -0,0 +1 @@ +../../filetype/mp3 \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-aframe b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-aframe new file mode 100755 index 0000000..60cac44 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-aframe @@ -0,0 +1,6 @@ +#!/bin/sh +# usage: import-to-aframe + +str="$(cat "$1" | sed ':a;N;$!ba;s/\n/\\n/g' )" # escape linebreaks + +echo "" >> /root/index.html diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-scene b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-scene new file mode 100755 index 0000000..db72fc1 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/model/gltf-binary/import-to-scene @@ -0,0 +1,2 @@ +#!/bin/sh +logger "*TODO*: importing to scene" diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/aframe/import-to-aframe b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/aframe/import-to-aframe new file mode 100755 index 0000000..455ab9d --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/aframe/import-to-aframe @@ -0,0 +1,5 @@ +#!/bin/sh +# usage: import-to-aframe + +# *FIXME* need consent +cat "$1" >> /root/index.html diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.aframe b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.aframe new file mode 100755 index 0000000..dd2c717 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.aframe @@ -0,0 +1,9 @@ +#!/bin/sh +source /etc/profile.sh +file="$1" + +# naive javascript detector +grep ' /dev/null && { + cat "$file" | grep -vE '( "$file".aframe + hook mimetype/text/aframe "$file".aframe +} diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.html b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.html new file mode 100755 index 0000000..49c147b --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.html @@ -0,0 +1,8 @@ +#!/bin/sh +source /etc/profile.sh +file="$1" + +# naive html detector +grep -E '(<\/a>|<\/div>)' "$file" &> /dev/null && { + hook mimetype/text/html "$file" +} diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.javascript b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.javascript new file mode 100755 index 0000000..8b7dc2e --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.javascript @@ -0,0 +1,8 @@ +#!/bin/sh +source /etc/profile.sh +file="$1" + +# naive javascript detector +grep -E '[a-zA-Z]\(' "$file" &> /dev/null && { + hook mimetype/text/javascript "$file" +} diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/html/eval b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/html/eval new file mode 100644 index 0000000..3bd060c --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/html/eval @@ -0,0 +1,5 @@ +#!/bin/sh + +# warning: to activate below make this file executable at own risk + +cat $1 | grep -vE "(> /root/index.html diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/import-to-aframe b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/import-to-aframe new file mode 120000 index 0000000..ef00ccd --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/import-to-aframe @@ -0,0 +1 @@ +plain/import-to-aframe \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/javascript/eval b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/javascript/eval new file mode 100644 index 0000000..f48e26f --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/javascript/eval @@ -0,0 +1,5 @@ +#!/bin/sh + +# warning: to activate below make this file executable at own risk + +js "$(cat $1)" diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/plain b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/plain new file mode 120000 index 0000000..cb1214d --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/plain @@ -0,0 +1 @@ +../../filetype/txt \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/video/mp4 b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/video/mp4 new file mode 120000 index 0000000..cdd57a7 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/video/mp4 @@ -0,0 +1 @@ +../../filetype/mp4 \ No newline at end of file diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/manual.md b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md index 05deb4d..9602047 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/root/manual.md +++ b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md @@ -71,6 +71,12 @@ The following files are loaded during boot (via `/etc/profile`) ```javascript const term = document.querySelector('[isoterminal]').components.isoterminal.term term.exec("ls -la") + +// interact directly with files +await term.worker.create_file("hello.txt", term.convert.toUint8Array("hello") ) +await term.worker.update_file("hello.txt", term.convert.toUint8Array("hi") ) +await term.worker.append_file("hello.txt", term.convert.toUint8Array("world") ) +const f = await term.worker.read_file("hello.txt") ``` # Calling javascript from terminal @@ -82,11 +88,43 @@ Various options: 3. Run `jsh alert hello` in the shell 4. Run `jsh` to start an interactive shell -# Hybrid Terminal/Browser Events +# Hooks -Events are automatically triggering scripts in `/root/hook.d/{eventname}/*` +Hooks are filebased events. +Why filebased? Well first, because unixy is sexy. +Second: it allows reacting to events in a hackable way via polyglot scripts. -> They can be triggered by the following ways +> TLDR: events are automatically triggering scripts found in `/root/hook.d/{eventname}/*` + +**OS related hooks** + +| hook location | when is this hook called? | +|-------------------------|-------------------------------------------------------| +| hook.d/wakeup/* | restoring xrsh session from cache | +| hook.d/save/* | saving xrsh session to cache | +| hook.d/alert/* | when 'alert'-function is used in shell | +| hook.d/prompt/* | when 'prompt'-function is used in shell | +| hook.d/confirm/* | when 'confirm'-function is used in shell | + +**Clipboard related hooks** + +| hook.d/clipboard/* | user copy-pastes clipboard or (drops) file into scene | +| hook.d/mimetype/* | clipboard activity (hook.d/clipboard/forwarder) | +| hook.d/filetype/* | clipboard activity (hook.d/clipboard/forwarder) | + +**XR related hooks** + +| hook location | when is this hook called? | +|-------------------------|-------------------------------------------------------| +| hook.d/exit-vr/* | user exits immersive WebXR [VR] mode | +| hook.d/enter-vr/* | user enters immersive WebXR [VR] mode | +| hook.d/exit-ar/* | user exits immersive WebXR [AR] mode | +| hook.d/enter-ar/* | user enters immersive WebXR [AR] mode | + +> How to trigger them? + +Well the isoterminal-AFRAME component triggers them automatically for you. +But you can do it manually too: 1. from shellscript: `hook myevent` (will trigger **executable** files in /root/hook.d/myevent) 2. from javascript: `isoterminal.exec("hook myevent")` (idem)