potatOS/copy-cat/embed.js

7 lines
1.5 KiB
JavaScript

/**
* copy-cat: Copyright SquidDev 2023
*
*
* @license
*/define(["./persist-7dd7de50","require"],function(e,t){"use strict";let r={addString:()=>{},addBoolean:()=>{},addInt:()=>{}};class o extends e.b{constructor(r,o){var n,l;super(r,o);let{persistId:i,hdFont:s}=r,a=new e.TerminalData,u=new e.Semaphore,c=new e.ComputerAccess(void 0===i?new e.VoidPersistence:new e.StoragePersistence(i),a,u,(e,t)=>this.setState({label:e,on:t}));null===(n=r.resolve)||void 0===n||n.call(r,c);let p="string"==typeof s?s:t.toUrl("./"+(void 0===s||s?e.termFontHd:e.termFont)),d=null!==(l=r.files)&&void 0!==l?l:{};for(let t in d){if(!Object.prototype.hasOwnProperty.call(d,t))continue;let[r]=e.splitName(t);if(r){let e=c.createDirectory(r);if(null===e.value)throw Error(e.error)}let o=d[t],n=c.createFile(t);if(null===n.value)throw Error(n.error);let l=n.value.setContents(o);if(null===l.value)throw Error(l.error)}let m=r.peripherals;if(m)for(let e in m){if(!Object.prototype.hasOwnProperty.call(m,e))continue;let t=m[e];null!=t&&c.setPeripheral(e,t)}this.setState({on:!1,label:null,font:p,terminal:a,terminalChanged:u,computer:c})}componentDidMount(){this.state.computer.start(()=>r,this.props)}componentWillUnmount(){this.state.computer.dispose()}render(t,{font:r,computer:o,terminal:n,terminalChanged:l,label:i,on:s}){return e.y(e.Terminal,{terminal:n,changed:l,focused:!0,computer:o,font:r,id:0,label:i,on:s})}}let n=(t,r)=>new Promise((n,l)=>e.B(e.y(o,Object.assign({resolve:n},null!=r?r:{})),t));return n.h=e.y,n.Component=e.b,n.render=e.B,n.Computer=o,n});