Skip to content

Commit

Permalink
migrating to serviceworker for custom FS shit
Browse files Browse the repository at this point in the history
  • Loading branch information
nova@novas optiplex committed Oct 22, 2024
1 parent 0e7e73e commit 33aa03a
Show file tree
Hide file tree
Showing 4 changed files with 467 additions and 117 deletions.
2 changes: 1 addition & 1 deletion assets/code/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ setTimeout(function () {
}
}
});
}, 1000)
}, 1000)
6 changes: 3 additions & 3 deletions assets/code/wfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ var foxyfs = {
}
return { items: content };
}
var dirHandle = await opfsRoot.getDirectoryHandle(path[0]);
var dirHandle = await opfsRoot.getDirectoryHandle(path[0], {create:true});
if (path.length > 1) {
for (var item of path) {
if (item == path[0]) {

} else {
dirHandle = await dirHandle.getDirectoryHandle(item)
dirHandle = await dirHandle.getDirectoryHandle(item, {create:true})
}
}
var content = [];
Expand Down Expand Up @@ -489,4 +489,4 @@ var fs2 = {
};
});
}
};
};
245 changes: 132 additions & 113 deletions desktop.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ <h1>NovaOS</h1>
</div> -->
</body>
</html>

<script src="./assets/code/vals.js"></script>
<script src="./assets/lib/jq.js"></script>
<script src="./assets/lib/jszip.js"></script>
Expand All @@ -122,139 +123,157 @@ <h1>NovaOS</h1>
<script src="./assets/code/fs.js"></script>
<script src="./assets/code/apps.js"></script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./serviceworker.js')
.then(registration => console.log('ServiceWorker registered'))
.catch(err => console.error('ServiceWorker registration failed:', err));
}
async function boot() {
var uname = "No Username, somehow."
uname = await fs.read('/user/info/name');
if (uname !== undefined) {
const name = await fs.read('/user/info/name');
const deskid = await fs.read('/system/deskid');
const darkpref = await fs.read('/user/info/lightdarkpref');
const lightdark = await fs.read('/user/info/lightdark');
const color = await fs.read('/user/info/color');
await wd.desktop(name, deskid, 'wait');
await ptp.go(deskid);
sys.setupd = true;
var uname = "No Username, somehow.";
var lsofuserinfo = await fs.ls("/user/info");
function hasNameFile(element, index, array) {
return element.name == "name";
}
var unamexist = lsofuserinfo.items.some(hasNameFile);
if (unamexist) {
console.log("yea")
const name = await fs.read("/user/info/name");
const deskid = await fs.read("/system/deskid");
const darkpref = await fs.read("/user/info/lightdarkpref");
const lightdark = await fs.read("/user/info/lightdark");
const color = await fs.read("/user/info/color");
await wd.desktop(name, deskid, "wait");
await ptp.go(deskid);
sys.setupd = true;

if (darkpref === "auto") {
sys.autodarkacc = true;
} else {
sys.autodarkacc = false;
}
if (lightdark === "dark") {
wd.dark();
} else if (lightdark === "clear") {
wd.clearm();
} else if (lightdark === "clear2") {
wd.clearm2();
} else {
wd.light();
}
ui.crtheme(color);
console.log(color)
if (!color) {
fs.write('/user/info/color', '#C68A00');
ui.crtheme('#C68A00');
}
if (darkpref === "auto") {
sys.autodarkacc = true;
} else {
sys.autodarkacc = false;
}
if (lightdark === "dark") {
wd.dark();
} else if (lightdark === "clear") {
wd.clearm();
} else if (lightdark === "clear2") {
wd.clearm2();
} else {
const id = gen(4);
await ptp.go(id);
await fs.mkdir('/system', "opfs");
await fs.write('/system/deskid', id, "opfs");
app.setup.init();
sys.setupd = false;
wd.light();
}
ui.crtheme(color);
console.log(color);
if (!color) {
fs.write("/user/info/color", "#C68A00");
ui.crtheme("#C68A00");
}
} else {
console.log("narr")
const id = gen(4);
await ptp.go(id);
await fs.mkdir("/system", "opfs");
await fs.write("/system/deskid", id, "opfs");
app.setup.init();
sys.setupd = false;
}

const dropZone = document.body;
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropZone.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
const dropZone = document.body;
["dragenter", "dragover", "dragleave", "drop"].forEach((eventName) => {
dropZone.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});

dropZone.addEventListener('drop', handleDrop, false);
dropZone.addEventListener("drop", handleDrop, false);

function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}

function handleDrop(e) {
let dt = e.dataTransfer;
let files = dt.files;
function handleDrop(e) {
let dt = e.dataTransfer;
let files = dt.files;

handleFiles(files);
}
handleFiles(files);
}

async function handleFiles(files) {
let filesArray = [...files];
filesArray.forEach(file => {
const reader = new FileReader();
reader.onload = function (e) {
const contents = e.target.result;
fs.write(`/user/files/${file.name}`, contents);
};
async function handleFiles(files) {
let filesArray = [...files];
filesArray.forEach((file) => {
const reader = new FileReader();
reader.onload = function (e) {
const contents = e.target.result;
fs.write(`/user/files/${file.name}`, contents);
};

if (file.type.startsWith('image')) {
reader.readAsDataURL(file);
} else {
reader.readAsArrayBuffer(file);
}
});
}

const data = await fs.read('/system/apps.json');
if (data) {
const apps = JSON.parse(data);
try {
const response = await fetch('https://appmarket.meower.xyz/refresh');
const onlineApps = await response.json();
for (const inapp of apps) {
await wd.loadapps(inapp, onlineApps, apps);
}
} catch (err) {
console.log(err);
try {
for (const inapp of apps) {
await wd.loadapps(inapp, inapp, inapp);
}
} catch (error) {
if (sys.fucker === false) {
sys.fucker = true;
fs.del('/system/apps.json');
fs.delfold('/system/apps');
wm.notif('App Issues', 'All apps were uninstalled due to corruption or an update. Your data is safe, you can reinstall them anytime.', () => app.appmark.init(), 'App Market');
}
}
}
if (file.type.startsWith("image")) {
reader.readAsDataURL(file);
} else {
reader.readAsArrayBuffer(file);
}
});
}

const data = await fs.read("/system/apps.json");
if (data) {
const apps = JSON.parse(data);
try {
const response = await fetch("https://appmarket.meower.xyz/refresh");
const onlineApps = await response.json();
for (const inapp of apps) {
await wd.loadapps(inapp, onlineApps, apps);
}
} catch (err) {
console.log(err);
try {
for (const inapp of apps) {
await wd.loadapps(inapp, inapp, inapp);
}
} catch (error) {
if (sys.fucker === false) {
sys.fucker = true;
fs.del("/system/apps.json");
fs.delfold("/system/apps");
wm.notif(
"App Issues",
"All apps were uninstalled due to corruption or an update. Your data is safe, you can reinstall them anytime.",
() => app.appmark.init(),
"App Market"
);
}
}
}
} else {
fs.write("/system/apps.json", "");
}
}
// if(localStorage.getItem("networking") == "false") {
// document.querySelector("#netw").classList.remove("on");
// } else {
// document.querySelector("#netw").classList.add("on")
// }
if(localStorage.getItem("doNotDisturb") == "falsbrthe") {
document.querySelector("#dnd").classList.remove("on");
if (localStorage.getItem("doNotDisturb") == "falsbrthe") {
document.querySelector("#dnd").classList.remove("on");
} else {
document.querySelector("#dnd").classList.add("on")
document.querySelector("#dnd").classList.add("on");
}

$("#dm").on("change", function() {
if($(this).val() == "dark") {
wd.dark();
fs.write('/user/info/lightdark', 'dark');
} else if($(this).val() == "light") {
wd.light();
fs.write('/user/info/lightdark', 'light');
} else if($(this).val() == "auto") {
fs.write('/user/info/lightdarkpref', 'auto');
fs.read('/user/info/color').then((col) => ui.crtheme(col));
sys.autodarkacc = true;
} else if($(this).val() == "cml") {
wd.clearm();
fs.write('/user/info/lightdark', 'clear');
} else if($(this).val() == "cmd") {
wd.clearm2();
fs.write('/user/info/lightdark', 'clear2');
}
$("#dm").on("change", function () {
if ($(this).val() == "dark") {
wd.dark();
fs.write("/user/info/lightdark", "dark");
} else if ($(this).val() == "light") {
wd.light();
fs.write("/user/info/lightdark", "light");
} else if ($(this).val() == "auto") {
fs.write("/user/info/lightdarkpref", "auto");
fs.read("/user/info/color").then((col) => ui.crtheme(col));
sys.autodarkacc = true;
} else if ($(this).val() == "cml") {
wd.clearm();
fs.write("/user/info/lightdark", "clear");
} else if ($(this).val() == "cmd") {
wd.clearm2();
fs.write("/user/info/lightdark", "clear2");
}
});
</script>
Loading

0 comments on commit 33aa03a

Please sign in to comment.