diff --git a/cmd.js b/cmd.js index 917f24d..39b4a07 100644 --- a/cmd.js +++ b/cmd.js @@ -1,49 +1,56 @@ -hmm.$=(c,cm)=>{ - let l=hmm.$.token(cm) - if(l[0]=="")return; - if(l[0] in hmm.storage.cmd){ - return hmm.storage.cmd[l[0]](c,l.slice(1)) - }else{ +hmm.$ = (cm, c) => { + let l = hmm.$.token(cm) + if (l[0] == "") return; + if (l[0] in hmm.storage.cmd) { + return new Function("return {" + hmm.storage.cmd[l[0]] + "}")()[l[0]](c, l.slice(1)) + } else { c.err("Command not found") } } -hmm.$.token=(e)=>{ - let l=[""],string=!1 - e.split("").forEach((e,n)=>{ - if(string){ - if(e!='"'||e[n-1]=="\\"){l[l.length-1]+=e}else{ - string=!1 +hmm.$.token = (e) => { + let l = [""], string = !1 + e.split("").forEach((e, n) => { + if (string) { + if (e != '"' || e[n - 1] == "\\") { l[l.length - 1] += e } else { + string = !1 } - }else{ - if(e==" "){ + } else { + if (e == " ") { l.push("") - }else if(e=='"'){ - string=!0 - }else{ - l[l.length-1]+=e + } else if (e == '"') { + string = !0 + } else { + l[l.length - 1] += e } } }) return l } -hmm.storage.cmd={ -// help(c){ -// c.echo(`Commands: -// echo: displays text -// err: displays an error -// open: opens an app`) -// }, -// echo(c,e){ -// c.echo(e.join(" ")) -// }, -// err(c,e){ -// c.err(e.join(" ")) -// }, -// open(c,e){ -// hmm.openApp(e[0]+".hmm") -// }, -// "#"(){}, +hmm.storage.cmd = { + help(c) { + c.echo(`Commands: +echo: displays text +err: displays an error +open: opens an app`) + }, + echo(c, e) { + c.echo(e.join(" ")) + }, + err(c, e) { + c.err(e.join(" ")) + }, + open(c, e) { + if (c) { + + } + }, + "#"() { }, +} +for (const cmd in hmm.storage.cmd) { + hmm.storage.cmd[cmd] = String(hmm.storage.cmd[cmd]) } -hmm.storage.env=[{ - -}] \ No newline at end of file +window.onmessage = (ev) => { + if ('_AppName' in ev.source) { + console.log(ev.source) + } +} \ No newline at end of file diff --git a/fe.html b/fe.html new file mode 100644 index 0000000..f34ef39 --- /dev/null +++ b/fe.html @@ -0,0 +1,54 @@ + + + + +
+ \ No newline at end of file diff --git a/main.js b/main.js index 41826e0..d5973dd 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,7 @@ function e(query) { } window.hmm = { testcommand: function () { - hmm.openApp("cmd.hmm"); + hmm.openApp("fe.hmm", "/.pr"); }, restart: function () { window.location = window.location.href @@ -12,17 +12,22 @@ window.hmm = { lang: "en" }, safe: {}, - perms: { - iframe: { - "nosandbox": "vscodish.hmm opts.hmm " - } - }, hasPerms: (name, filename) => { - return eval("hmm.perms." + name).includes(filename + " ") + return eval("hmm.storage['.pr'].perms." + name).includes(filename + " ") }, l: {}, t: phrase => { return hmm.l[hmm.storage.opts.lang]?.t(phrase) + }, + reset() { + hmm.storage = null + localforage.setItem('hmm-fs', hmm.storage) + location = location.href + }, + pathToJs(p) { + var cr = hmm.storage; + (p.match(/\/[^/]+/g) || []).forEach((e) => cr = cr[e.slice(1)]) + return cr } } hmm.l.en = new Polyglot({ @@ -70,19 +75,36 @@ hmm.storage = { type: 0, code: `` }, - "vscodish.hmm": { - title: "VSCode (ish)", - type: "iframe", - code: "" - }, "opts.hmm": { title: "settings", type: "iframe", - code: "", + code: "", }, + "fe.hmm": { + title: "Files", + type: "iframe", + code: `` + } + }, + opts: { + lang: 'en' }, - opts:{ - lang:'en' + ".pr": { + perms: { + iframe: { + "nosandbox": "vscodish.hmm opts.hmm fe.hmm " + } + }, + handlers: { + '/': 'fe.hmm' + } } } @@ -90,8 +112,8 @@ window.onload = () => { localforage.getItem("hmm-fs").then((val) => { if (null !== val) { hmm.storage = val - }else{ - localforage.setItem('hmm-fs',hmm.storage) + } else { + localforage.setItem('hmm-fs', hmm.storage) } hmm.setup() }) @@ -121,10 +143,10 @@ hmm.bar.toggle = function () { } hmm.bar.isOpen = !hmm.bar.isOpen } -hmm.openApp = function (app) { +hmm.openApp = function (app, arg) { if (app in hmm.storage.apps && app.endsWith(".hmm")) { var a = new hmm.App(app) - a.open() + a.open(arg) } } hmm.El = class { @@ -146,7 +168,7 @@ hmm.App = class { this.baritem = document.createElement("baritem") this.baritem.innerText = this.title[0] } - open() { + open(arg) { var node = document.createElement("window") var tb = document.createElement("taskbar") tb.appendChild(document.createElement("span")) @@ -205,6 +227,7 @@ hmm.App = class { n.classList.add("win") content.style.overflow = "hidden" content.appendChild(n) + postMessage(arg, n.contentWindow) } node.appendChild(content) @@ -337,12 +360,12 @@ hmm.setup = () => { ` hmm.setMenu() - if (location.href.startsWith("http://localhost:7700")) { + if (location.href.startsWith("http://localhost:")) { hmm.testcommand() } - setInterval(()=>{ //periodically update localforage - localforage.setItem('hmm-fs',hmm.storage) - },1000) + setInterval(() => { //periodically update localforage + localforage.setItem('hmm-fs', hmm.storage) + }, 1000) } //very useful BUT BREAKS CODE FOR SOME REASON: //Object.prototype.with=function(k,v){var x=this;x[k]=v;return x}