xrsh-com/com/isoterminal/feat/boot.js

87 lines
2.7 KiB
JavaScript
Raw Normal View History

ISOTerminal.addEventListener('ready', function(e){
2025-05-22 16:24:53 +02:00
setTimeout( () => this.boot(), 50 ) // allow other features/plugins to settle first (autorestore.js e.g.)
})
2025-01-27 12:00:16 +01:00
ISOTerminal.prototype.bootMenu = function(e){
this.boot.menu.selected = false // reset
2025-02-28 17:05:43 +01:00
const autobootURL = e && e.detail.bootMenuURL && document.location.hash.length > 1
const autoboot = e && e.detail.bootMenu || autobootURL
2025-02-21 15:59:29 +01:00
if( !autoboot ){
let msg = '\n\r'
this.boot.menu.map( (m) => {
msg += `\r${m.key}) ${m.title(this.opts)}\n`
})
msg += `\n\renter choice> `
this.send(msg)
}else{ // autoboot
if( this.term ){
2025-05-22 16:24:53 +02:00
this.term.handler( String(e.detail.bootMenu || e.detail.bootMenuURL).charAt(0) )
2025-02-21 15:59:29 +01:00
this.term.handler("\n")
}
}
2025-01-27 12:00:16 +01:00
}
2025-02-21 15:59:29 +01:00
ISOTerminal.addEventListener('bootMenu', function(e){ this.bootMenu(e) } )
ISOTerminal.prototype.boot = async function(e){
// set environment
let env = [
`export LINES=${this.opts.rows}`,
`export COLUMNS=${this.opts.cols}`,
'export BROWSER=1',
]
for ( let i in document.location ){
2025-05-22 16:24:53 +02:00
if( typeof document.location[i] == 'string' && !String(i).match(/(hash|search)/) ){
2024-09-23 16:01:40 +00:00
env.push( 'export '+String(i).toUpperCase()+'="'+decodeURIComponent( document.location[i]+'"') )
}
}
2025-05-22 16:24:53 +02:00
// we export the cached hash/query (because they might be gone due to remotestorage plugin)
if( this.boot.hash.charAt(2) == '&' ){ // strip bootoption
this.boot.hashExBoot = `#` + this.boot.hash.substr(3)
}
env.push( 'export HASH="'+decodeURIComponent( this.boot.hashExBoot || this.boot.hash ) +'"' )
env.push( 'export QUERY="'+decodeURIComponent( this.boot.query ) +'"' )
2025-01-15 18:02:30 +01:00
await this.worker.create_file("profile.browser", this.convert.toUint8Array( env.join('\n') ) )
if( this.serial_input == 0 ){
if( !this.noboot ){
this.send("source /etc/profile # \\o/ FOSS powa!\n")
}
}
}
2025-05-22 16:24:53 +02:00
ISOTerminal.prototype.boot.fromImage = false
2025-01-27 12:00:16 +01:00
ISOTerminal.prototype.boot.menu = []
2025-05-22 16:24:53 +02:00
ISOTerminal.prototype.boot.hash = document.location.hash
ISOTerminal.prototype.boot.query = document.location.search
// here REPL's can be defined
2025-01-27 12:00:16 +01:00
// REPL: iso
if( typeof window.PromiseWorker != 'undefined' ){ // if xrsh v86 is able to run in in worker
ISOTerminal.prototype.boot.menu.push(
{
key: "1",
title: (opts) => `boot ${String(opts.iso || "").replace(/.*\//,'')} Linux ❤️ `,
2025-02-14 17:18:33 +01:00
init: function(){
// hack to notify href clicks
Term.prototype.href = (a) => {
if( a.href ){
this.exec(`source /etc/profile.sh; hook href "${a.href}"`)
}
return false
}
this.bootISO()
},
keyHandler: function(ch){ this.send(ch) } // send to v86 webworker
}
)
}