#!/bin/sh source /etc/profile.sh state(){ javascript=' const isoterminal = document.querySelector("[isoterminal]").components.isoterminal.term isoterminal.save() return "[OK] xrsh state saved\n" ' echo "[i] triggering ~/hook.d/save/* scripts" hook save echo "[i] warning: do not resize the browserwindow" echo "[i] please wait.." js "$javascript" exit } file(){ javascript=' filename='$1' function saveUint8Array(uint8Array, filename = 'download.bin', mimeType = 'application/octet-stream') { const blob = new Blob([uint8Array], { type: mimeType }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; // Programmatically trigger the click event document.body.appendChild(a); a.click(); document.body.removeChild(a); // Clean up the URL object URL.revokeObjectURL(url); } let term = document.querySelector("[isoterminal]") term.emit("read_file", [filename, (str,buf) > saveUint8Array(buf, filename) ) return "" ' hook save js "$javascript" exit } test -z "$1" && state test -n "$1" && file echo "Usage: save [file] # pass no argument to save VM state to localStorage"