Add bad coders webring, update kumaos.
This commit is contained in:
parent
770369c84b
commit
dc0b9b14cb
17 changed files with 401 additions and 155 deletions
|
|
@ -1,33 +1,61 @@
|
|||
const language = "en";
|
||||
const procList = [];
|
||||
const applications = [];
|
||||
const screenRoot = document.querySelector('body');
|
||||
screenRoot.classList.add("kumosroot");
|
||||
|
||||
export const bus = new EventTarget();
|
||||
|
||||
class SecurityError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "SercurityError"
|
||||
}
|
||||
};
|
||||
|
||||
export class Process {
|
||||
constructor(app) {
|
||||
constructor(name, fn, parent = []) {
|
||||
this.pid = procList.length == 0 ? 0 : procList[procList.length - 1].pid + 1;
|
||||
this.name = app.name;
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
procList.push(this);
|
||||
app.fn(this);
|
||||
fn(this);
|
||||
}
|
||||
|
||||
|
||||
detach() {
|
||||
procList.splice(procList.indexOf(this), 1);
|
||||
}
|
||||
|
||||
child(name, fn) {
|
||||
return new Process(name, fn, [...this.parent, this.pid]);
|
||||
}
|
||||
|
||||
isPrivileged() {
|
||||
return this.parent.indexOf(0) !== -1 || this.pid == 0;
|
||||
}
|
||||
}
|
||||
|
||||
export class Application {
|
||||
constructor(name, fn) {
|
||||
this.fn = fn;
|
||||
this.name = name;
|
||||
registerApplication(this);
|
||||
}
|
||||
|
||||
bootstrap() {
|
||||
new Process(this.name, this.fn);
|
||||
}
|
||||
}
|
||||
|
||||
export class Window {
|
||||
constructor() {
|
||||
constructor(p) {
|
||||
this.process = p;
|
||||
|
||||
// Window
|
||||
const w = document.createElement("div");
|
||||
w.classList.add("window");
|
||||
this.window = w;
|
||||
|
||||
|
||||
// Header
|
||||
const h = document.createElement("div");
|
||||
h.classList.add("windowHeader");
|
||||
|
|
@ -37,13 +65,23 @@ export class Window {
|
|||
const title = document.createElement("p");
|
||||
title.classList.add("windowHeaderTitle");
|
||||
this.title = title;
|
||||
|
||||
// Buttons container
|
||||
const container = document.createElement("div");
|
||||
container.classList.add("buttonContainer");
|
||||
|
||||
// Close button
|
||||
const close = document.createElement("button");
|
||||
close.innerText = "close";
|
||||
close.classList.add("windowHeaderButton");
|
||||
close.classList.add("windowHeaderButtonClose");
|
||||
close.classList.add("close");
|
||||
this.close = close;
|
||||
|
||||
// Maximize button
|
||||
const maximize = document.createElement("button");
|
||||
maximize.classList.add("windowHeaderButton");
|
||||
maximize.classList.add("maximize");
|
||||
this.maximizeButton = maximize;
|
||||
maximize.addEventListener("click", () => { this.maximize() });
|
||||
|
||||
// Content
|
||||
const c = document.createElement("div");
|
||||
|
|
@ -51,50 +89,58 @@ export class Window {
|
|||
this.content = c;
|
||||
|
||||
// Building
|
||||
container.appendChild(maximize);
|
||||
container.appendChild(close);
|
||||
h.appendChild(title);
|
||||
h.appendChild(close);
|
||||
h.appendChild(container);
|
||||
w.appendChild(h);
|
||||
w.appendChild(c);
|
||||
}
|
||||
|
||||
this.state = "floating";
|
||||
}
|
||||
|
||||
setTitle(title) {
|
||||
this.title.innerText = title;
|
||||
}
|
||||
|
||||
|
||||
destroy() {
|
||||
this.window.remove();
|
||||
}
|
||||
|
||||
maximize() {
|
||||
this.window.classList.toggle("maximized");
|
||||
}
|
||||
}
|
||||
|
||||
export function promoteWindow(window) {
|
||||
const header = window.header;
|
||||
const elmnt = window.window;
|
||||
|
||||
|
||||
header.style.cursor = 'move';
|
||||
|
||||
|
||||
header.onmousedown = (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
let pos3 = e.clientX;
|
||||
let pos4 = e.clientY;
|
||||
|
||||
|
||||
const startTop = elmnt.offsetTop;
|
||||
const startLeft = elmnt.offsetLeft;
|
||||
|
||||
|
||||
document.onmouseup = closeDragElement;
|
||||
document.onmousemove = elementDrag;
|
||||
|
||||
|
||||
function elementDrag(e) {
|
||||
e.preventDefault();
|
||||
const pos1 = pos3 - e.clientX;
|
||||
const pos2 = pos4 - e.clientY;
|
||||
pos3 = e.clientX;
|
||||
pos4 = e.clientY;
|
||||
|
||||
|
||||
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
|
||||
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
|
||||
}
|
||||
|
||||
|
||||
function closeDragElement() {
|
||||
document.onmouseup = null;
|
||||
document.onmousemove = null;
|
||||
|
|
@ -103,11 +149,9 @@ export function promoteWindow(window) {
|
|||
}
|
||||
|
||||
export function getScreenRoot() {
|
||||
return document.querySelector('body');
|
||||
return screenRoot;
|
||||
}
|
||||
|
||||
const applications = [];
|
||||
|
||||
export function getApplications() {
|
||||
return applications;
|
||||
}
|
||||
|
|
@ -122,4 +166,15 @@ export function getLanguage() {
|
|||
|
||||
export function getProcList() {
|
||||
return procList;
|
||||
}
|
||||
}
|
||||
|
||||
["log","warn", "error", "info"].forEach(method => {
|
||||
const original = console[method];
|
||||
|
||||
console[method] = (...args) => {
|
||||
original(...args);
|
||||
bus.dispatchEvent(new CustomEvent("system-console", {
|
||||
detail: args
|
||||
}));
|
||||
};
|
||||
})
|
||||
Loading…
Reference in a new issue