trimming the fat..going for a xrsh-driven way to include files
This commit is contained in:
parent
31b6f99050
commit
b1bbaac311
|
@ -7,11 +7,13 @@ if( !AFRAME.components['html-as-textre-in-xr'] ){
|
||||||
|
|
||||||
dependencies:{
|
dependencies:{
|
||||||
html: "https://unpkg.com/aframe-htmlmesh@2.1.0/build/aframe-html.js", // html to AFRAME
|
html: "https://unpkg.com/aframe-htmlmesh@2.1.0/build/aframe-html.js", // html to AFRAME
|
||||||
|
//html: "https://coderofsalvation.github.io/aframe-htmlmesh/build/aframe-html.js"
|
||||||
|
//html: "com/aframe-html.js"
|
||||||
},
|
},
|
||||||
|
|
||||||
init: async function () {
|
init: async function () {
|
||||||
let s = await AFRAME.utils.require(this.dependencies)
|
let s = await AFRAME.utils.require(this.dependencies)
|
||||||
this.el.setAttribute("html",`html: ${this.data.domid}; cursor:#cursor`)
|
this.el.setAttribute("html",`html: ${this.data.domid}; cursor:#cursor; xrlayer: true`)
|
||||||
this.el.setAttribute("visible", AFRAME.utils.XD() == '3D' ? 'true' : 'false' )
|
this.el.setAttribute("visible", AFRAME.utils.XD() == '3D' ? 'true' : 'false' )
|
||||||
this.el.setAttribute("position", AFRAME.utils.XD.getPositionInFrontOfCamera(0.5) )
|
this.el.setAttribute("position", AFRAME.utils.XD.getPositionInFrontOfCamera(0.5) )
|
||||||
},
|
},
|
||||||
|
@ -94,9 +96,6 @@ if( !AFRAME.components['html-as-textre-in-xr'] ){
|
||||||
this.sceneEl.addEventListener('2D', () => this.showElements(false) )
|
this.sceneEl.addEventListener('2D', () => this.showElements(false) )
|
||||||
this.sceneEl.addEventListener('3D', () => this.showElements(true) )
|
this.sceneEl.addEventListener('3D', () => this.showElements(true) )
|
||||||
|
|
||||||
// toggle immersive with ESCAPE
|
|
||||||
//document.body.addEventListener('keydown', (e) => e.key == 'Escape' && this.toggle() )
|
|
||||||
|
|
||||||
document.head.innerHTML += `<style type="text/css">
|
document.head.innerHTML += `<style type="text/css">
|
||||||
.XR #toggle_overlay{
|
.XR #toggle_overlay{
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|
|
@ -39,16 +39,20 @@ if( typeof AFRAME != 'undefined '){
|
||||||
|
|
||||||
init: async function(){
|
init: async function(){
|
||||||
this.el.object3D.visible = false
|
this.el.object3D.visible = false
|
||||||
|
this.initTerminal(true)
|
||||||
},
|
},
|
||||||
|
|
||||||
requires:{
|
requires:{
|
||||||
'window': "com/window.js",
|
com: "com/dom.js",
|
||||||
|
window: "com/window.js",
|
||||||
xtermjs: "https://unpkg.com/@xterm/xterm@5.5.0/lib/xterm.js",
|
xtermjs: "https://unpkg.com/@xterm/xterm@5.5.0/lib/xterm.js",
|
||||||
xtermcss: "https://unpkg.com/@xterm/xterm@5.5.0/css/xterm.css",
|
xtermcss: "https://unpkg.com/@xterm/xterm@5.5.0/css/xterm.css",
|
||||||
v86: "com/isoterminal/libv86.js",
|
v86: "com/isoterminal/libv86.js",
|
||||||
|
// allow xrsh to selfcontain scene + itself
|
||||||
|
xhook: "https://jpillora.com/xhook/dist/xhook.min.js",
|
||||||
|
selfcontain: "com/selfcontainer.js",
|
||||||
// html to texture
|
// html to texture
|
||||||
htmlinxr: "com/html-as-texture-in-xr.js",
|
htmlinxr: "com/html-as-texture-in-xr.js",
|
||||||
html: "https://unpkg.com/aframe-htmlmesh@2.1.0/build/aframe-html.js", // html to AFRAME
|
|
||||||
// isoterminal features
|
// isoterminal features
|
||||||
core: "com/isoterminal/core.js",
|
core: "com/isoterminal/core.js",
|
||||||
utils_9p: "com/isoterminal/feat/9pfs_utils.js",
|
utils_9p: "com/isoterminal/feat/9pfs_utils.js",
|
||||||
|
@ -107,23 +111,31 @@ if( typeof AFRAME != 'undefined '){
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
|
|
||||||
initTerminal: async function(){
|
initTerminal: async function(singleton){
|
||||||
if( this.instance ){
|
|
||||||
const el = document.querySelector('.isoterminal')
|
|
||||||
return console.warn('TODO: allow multiple terminals (see v86 examples)')
|
|
||||||
}
|
|
||||||
|
|
||||||
let s = await AFRAME.utils.require(this.requires)
|
let s = await AFRAME.utils.require(this.requires)
|
||||||
|
|
||||||
// instance this component
|
this.el.setAttribute("selfcontainer","")
|
||||||
const instance = this.instance = this.el.cloneNode(false)
|
|
||||||
|
// *DISABLED* instance this component
|
||||||
|
// rason: we only need one term for now (more = too cpu heavy)
|
||||||
|
let instance
|
||||||
|
if( singleton ){
|
||||||
|
instance = this.el
|
||||||
|
}else{
|
||||||
|
if( this.instance ){
|
||||||
|
const el = document.querySelector('.isoterminal')
|
||||||
|
return console.warn('TODO: allow multiple terminals for future beefy devices(see v86 examples)')
|
||||||
|
}
|
||||||
|
instance = this.instance = this.el.cloneNode(false)
|
||||||
this.el.sceneEl.appendChild( instance )
|
this.el.sceneEl.appendChild( instance )
|
||||||
|
}
|
||||||
|
|
||||||
// init isoterminal
|
// init isoterminal
|
||||||
this.isoterminal = new ISOTerminal()
|
this.isoterminal = new ISOTerminal()
|
||||||
|
|
||||||
instance.addEventListener('DOMready', () => {
|
instance.addEventListener('DOMready', () => {
|
||||||
instance.setAttribute("window", `title: ${this.data.iso}; uid: ${instance.uid}; attach: #overlay; dom: #${instance.dom.id}`)
|
instance.setAttribute("window", `title: xrsh [booting linux iso..]; uid: ${instance.uid}; attach: #overlay; dom: #${instance.dom.id}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
instance.addEventListener('window.oncreate', (e) => {
|
instance.addEventListener('window.oncreate', (e) => {
|
||||||
|
@ -166,7 +178,11 @@ if( typeof AFRAME != 'undefined '){
|
||||||
|
|
||||||
instance.setAttribute("dom", "")
|
instance.setAttribute("dom", "")
|
||||||
|
|
||||||
const focus = () => this.isoterminal.emulator.serial_adapter.term.focus()
|
const focus = () => {
|
||||||
|
if( this.isoterminal?.emulator?.serial_adapter?.focus ){
|
||||||
|
this.isoterminal.emulator.serial_adapter.term.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
instance.addEventListener('obbcollisionstarted', focus )
|
instance.addEventListener('obbcollisionstarted', focus )
|
||||||
this.el.sceneEl.addEventListener('enter-vr', focus )
|
this.el.sceneEl.addEventListener('enter-vr', focus )
|
||||||
this.el.sceneEl.addEventListener('enter-ar', focus )
|
this.el.sceneEl.addEventListener('enter-ar', focus )
|
||||||
|
|
|
@ -80,16 +80,14 @@ ISOTerminal.prototype.runISO = function(opts){
|
||||||
let loadmsg = loading[ Math.floor(Math.random()*1000) % loading.length-1 ]
|
let loadmsg = loading[ Math.floor(Math.random()*1000) % loading.length-1 ]
|
||||||
this.emit('status',loadmsg)
|
this.emit('status',loadmsg)
|
||||||
|
|
||||||
let motd = "\n\r"
|
// replace welcome message https://github.com/copy/v86/blob/3c77b98bc4bc7a5d51a2056ea73d7666ca50fc9d/src/browser/serial.js#L231
|
||||||
motd += "[38;5;57m " + ' ____ _____________ _________ ___ ___ ' + "\n\r"
|
let welcome = "This is the serial console. Whatever you type or paste here will be sent to COM1"
|
||||||
motd += "[38;5;93m " + ' \\ \\/ /\\______ \\/ _____// | \\ ' + "\n\r"
|
|
||||||
motd += "[38;5;93m " + ' \\ / | _/\\_____ \\/ ~ \\ ' + "\n\r"
|
let motd = "\r[38;5;129m"
|
||||||
motd += "[38;5;129m " + ' / \\ | | \\/ \\ Y / ' + "\n\r"
|
let msg = `${loadmsg}, please wait..`
|
||||||
motd += "[38;5;165m " + ' /___/\\ \\ |____|_ /_______ /\\___|_ / ' + "\n\r"
|
while( msg.length < welcome.length ) msg += " "
|
||||||
motd += "[38;5;201m " + ' \\_/ \\/ \\/ \\/ ' + "\n\r"
|
msg += "\n"
|
||||||
motd += " \n\r"
|
motd += msg+"\033[0m"
|
||||||
motd += `${loadmsg}, please wait..\n\r\n\r`
|
|
||||||
motd += "\033[0m"
|
|
||||||
|
|
||||||
const files = [
|
const files = [
|
||||||
"com/isoterminal/mnt/js",
|
"com/isoterminal/mnt/js",
|
||||||
|
@ -108,12 +106,6 @@ ISOTerminal.prototype.runISO = function(opts){
|
||||||
emulator.serial_adapter.term.clear()
|
emulator.serial_adapter.term.clear()
|
||||||
emulator.serial_adapter.term.write(motd)
|
emulator.serial_adapter.term.write(motd)
|
||||||
|
|
||||||
emulator.create_file("motd", this.toUint8Array(motd) )
|
|
||||||
emulator.create_file("js", this.toUint8Array(`#!/bin/sh
|
|
||||||
cat /mnt/motd
|
|
||||||
cat > /dev/null
|
|
||||||
`))
|
|
||||||
|
|
||||||
let p = files.map( (f) => fetch(f) )
|
let p = files.map( (f) => fetch(f) )
|
||||||
Promise.all(p)
|
Promise.all(p)
|
||||||
.then( (files) => {
|
.then( (files) => {
|
||||||
|
|
|
@ -10,7 +10,7 @@ ISOTerminal.prototype.boot = async function(){
|
||||||
env.push( 'export '+String(i).toUpperCase()+'="'+document.location[i]+'"')
|
env.push( 'export '+String(i).toUpperCase()+'="'+document.location[i]+'"')
|
||||||
}
|
}
|
||||||
await this.emulator.create_file("profile.browser", this.toUint8Array( env.join('\n') ) )
|
await this.emulator.create_file("profile.browser", this.toUint8Array( env.join('\n') ) )
|
||||||
let boot = `source /mnt/profile`
|
let boot = `clear ; echo 'preparing xrsh env..'; source /mnt/profile`
|
||||||
// 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`
|
||||||
|
|
|
@ -23,6 +23,7 @@ ISOTerminal.prototype.redirectConsole = function(handler){
|
||||||
handler(textArg+'\n','\x1b[38;5;208mwarn\x1b[0m');
|
handler(textArg+'\n','\x1b[38;5;208mwarn\x1b[0m');
|
||||||
err.apply(log, args);
|
err.apply(log, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISOTerminal.addEventListener('emulator-started', function(){
|
ISOTerminal.addEventListener('emulator-started', function(){
|
||||||
|
@ -39,6 +40,16 @@ ISOTerminal.addEventListener('emulator-started', function(){
|
||||||
emulator.fs9p.append_file( "console", str )
|
emulator.fs9p.append_file( "console", str )
|
||||||
})
|
})
|
||||||
|
|
||||||
|
window.addEventListener('error', function(event) {
|
||||||
|
console.error(event.filename+":"+event.lineno+":"+event.colno)
|
||||||
|
console.error(event.message);
|
||||||
|
console.error(event.error);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('unhandledrejection', function(event) {
|
||||||
|
console.error('Unhandled promise rejection:', event.reason);
|
||||||
|
});
|
||||||
|
|
||||||
// enable/disable logging file (echo 1 > mnt/console.tty)
|
// enable/disable logging file (echo 1 > mnt/console.tty)
|
||||||
this.readFromPipe( '/mnt/console.tty', (data) => {
|
this.readFromPipe( '/mnt/console.tty', (data) => {
|
||||||
emulator.log_to_tty = ( String(data).trim() == '1')
|
emulator.log_to_tty = ( String(data).trim() == '1')
|
||||||
|
|
|
@ -24,6 +24,8 @@ ISOTerminal.prototype.xtermInit = function(){
|
||||||
|
|
||||||
this.addEventListener('emulator-started', function(){
|
this.addEventListener('emulator-started', function(){
|
||||||
this.emulator.serial_adapter.term.element.querySelector('.xterm-viewport').style.background = 'transparent'
|
this.emulator.serial_adapter.term.element.querySelector('.xterm-viewport').style.background = 'transparent'
|
||||||
|
// toggle immersive with ESCAPE
|
||||||
|
//document.body.addEventListener('keydown', (e) => e.key == 'Escape' && this.emulator.serial_adapter.term.blur() )
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,9 @@ test -n "$BROWSER" || { alert warning "/dev/browser not active (are you running
|
||||||
javascript="$*"
|
javascript="$*"
|
||||||
|
|
||||||
# if we are run as shebang, use the file as input
|
# if we are run as shebang, use the file as input
|
||||||
case "$1" in
|
test -f "$1" && {
|
||||||
*/*) javascript="args = String('$*').split(' '); $(cat $1 | tail +2)"
|
javascript="args = String('$*').split(' '); $(cat $1 | tail +2)"
|
||||||
;;
|
}
|
||||||
esac
|
|
||||||
|
|
||||||
# below is not ideal
|
# below is not ideal
|
||||||
# first I tried /dev/ttyS* https://github.com/copy/v86/issues/530
|
# first I tried /dev/ttyS* https://github.com/copy/v86/issues/530
|
||||||
|
|
|
@ -12,7 +12,12 @@ source /mnt/profile.sh
|
||||||
|
|
||||||
## 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?)"
|
||||||
|
test -n "$ONBOARDING" && echo "[i] type 'help' for handy commands"
|
||||||
|
test -n "$ONBOARDING" || help
|
||||||
|
}
|
||||||
|
|
||||||
|
help(){
|
||||||
echo ""
|
echo ""
|
||||||
echo 'TIPS'
|
echo 'TIPS'
|
||||||
echo '----'
|
echo '----'
|
||||||
|
@ -23,6 +28,9 @@ command_not_found_handle(){
|
||||||
echo 'js console disable: ' "type 'echo 0 > /dev/browser/console.tty' to enable"
|
echo 'js console disable: ' "type 'echo 0 > /dev/browser/console.tty' to enable"
|
||||||
echo 'js capture console: ' "type 'tail -f /dev/browser/console'"
|
echo 'js capture console: ' "type 'tail -f /dev/browser/console'"
|
||||||
echo 'jsh<->sh hooks: ' "type 'chmod +x ~/hook.d/*/* && alert helloworld'"
|
echo 'jsh<->sh hooks: ' "type 'chmod +x ~/hook.d/*/* && alert helloworld'"
|
||||||
|
echo 'include file into page' "type 'require <url.js|css>'"
|
||||||
|
echo 'create AFRAME a-entity' "type 'a_entity <componentname> [...]"
|
||||||
|
ONBOARDING=1
|
||||||
}
|
}
|
||||||
|
|
||||||
resize
|
resize
|
||||||
|
|
|
@ -39,6 +39,19 @@ console(){
|
||||||
js 'return '$1
|
js 'return '$1
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(){
|
require(){
|
||||||
js ''
|
file=$(basename "$1")
|
||||||
|
js '(async () => {
|
||||||
|
await AFRAME.utils.require({"'$file'": "'$1'"})
|
||||||
|
})()'
|
||||||
|
}
|
||||||
|
|
||||||
|
a_entity(){
|
||||||
|
code="let el = document.createElement('a-entity')"
|
||||||
|
for i in "$@"; do
|
||||||
|
code="$code;\nel.setAttribute('$i','')\n";
|
||||||
|
done
|
||||||
|
code="document.querySelector('a-scene').appendChild(el)"
|
||||||
|
echo "$code"
|
||||||
|
js "$code"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue