2024-01-22 10:38:16 +01:00
|
|
|
/*
|
2024-04-19 16:42:46 +02:00
|
|
|
* ## launcher
|
2024-01-22 10:38:16 +01:00
|
|
|
*
|
|
|
|
* displays app (icons) for enduser to launch
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* <a-entity app="app/launcher.js"/>
|
|
|
|
* ```
|
2024-04-19 16:42:46 +02:00
|
|
|
*
|
2024-01-22 10:38:16 +01:00
|
|
|
* | property | type | example |
|
|
|
|
* |--------------|--------------------|----------------------------------------------------------------------------------------|
|
2024-04-19 16:42:46 +02:00
|
|
|
* | `registries` | `array` of strings | <a-entity app="app/launcher.js; registers: https://foo.com/index.json, ./index.json"/> |
|
2024-01-22 10:38:16 +01:00
|
|
|
*
|
|
|
|
* | event | target | info |
|
|
|
|
* |--------------|-------------------------------------------------------------------------------------------------------------|
|
2024-04-19 16:42:46 +02:00
|
|
|
* | `launcher` | an app | when pressing an app icon, `launcher` event will be send to the respective app |
|
2024-01-22 10:38:16 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
AFRAME.registerComponent('launcher', {
|
2024-04-19 16:42:46 +02:00
|
|
|
schema: {
|
2024-01-22 10:38:16 +01:00
|
|
|
foo: { type:"string"}
|
|
|
|
},
|
|
|
|
|
2024-04-19 16:42:46 +02:00
|
|
|
init: function () {
|
2024-01-22 10:38:16 +01:00
|
|
|
this.data.apps = []
|
|
|
|
|
|
|
|
AFRAME.scenes.map( (scene) => {
|
|
|
|
scene.addEventListener('app:ready', (e) => this.render(e.detail) )
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
requires:{
|
|
|
|
html: "https://unpkg.com/aframe-htmlmesh@2.1.0/build/aframe-html.js", // html to AFRAME
|
|
|
|
},
|
|
|
|
|
|
|
|
dom: {
|
|
|
|
scale: 3,
|
|
|
|
events: ['click'],
|
|
|
|
html: (me) => `<div>
|
2024-01-22 12:13:41 +01:00
|
|
|
<div id="iconmenu"></div>
|
2024-01-22 10:38:16 +01:00
|
|
|
</div>`,
|
|
|
|
|
2024-04-19 16:42:46 +02:00
|
|
|
css: (me) => `#iconmenu {
|
2024-01-22 10:38:16 +01:00
|
|
|
z-index: 1000;
|
|
|
|
display: flex;
|
2024-04-19 16:42:46 +02:00
|
|
|
flex-direction: row;
|
|
|
|
align-items: flex-start;
|
|
|
|
height: 50px;
|
|
|
|
overflow:hidden;
|
2024-01-22 10:38:16 +01:00
|
|
|
position: fixed;
|
2024-04-19 16:42:46 +02:00
|
|
|
right: 162px;
|
|
|
|
bottom: 0px;
|
|
|
|
left:20px;
|
|
|
|
background: transparent;
|
|
|
|
padding-bottom: 54px;
|
2024-01-22 10:38:16 +01:00
|
|
|
box-sizing: border-box;
|
|
|
|
pointer-events: none;
|
2024-01-22 12:13:41 +01:00
|
|
|
visibility: visible !important;
|
2024-01-22 10:38:16 +01:00
|
|
|
}
|
|
|
|
#iconmenu > button {
|
2024-04-19 16:42:46 +02:00
|
|
|
line-height:0px;
|
2024-01-22 10:38:16 +01:00
|
|
|
pointer-events:all;
|
|
|
|
width: 58px;
|
2024-04-19 16:42:46 +02:00
|
|
|
height: 34px;
|
|
|
|
padding: 12px 0px 12px 0px;
|
2024-01-22 10:38:16 +01:00
|
|
|
border-radius: 0px;
|
|
|
|
color: var(--xrsh-primary);
|
|
|
|
background: #FFF;
|
2024-04-19 16:42:46 +02:00
|
|
|
border-top: 2px solid #BBB;
|
|
|
|
border-bottom: 2px solid #BBB;
|
|
|
|
font-size:18px;
|
2024-01-22 10:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#iconmenu > button:first-child {
|
2024-04-19 16:42:46 +02:00
|
|
|
border-radius: 5px 0px 0px 5px;
|
|
|
|
border-bottom: 2px solid #BBB;
|
|
|
|
border-left: 2px solid #BBB;
|
|
|
|
padding-bottom:16px;
|
2024-01-22 10:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#iconmenu > button:last-child {
|
2024-04-19 16:42:46 +02:00
|
|
|
border-radius:0px 5px 5px 0px;
|
|
|
|
border-top: 2px solid #BBB;
|
|
|
|
border-right: 2px solid #BBB;
|
2024-01-22 10:38:16 +01:00
|
|
|
padding-top:13px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#iconmenu > button > img {
|
2024-04-19 16:42:46 +02:00
|
|
|
transform: translate(0px,-14px);
|
2024-01-22 10:38:16 +01:00
|
|
|
opacity:0.5;
|
|
|
|
padding: 5px;
|
|
|
|
border-radius: 0px;
|
|
|
|
}
|
2024-01-22 12:13:41 +01:00
|
|
|
#iconmenu > button > img:hover{
|
|
|
|
background: #AAA;
|
2024-01-22 10:38:16 +01:00
|
|
|
transition:0.gg3s;
|
|
|
|
border-radius: 50%;
|
|
|
|
}`
|
|
|
|
},
|
|
|
|
|
|
|
|
events:{
|
|
|
|
|
|
|
|
// combined AFRAME+DOM reactive events
|
2024-04-19 16:42:46 +02:00
|
|
|
click: function(e){
|
2024-01-22 10:38:16 +01:00
|
|
|
console.dir(e)
|
2024-04-19 16:42:46 +02:00
|
|
|
}, //
|
2024-01-22 10:38:16 +01:00
|
|
|
|
|
|
|
|
2024-04-19 16:42:46 +02:00
|
|
|
ready: function( ){
|
2024-01-22 10:38:16 +01:00
|
|
|
this.el.dom.children[0].id = this.el.uid // important hint for html-mesh
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function(app){
|
|
|
|
clearTimeout(this.timeout)
|
|
|
|
this.timeout = setTimeout( () => {
|
2024-04-19 16:42:46 +02:00
|
|
|
const drawButton = (app) => {
|
|
|
|
if( !app.manifest ) return
|
2024-01-22 12:13:41 +01:00
|
|
|
console.log(app.data.uri+" "+app.data.order)
|
2024-01-22 10:38:16 +01:00
|
|
|
let btn = app.btn = document.createElement('button')
|
|
|
|
if( app.manifest.icons?.length > 0){
|
2024-04-19 16:42:46 +02:00
|
|
|
let img = document.createElement('img')
|
2024-01-22 10:38:16 +01:00
|
|
|
img.src = app.manifest.icons[0].src
|
2024-01-22 12:13:41 +01:00
|
|
|
img.title = app.manifest.name + ": " + app.manifest.description
|
2024-01-22 10:38:16 +01:00
|
|
|
btn.appendChild(img)
|
|
|
|
}else btn.innerText = app.manifest.short_name
|
2024-04-19 16:42:46 +02:00
|
|
|
btn.addEventListener('click', () => {
|
|
|
|
app.el.emit('launcher',app)
|
|
|
|
app.el.sceneEl.emit('launched',app)
|
|
|
|
})
|
2024-01-22 10:38:16 +01:00
|
|
|
this.el.dom.querySelector('#iconmenu').appendChild(btn)
|
2024-04-19 16:42:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const drawCategory = (app,c) => app.manifest &&
|
|
|
|
app.manifest.short_name != "launcher" &&
|
|
|
|
app.manifest.category == c ? drawButton(app) : false
|
|
|
|
|
|
|
|
AFRAME.app.foreach( (app) => drawCategory(app,undefined) )
|
|
|
|
AFRAME.app.foreach( (app) => drawCategory(app,"system") )
|
|
|
|
|
2024-01-22 12:13:41 +01:00
|
|
|
},100)
|
2024-01-22 10:38:16 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
manifest: { // HTML5 manifest to identify app to xrsh
|
2024-04-19 16:42:46 +02:00
|
|
|
"short_name": "launcher",
|
|
|
|
"name": "App Launcher",
|
2024-01-22 10:38:16 +01:00
|
|
|
"icons": [
|
|
|
|
{
|
|
|
|
"src": "https://css.gg/browser.svg",
|
|
|
|
"type": "image/svg+xml",
|
|
|
|
"sizes": "512x512"
|
|
|
|
}
|
|
|
|
],
|
2024-04-19 16:42:46 +02:00
|
|
|
"category":"system",
|
2024-01-22 10:38:16 +01:00
|
|
|
"id": "/?source=pwa",
|
|
|
|
"start_url": "/?source=pwa",
|
|
|
|
"background_color": "#3367D6",
|
|
|
|
"display": "standalone",
|
|
|
|
"scope": "/",
|
|
|
|
"theme_color": "#3367D6",
|
|
|
|
"shortcuts": [
|
|
|
|
{
|
|
|
|
"name": "What is the latest news?",
|
|
|
|
"cli":{
|
|
|
|
"usage": "helloworld <type> [options]",
|
|
|
|
"example": "helloworld news",
|
|
|
|
"args":{
|
|
|
|
"--latest": {type:"string"}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"short_name": "Today",
|
|
|
|
"description": "View weather information for today",
|
|
|
|
"url": "/today?source=pwa",
|
|
|
|
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"description": "Hello world information",
|
|
|
|
"screenshots": [
|
|
|
|
{
|
|
|
|
"src": "/images/screenshot1.png",
|
|
|
|
"type": "image/png",
|
|
|
|
"sizes": "540x720",
|
|
|
|
"form_factor": "narrow"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"help":`
|
2024-04-19 16:42:46 +02:00
|
|
|
Helloworld application
|
2024-01-22 10:38:16 +01:00
|
|
|
|
|
|
|
This is a help file which describes the application.
|
|
|
|
It will be rendered thru troika text, and will contain
|
|
|
|
headers based on non-punctualized lines separated by linebreaks,
|
|
|
|
in above's case "\nHelloworld application\n" will qualify as header.
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|