Skip to content

Commit

Permalink
mostly done with file explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Electogenius committed Nov 27, 2021
1 parent 0072529 commit 0a385c3
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 62 deletions.
83 changes: 45 additions & 38 deletions cmd.js
Original file line number Diff line number Diff line change
@@ -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=[{

}]
window.onmessage = (ev) => {
if ('_AppName' in ev.source) {
console.log(ev.source)
}
}
54 changes: 54 additions & 0 deletions fe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script>
window._AppName = "fe"
</script>
<link rel="stylesheet" href="style.css">
<style>
body {
overflow: auto;
}

div.file {
background-color: #000;
border-radius: 5px;
border: 2px solid #fff;
border-bottom: 1px solid #fff;
border-top: 1px solid #fff;
}

div.folder::after {
content: ">";
float: right;
color: #aaa;
}

#pathlabel {
font-family: menlo, monospace;
}
</style>
<span id="pathlabel"></span>
<div id="files"></div>
<script>
hmm = window.top.hmm;
path = "/"
loadpath=()=>{
document.getElementById('pathlabel').innerText = path
document.getElementById('files').innerHTML = (path != "/") ? `
<div class="file" style="color:#05d" onclick="path=path.slice(0,path.slice(0,-1).lastIndexOf('/')+1);loadpath()">&larr; back</div>
`: ''
Object.keys(hmm.pathToJs(path)).sort().forEach(e => {
var el = document.createElement('div')
el.classList.add('file')
if (typeof (hmm.pathToJs(path)[e]) == "object") {
el.classList.add('folder')
el.onclick = () => {
path += e + '/'
loadpath()
}
}
if (e.startsWith('.')) el.style.color = "#aaa"
el.innerText = e
document.getElementById('files').appendChild(el)
})
}
loadpath()
</script>
71 changes: 47 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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({
Expand Down Expand Up @@ -70,28 +75,45 @@ hmm.storage = {
type: 0,
code: ``
},
"vscodish.hmm": {
title: "VSCode (ish)",
type: "iframe",
code: "<script>location='https://github1s.com/Electogenius/HmmOS'</script>"
},
"opts.hmm": {
title: "settings",
type: "iframe",
code: "<script>location = './settings.html'</script>",
code: "<script>location='./settings.html'</script>",
},
"fe.hmm": {
title: "Files",
type: "iframe",
code: `<script id=start>
onmessage=e=>window.arg=e.data
fetch('./fe.html').then(e=>e.text()).then(e=>{
console.log(e)
document.body.innerHTML=e
document.querySelectorAll('script:not(#start)').forEach(e=>{eval(e.innerHTML)})
})
</script>`
}
},
opts: {
lang: 'en'
},
opts:{
lang:'en'
".pr": {
perms: {
iframe: {
"nosandbox": "vscodish.hmm opts.hmm fe.hmm "
}
},
handlers: {
'/': 'fe.hmm'
}
}
}

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()
})
Expand Down Expand Up @@ -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 {
Expand All @@ -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"))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 0a385c3

Please sign in to comment.