From 157ec6da1fcbcf5b4858f6eae227f1d1e9336aea Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 23 Jul 2024 13:05:59 +0000 Subject: [PATCH] limit to 1 terminal + several fixes --- com/dom.js | 1 + com/isoterminal.js | 32 +++++++++++++++++++++++++--- com/{add.js => launcher-optional.js} | 2 +- com/save.js | 14 +++++++++++- 4 files changed, 44 insertions(+), 5 deletions(-) rename com/{add.js => launcher-optional.js} (98%) diff --git a/com/dom.js b/com/dom.js index fb77222..1c1bf9a 100644 --- a/com/dom.js +++ b/com/dom.js @@ -65,6 +65,7 @@ AFRAME.registerComponent('dom',{ if( !overlay ){ overlay = document.createElement('div') overlay.id = "overlay" + overlay.setAttribute('style','position:fixed;top:0px;left:0px;right:0px;bottom:0px') document.body.appendChild(overlay) // sceneEl.setAttribute("webxr","overlayElement:#overlay") } diff --git a/com/isoterminal.js b/com/isoterminal.js index ec65ce6..51ac6be 100644 --- a/com/isoterminal.js +++ b/com/isoterminal.js @@ -45,6 +45,23 @@ AFRAME.registerComponent('isoterminal', { .wb-body:has(> .isoterminal){ background: #000; } .isoterminal div{ display:block; } .isoterminal span{ display: inline } + + @keyframes fade { + from { opacity: 1.0; } + 50% { opacity: 0.5; } + to { opacity: 1.0; } + } + + @-webkit-keyframes fade { + from { opacity: 1.0; } + 50% { opacity: 0.5; } + to { opacity: 1.0; } + } + + .blink { + animation:fade 1000ms infinite; + -webkit-animation:fade 1000ms infinite; + } ` }, @@ -65,7 +82,7 @@ AFRAME.registerComponent('isoterminal', { url: this.data.iso, }, network_relay_url: "", - cmdline: "rw root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose modules=virtio_pci tsc=reliable init_on_free=on", + cmdline: "rw root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose modules=virtio_pci tsc=reliable init_on_free=on init=/bin/date", //bzimage:{ // url: "com/isoterminal/images/buildroot-bzimage.bin" //}, @@ -74,7 +91,7 @@ AFRAME.registerComponent('isoterminal', { // baseurl: "com/isoterminal/v86/images/alpine-rootfs-flat", // basefs: "com/isoterminal/v86/images/alpine-fs.json", // }, - screen_dummy: true, + //screen_dummy: true, autostart: true, }); @@ -97,9 +114,16 @@ AFRAME.registerComponent('isoterminal', { }, launcher: async function(){ + if( this.instance ){ + const el = document.querySelector('.isoterminal') + el.classList.add('blink') + setTimeout( () => el.classList.remove('blink'), 2000 ) + return console.warn('TODO: allow multiple terminals (see v86 examples)') + } + let s = await AFRAME.utils.require(this.requires) // instance this component - const instance = this.el.cloneNode(false) + const instance = this.instance = this.el.cloneNode(false) this.el.sceneEl.appendChild( instance ) instance.addEventListener('DOMready', () => { @@ -108,6 +132,7 @@ AFRAME.registerComponent('isoterminal', { }) instance.addEventListener('window.oncreate', (e) => { + instance.dom.classList.add('blink') // resize after the dom content has been rendered & updated setTimeout( () => { let spans = [...instance.dom.querySelectorAll('span')] @@ -116,6 +141,7 @@ AFRAME.registerComponent('isoterminal', { ((spans.length * spans[0].offsetHeight) ) +'px' ) },1200) + setTimeout( () => instance.dom.classList.remove('blink'), 5000 ) }) instance.addEventListener('window.onclose', (e) => { diff --git a/com/add.js b/com/launcher-optional.js similarity index 98% rename from com/add.js rename to com/launcher-optional.js index f1109c7..b0bdcdd 100644 --- a/com/add.js +++ b/com/launcher-optional.js @@ -1,4 +1,4 @@ -AFRAME.registerComponent('add', { +AFRAME.registerComponent('launcher-optional', { schema:{ comps: {type:"array"} }, diff --git a/com/save.js b/com/save.js index 04ef6b1..eb6843a 100644 --- a/com/save.js +++ b/com/save.js @@ -24,11 +24,23 @@ AFRAME.registerComponent('save', { r.remove() // *TODO* dont crash on hands - this.inlineFiles() + this.save_state() + .then( this.inlineFiles ) .then( () => this.download(document.documentElement.innerHTML,"xrsh.html") ) .catch(console.error) }, + save_state: async function(){ + if( window.emulator ){ + let binaryString = ''; + const state = await emulator.restore_state(state); + uint8Array.forEach(byte => binaryString += String.fromCharCode(byte) ); + let b64data = btoa(binaryString); + console.log(b64data) + + } + }, + download: function(content, filename, contentType){ const a = document.createElement('a'); const file = new Blob([document.documentElement.innerHTML], {type: "text/html"});