javascript bridge fixes
This commit is contained in:
parent
3c3340144f
commit
54c547fe4d
|
@ -0,0 +1,3 @@
|
||||||
|
com/isoterminal/mnt/hook.d
|
||||||
|
com/isoterminal/mnt/console*
|
||||||
|
com/isoterminal/mnt/dev/*
|
|
@ -174,12 +174,9 @@ AFRAME.registerComponent('isoterminal', {
|
||||||
const files = [
|
const files = [
|
||||||
"com/isoterminal/mnt/js",
|
"com/isoterminal/mnt/js",
|
||||||
"com/isoterminal/mnt/jsh",
|
"com/isoterminal/mnt/jsh",
|
||||||
"com/isoterminal/mnt/confirm",
|
|
||||||
"com/isoterminal/mnt/prompt",
|
|
||||||
"com/isoterminal/mnt/alert",
|
|
||||||
"com/isoterminal/mnt/hook",
|
|
||||||
"com/isoterminal/mnt/xrsh",
|
"com/isoterminal/mnt/xrsh",
|
||||||
"com/isoterminal/mnt/profile",
|
"com/isoterminal/mnt/profile",
|
||||||
|
"com/isoterminal/mnt/profile.sh",
|
||||||
"com/isoterminal/mnt/profile.xrsh",
|
"com/isoterminal/mnt/profile.xrsh",
|
||||||
"com/isoterminal/mnt/profile.js",
|
"com/isoterminal/mnt/profile.js",
|
||||||
"com/isoterminal/mnt/motd",
|
"com/isoterminal/mnt/motd",
|
||||||
|
@ -282,12 +279,13 @@ AFRAME.registerComponent('isoterminal', {
|
||||||
if( typeof document.location[i] == 'string' )
|
if( typeof document.location[i] == 'string' )
|
||||||
env.push( 'export '+String(i).toUpperCase()+'="'+document.location[i]+'"')
|
env.push( 'export '+String(i).toUpperCase()+'="'+document.location[i]+'"')
|
||||||
}
|
}
|
||||||
env.map( (e) => emulator.serial0_send(`echo '${e}' >> /mnt/profile\n`) )
|
await emulator.create_file("profile.browser", this.toUint8Array( env.join('\n') ) )
|
||||||
let boot = `source /mnt/profile ; js "$(cat /mnt/profile.js)"`
|
let boot = `source /mnt/profile ; js "$(cat /mnt/profile.js)"`
|
||||||
// exec hash as extra boot cmd
|
// exec hash as extra boot cmd
|
||||||
if( document.location.hash.length > 1 ){
|
if( document.location.hash.length > 1 ){
|
||||||
boot += ` && cmd='${decodeURI(document.location.hash.substr(1))}' && $cmd`
|
boot += ` ; cmd='${decodeURI(document.location.hash.substr(1))}' && $cmd`
|
||||||
}
|
}
|
||||||
|
console.dir(boot)
|
||||||
emulator.serial0_send(boot+"\n")
|
emulator.serial0_send(boot+"\n")
|
||||||
instance.winbox.maximize()
|
instance.winbox.maximize()
|
||||||
emulator.serial_adapter.term.focus()
|
emulator.serial_adapter.term.focus()
|
||||||
|
@ -368,7 +366,7 @@ AFRAME.registerComponent('isoterminal', {
|
||||||
if( instance.dom.emulator && instance.dom.emulator.serial_adapter ){
|
if( instance.dom.emulator && instance.dom.emulator.serial_adapter ){
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
this.autoResize(instance.dom.emulator.serial_adapter.term,instance,-5)
|
this.autoResize(instance.dom.emulator.serial_adapter.term,instance,-5)
|
||||||
},500) // wait for resize anim
|
},800) // wait for resize anim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance.addEventListener('window.onresize', resize )
|
instance.addEventListener('window.onresize', resize )
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
title=$1
|
|
||||||
shift
|
|
||||||
msg="$*"
|
|
||||||
echo "[38;5;165m$title $(printf "\033[0m")$msg"
|
|
||||||
hook alert $title "$msg"
|
|
|
@ -1,4 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
read -p "$(printf "\033[0m")[?] [38;5;165m$1 [y/n] $(printf "\033[0m")" y
|
|
||||||
test $y = y && echo true && exit
|
|
||||||
echo false
|
|
|
@ -1,11 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
test -z $1 && { echo "usage: hook <cmd_or_jsfunction> [args]"; exit 0; }
|
|
||||||
cmd=$1
|
|
||||||
shift
|
|
||||||
|
|
||||||
test -d ~/hook.d/$cmd && {
|
|
||||||
find ~/hook.d/$cmd/ -type f -executable | while read hook; do
|
|
||||||
{ $hook "$@" || true; } | awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1'
|
|
||||||
done
|
|
||||||
}
|
|
|
@ -3,6 +3,8 @@
|
||||||
#
|
#
|
||||||
# 'jsh prompt question answer' executes: js prompt('question','answer') )
|
# 'jsh prompt question answer' executes: js prompt('question','answer') )
|
||||||
|
|
||||||
|
source /mnt/profile.sh
|
||||||
|
|
||||||
to_js(){
|
to_js(){
|
||||||
printf "%s(" "$1"
|
printf "%s(" "$1"
|
||||||
shift
|
shift
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
[38;5;165mOpen, local-first, unix hackable & selfcontained XR apps.
|
[38;5;165mOpen, local-first, unix hackable & selfcontained XR apps.
|
||||||
|
|
||||||
credits: all FOSS devs | @lvk@mastodon.online
|
credits: NLnet | @nlnet@nlnet.nl https://nlnet.nl/project
|
||||||
copy.sh (v86) | @utopiah@mastodon.pirateparty.be
|
all FOSS devs | copy.sh (v86) aframe.io (AFRAME)
|
||||||
|
Leon van Kammen | @lvk@mastodon.online
|
||||||
|
Fabien Benetou | @utopiah@mastodon.pirateparty.be
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,30 @@
|
||||||
|
# source URL data from v86 (file created by v86 during boot)
|
||||||
|
test -f /mnt/profile.browser && source /mnt/profile.browser
|
||||||
|
|
||||||
# source xrsh env
|
# source xrsh env
|
||||||
source /mnt/profile.xrsh
|
source /mnt/profile.xrsh
|
||||||
|
|
||||||
|
# source shell functions
|
||||||
|
source /mnt/profile.sh
|
||||||
|
|
||||||
|
# source js functions
|
||||||
|
js "$(cat ~/.profile.js)"
|
||||||
|
|
||||||
## forward not-found commands to javascript (via jsh)
|
## forward not-found commands to javascript (via jsh)
|
||||||
command_not_found_handle(){
|
command_not_found_handle(){
|
||||||
echo "$1 not found, did you mean $1(...) (javascript?)"
|
echo "$1 not found, did you mean $1(...) (javascript?)"
|
||||||
alert '[XRSH TIPS]'
|
echo ""
|
||||||
alert 'js console: ' "type 'jsh'"
|
echo 'TIPS'
|
||||||
alert 'js shellfunction:' "type 'alias $1=\"jsh $1\"' to run '$1 yo' as $1('yo')"
|
echo '----'
|
||||||
alert 'js logging: ' "type 'echo 0 > /dev/browser/console.tty' to disable"
|
echo 'js console: ' "type 'jsh'"
|
||||||
alert 'js capture log: ' "type 'tail -f /dev/browser/console'"
|
echo 'js shellfunction:' "type 'alias $1=\"jsh $1\"' to run '$1 yo' as $1('yo')"
|
||||||
alert 'jsh<->sh hooks: ' "type 'chmod +x ~/hook.d/*/* && alert helloworld'"
|
echo 'js logging: ' "type 'echo 0 > /dev/browser/console.tty' to disable"
|
||||||
|
echo 'js capture log: ' "type 'tail -f /dev/browser/console'"
|
||||||
|
echo 'jsh<->sh hooks: ' "type 'chmod +x ~/hook.d/*/* && alert helloworld'"
|
||||||
}
|
}
|
||||||
|
|
||||||
resize
|
resize
|
||||||
test $HOSTNAME = localhost || clear
|
#test $HOSTNAME = localhost || clear
|
||||||
cat /mnt/motd
|
cat /mnt/motd
|
||||||
export PATH=$PATH:/mnt
|
export PATH=$PATH:/mnt
|
||||||
export PS1="\n[38;5;57mx[38;5;93mr[38;5;129ms[38;5;165mh [38;5;201m# \033[0m"
|
export PS1="\n[38;5;57mx[38;5;93mr[38;5;129ms[38;5;165mh [38;5;201m# \033[0m"
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
hook(){
|
||||||
|
test -z "$1" && { echo "usage: hook <cmd_or_jsfunction> [args]"; return 0; }
|
||||||
|
cmd=$1
|
||||||
|
shift
|
||||||
|
test -d ~/hook.d/$cmd && {
|
||||||
|
find ~/hook.d/$cmd/ -type f -executable | while read hook; do
|
||||||
|
{ $hook "$@" || true; } | awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1'
|
||||||
|
done
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
alert(){
|
||||||
|
test -z "$1" && { echo "usage: alert <title> <message>"; return 0; }
|
||||||
|
title=$1
|
||||||
|
test -z "$1" || shift
|
||||||
|
msg="$*"
|
||||||
|
printf "[38;5;165m%s \033[0m%s\n" "$title" "$msg"
|
||||||
|
hook alert $title "$msg"
|
||||||
|
}
|
||||||
|
|
||||||
|
confirm(){
|
||||||
|
test -z "$1" && { echo "usage: confirm <question>"; return 0; }
|
||||||
|
read -p "$(printf "\033[0m")[?] [38;5;165m$1 [y/n] $(printf "\033[0m")" y
|
||||||
|
test $y = y && echo true && return 0
|
||||||
|
test $y = y || echo false
|
||||||
|
hook confirm $1 $y
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt(){
|
||||||
|
test -z "$1" && { echo "usage: prompt <question> [answer_default]"; return 0; }
|
||||||
|
test -n "$2" && answer="[$2] " && answer_fallback="$2"
|
||||||
|
read -p "$(printf "\033[0m")[?] [38;5;165m$1: $answer $(printf "\033[0m")" answer
|
||||||
|
test -z "$answer" && answer="$answer_fallback"
|
||||||
|
echo "$answer"
|
||||||
|
hook prompt $1 $answer
|
||||||
|
}
|
|
@ -3,12 +3,20 @@
|
||||||
test -d /dev/browser || {
|
test -d /dev/browser || {
|
||||||
|
|
||||||
setup_binaries(){
|
setup_binaries(){
|
||||||
for bin in /mnt/prompt /mnt/alert /mnt/confirm /mnt/hook /mnt/js* /mnt/v86pipe /mnt/xrsh; do
|
for bin in /mnt/js* /mnt/v86pipe /mnt/xrsh; do
|
||||||
chmod +x $bin
|
chmod +x $bin
|
||||||
ln -s $bin /bin/.
|
ln -s $bin /bin/.
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup_links(){
|
||||||
|
ln -s /mnt/profile ~/.profile
|
||||||
|
ln -s /mnt/profile.js ~/.profile.js
|
||||||
|
ln -s /mnt/profile.browser ~/.profile.browser
|
||||||
|
ln -s /mnt/profile.sh ~/.profile.sh
|
||||||
|
ln -s /mnt/motd ~/.motd
|
||||||
|
}
|
||||||
|
|
||||||
setup_browser_dev(){
|
setup_browser_dev(){
|
||||||
mkdir -p /mnt/dev/browser
|
mkdir -p /mnt/dev/browser
|
||||||
touch /mnt/dev/browser/js
|
touch /mnt/dev/browser/js
|
||||||
|
@ -35,7 +43,7 @@ test -d /dev/browser || {
|
||||||
|
|
||||||
setup_network(){
|
setup_network(){
|
||||||
test -n "$BROWSER" || return 0
|
test -n "$BROWSER" || return 0
|
||||||
mount -a
|
#mount -a
|
||||||
udhcpc 1>>/var/log/network.log 2>>/var/log/network.log &
|
udhcpc 1>>/var/log/network.log 2>>/var/log/network.log &
|
||||||
echo 0 > /proc/sys/kernel/printk
|
echo 0 > /proc/sys/kernel/printk
|
||||||
}
|
}
|
||||||
|
@ -43,6 +51,6 @@ test -d /dev/browser || {
|
||||||
setup_binaries
|
setup_binaries
|
||||||
setup_browser_dev
|
setup_browser_dev
|
||||||
setup_hook_dirs
|
setup_hook_dirs
|
||||||
|
setup_links
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
read -p "$(printf "\033[0m")[?] [38;5;165m$1: $(printf "\033[0m")" answer
|
|
||||||
echo "$answer"
|
|
Loading…
Reference in New Issue