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:{
|
||||
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 () {
|
||||
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("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('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">
|
||||
.XR #toggle_overlay{
|
||||
background: transparent;
|
||||
|
|
|
@ -39,16 +39,20 @@ if( typeof AFRAME != 'undefined '){
|
|||
|
||||
init: async function(){
|
||||
this.el.object3D.visible = false
|
||||
this.initTerminal(true)
|
||||
},
|
||||
|
||||
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",
|
||||
xtermcss: "https://unpkg.com/@xterm/xterm@5.5.0/css/xterm.css",
|
||||
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
|
||||
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
|
||||
core: "com/isoterminal/core.js",
|
||||
utils_9p: "com/isoterminal/feat/9pfs_utils.js",
|
||||
|
@ -107,23 +111,31 @@ if( typeof AFRAME != 'undefined '){
|
|||
`
|
||||
},
|
||||
|
||||
initTerminal: async function(){
|
||||
if( this.instance ){
|
||||
const el = document.querySelector('.isoterminal')
|
||||
return console.warn('TODO: allow multiple terminals (see v86 examples)')
|
||||
}
|
||||
initTerminal: async function(singleton){
|
||||
|
||||
let s = await AFRAME.utils.require(this.requires)
|
||||
|
||||
// instance this component
|
||||
const instance = this.instance = this.el.cloneNode(false)
|
||||
this.el.sceneEl.appendChild( instance )
|
||||
this.el.setAttribute("selfcontainer","")
|
||||
|
||||
// *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 )
|
||||
}
|
||||
|
||||
// init isoterminal
|
||||
this.isoterminal = new ISOTerminal()
|
||||
|
||||
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) => {
|
||||
|
@ -166,7 +178,11 @@ if( typeof AFRAME != 'undefined '){
|
|||
|
||||
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 )
|
||||
this.el.sceneEl.addEventListener('enter-vr', 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 ]
|
||||
this.emit('status',loadmsg)
|
||||
|
||||
let motd = "\n\r"
|
||||
motd += "[38;5;57m " + ' ____ _____________ _________ ___ ___ ' + "\n\r"
|
||||
motd += "[38;5;93m " + ' \\ \\/ /\\______ \\/ _____// | \\ ' + "\n\r"
|
||||
motd += "[38;5;93m " + ' \\ / | _/\\_____ \\/ ~ \\ ' + "\n\r"
|
||||
motd += "[38;5;129m " + ' / \\ | | \\/ \\ Y / ' + "\n\r"
|
||||
motd += "[38;5;165m " + ' /___/\\ \\ |____|_ /_______ /\\___|_ / ' + "\n\r"
|
||||
motd += "[38;5;201m " + ' \\_/ \\/ \\/ \\/ ' + "\n\r"
|
||||
motd += " \n\r"
|
||||
motd += `${loadmsg}, please wait..\n\r\n\r`
|
||||
motd += "\033[0m"
|
||||
// replace welcome message https://github.com/copy/v86/blob/3c77b98bc4bc7a5d51a2056ea73d7666ca50fc9d/src/browser/serial.js#L231
|
||||
let welcome = "This is the serial console. Whatever you type or paste here will be sent to COM1"
|
||||
|
||||
let motd = "\r[38;5;129m"
|
||||
let msg = `${loadmsg}, please wait..`
|
||||
while( msg.length < welcome.length ) msg += " "
|
||||
msg += "\n"
|
||||
motd += msg+"\033[0m"
|
||||
|
||||
const files = [
|
||||
"com/isoterminal/mnt/js",
|
||||
|
@ -108,12 +106,6 @@ ISOTerminal.prototype.runISO = function(opts){
|
|||
emulator.serial_adapter.term.clear()
|
||||
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) )
|
||||
Promise.all(p)
|
||||
.then( (files) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ ISOTerminal.prototype.boot = async function(){
|
|||
env.push( 'export '+String(i).toUpperCase()+'="'+document.location[i]+'"')
|
||||
}
|
||||
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
|
||||
if( document.location.hash.length > 1 ){
|
||||
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');
|
||||
err.apply(log, args);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
ISOTerminal.addEventListener('emulator-started', function(){
|
||||
|
@ -39,6 +40,16 @@ ISOTerminal.addEventListener('emulator-started', function(){
|
|||
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)
|
||||
this.readFromPipe( '/mnt/console.tty', (data) => {
|
||||
emulator.log_to_tty = ( String(data).trim() == '1')
|
||||
|
|
|
@ -24,6 +24,8 @@ ISOTerminal.prototype.xtermInit = function(){
|
|||
|
||||
this.addEventListener('emulator-started', function(){
|
||||
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="$*"
|
||||
|
||||
# if we are run as shebang, use the file as input
|
||||
case "$1" in
|
||||
*/*) javascript="args = String('$*').split(' '); $(cat $1 | tail +2)"
|
||||
;;
|
||||
esac
|
||||
test -f "$1" && {
|
||||
javascript="args = String('$*').split(' '); $(cat $1 | tail +2)"
|
||||
}
|
||||
|
||||
# below is not ideal
|
||||
# first I tried /dev/ttyS* https://github.com/copy/v86/issues/530
|
||||
|
|
|
@ -12,17 +12,25 @@ source /mnt/profile.sh
|
|||
|
||||
## forward not-found commands to javascript (via jsh)
|
||||
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 'TIPS'
|
||||
echo '----'
|
||||
echo 'js run ' "type 'js 'alert(\"hello\")'"
|
||||
echo 'js console.log: ' "type 'console document.baseURI"
|
||||
echo 'js function as cmd: ' "type 'alias $1=\"jsh $1\"' to run '$1 yo' as $1('yo')"
|
||||
echo 'js inspect: ' "type 'js \"return document.baseURI\"'"
|
||||
echo 'js console disable: ' "type 'echo 0 > /dev/browser/console.tty' to enable"
|
||||
echo 'js capture console: ' "type 'tail -f /dev/browser/console'"
|
||||
echo 'jsh<->sh hooks: ' "type 'chmod +x ~/hook.d/*/* && alert helloworld'"
|
||||
echo 'js run ' "type 'js 'alert(\"hello\")'"
|
||||
echo 'js console.log: ' "type 'console document.baseURI"
|
||||
echo 'js function as cmd: ' "type 'alias $1=\"jsh $1\"' to run '$1 yo' as $1('yo')"
|
||||
echo 'js inspect: ' "type 'js \"return document.baseURI\"'"
|
||||
echo 'js console disable: ' "type 'echo 0 > /dev/browser/console.tty' to enable"
|
||||
echo 'js capture console: ' "type 'tail -f /dev/browser/console'"
|
||||
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
|
||||
|
|
|
@ -39,6 +39,19 @@ console(){
|
|||
js 'return '$1
|
||||
}
|
||||
|
||||
fetch(){
|
||||
js ''
|
||||
require(){
|
||||
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