Skip to content

Commit f15e7a7

Browse files
committed
uwu dual fs
1 parent 00fb97b commit f15e7a7

File tree

6 files changed

+463
-45
lines changed

6 files changed

+463
-45
lines changed

assets/code/apps.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,14 @@ var app = {
138138
name: 'Files',
139139
icon: './assets/img/systemIcons/files.svg',
140140
init: async function () {
141-
const win = tk.mbw(`Files`, '340px', 'auto', true, true, true);
141+
const win = tk.mbw(`Files`, '340px', 'auto', true, true, true, undefined, app.files.icon);
142142
win.main.classList.add("fileman")
143-
const mainPane = tk.c('div', win.main)
144-
const navBar = tk.c('div', mainPane)
143+
const lowerZone = tk.c('div', win.main)
144+
lowerZone.classList.add("lowerZone")
145+
const mainPane = tk.c('div', lowerZone)
146+
const navBar = tk.c('div', win.main)
145147
navBar.classList.add("navbar")
146-
const navPane = tk.c('div', win.main)
148+
const navPane = tk.c('div', lowerZone)
147149
navPane.classList.add("navpane")
148150
const fm = tk.c('div', mainPane)
149151
fm.classList.add("fm")
@@ -153,45 +155,55 @@ var app = {
153155
const mkFolder = tk.cb('b1', '➕', function () {}, navBar);
154156
const breadcrumbs = tk.c('div', navBar);
155157
breadcrumbs.classList.add("bc");
156-
breadcrumbs.classList.add("b1");
157158
const items = tk.c('div', fm);
158159
const navPaneDrives = tk.c('ul', navPane)
159160
const osDrive = tk.c("li", navPaneDrives)
160-
osDrive.innerText = "/ Root"
161-
async function navto(path, fs = "idb") {
161+
osDrive.classList.add("flist", "width", "drive")
162+
osDrive.innerText = "OPFS (NovaOS)"
163+
const classicDrive = tk.c("li", navPaneDrives)
164+
classicDrive.classList.add("flist", "width", "drive")
165+
classicDrive.innerText = "IDBFS (Classic)"
166+
async function navto(path, filesystem = "opfs") {
162167
mkFolder.onclick = async function () {
163-
fs.write(`${path}${prompt("enter folder name here", "New Folder")}/.`, '');
164-
navto(path)
168+
if(filesystem == 'opfs'){
169+
fs.mkdir(`${path}${prompt("enter folder name here", "New Folder")}/.`, 'opfs');
170+
}
171+
else{
172+
fs.write(`${path}${prompt("enter folder name here", "New Folder")}/.`, '', 'idbfs');
173+
};
174+
navto(path, filesystem)
165175
}
166176
items.innerHTML = "";
167177
breadcrumbs.innerHTML = "";
168178
let crumbs = path.split('/').filter(Boolean);
169179
let currentp = '/';
170-
tk.cb('flist', 'Root', () => navto('/'), breadcrumbs);
180+
tk.cb('flist', 'Root', () => navto('/', filesystem), breadcrumbs);
171181
crumbs.forEach((crumb, index) => {
172182
currentp += crumb + '/';
173183
tk.cb('flists', '/', undefined, breadcrumbs);
174184
tk.cb('flist', crumb, () => {
175185
let newPath = crumbs.slice(0, index + 1).join('/');
176-
navto('/' + newPath + "/");
186+
navto('/' + newPath + "/", filesystem);
177187
}, breadcrumbs);
178188
});
179-
const thing = await fs.ls(path, fs);
189+
const thing = await fs.ls(path, filesystem);
180190
thing.items.forEach(function (thing) {
181-
if (thing.type === "folder") {
182-
tk.cb('flist width', "Folder: " + thing.name, () => navto(thing.path + "/"), items);
191+
if (thing.type === "folder" || thing.type === "directory") {
192+
tk.cb('flist width', "📁 " + thing.name, () => navto(thing.path + "/", filesystem), items);
183193
} else if (thing.name.startsWith('.')) {
184194
void (0)
185195
} else {
186-
tk.cb('flist width', "File: " + thing.name, async function () { const yeah = await fs.read(thing.path); wm.wal(yeah); }, items);
196+
tk.cb('flist width', "📄 " + thing.name, async function () { const yeah = await fs.read(thing.path); wm.wal(yeah); }, items);
187197
}
188198
});
189199
}
190200
osDrive.addEventListener("click", await function (){
191-
navto("/", "idbfs")
201+
navto("/", "opfs")
192202
})
193-
194-
navto('/');
203+
classicDrive.addEventListener("click", await function (){
204+
navto("/", "idbfs")
205+
});
206+
navto('/', 'opfs');
195207
}
196208
},
197209
about: {

assets/code/core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ var wd = {
213213
return formattedTime;
214214
},
215215
finishsetup: function (name, div1, div2) {
216-
ui.sw2(div1, div2); ui.masschange('name', name); fs.write('/user/info/name', name);
216+
ui.sw2(div1, div2); ui.masschange('name', name);
217+
fs.mkdir('/user')
218+
fs.mkdir('/user/info')
219+
fs.write('/user/info/name', name);
217220
},
218221
reboot: function () {
219222
window.location.reload();

assets/code/fs.js

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ var fs = {
2525
send: function (message, transferList) {
2626
wfs.postMessage(message, transferList);
2727
},
28+
sendopfs: function (message, transferList) {
29+
wfs.postMessage(message, transferList);
30+
},
2831
askwfs: function (operation, params, opt) {
2932
const requestId = requestIdCounter++;
3033
return new Promise((resolve, reject) => {
@@ -36,21 +39,62 @@ var fs = {
3639
}
3740
});
3841
},
39-
read: function (path) {
40-
return this.askwfs('read', path);
42+
askwfsOPFS: function (operation, params, opt) {
43+
const requestId = requestIdCounter++;
44+
return new Promise((resolve, reject) => {
45+
pendingRequests[requestId] = { resolve, reject };
46+
if (operation === 'write' && opt instanceof ArrayBuffer) {
47+
fs.sendopfs({ type: 'opfs', operation, params, opt, requestId }, [p2]);
48+
} else {
49+
fs.sendopfs({ type: 'opfs', operation, params, opt, requestId });
50+
}
51+
});
52+
},
53+
read: function (path, filesystem = "opfs") {
54+
if(filesystem == "opfs") {
55+
return this.askwfsOPFS('read', path);
56+
}
57+
else if(filesystem == "idbfs") {
58+
return this.askwfs('read', path);
59+
}
4160
},
42-
write: function (path, data) {
43-
return this.askwfs('write', path, data);
61+
write: function (path, data, filesystem = "opfs") {
62+
if(filesystem == "opfs") {
63+
return this.askwfsOPFS('write', path, data);
64+
}
65+
else if(filesystem == "idbfs") {
66+
return this.askwfs('write', path, data);
67+
}
4468
},
45-
del: function (path) {
46-
return this.askwfs('delete', path);
69+
del: function (path, filesystem = "opfs") {
70+
if(filesystem == "opfs") {
71+
return this.askwfsOPFS('delete', path);
72+
}
73+
else if(filesystem == "idbfs") {
74+
return this.askwfs('delete', path);
75+
}
4776
},
48-
erase: function (path) {
49-
return this.askwfs('erase', path);
77+
erase: function (filesystem = "idbfs") {
78+
if(filesystem == "opfs") {
79+
return this.askwfsOPFS('erase', path);
80+
} else if(filesystem == "idbfs") {
81+
return this.askwfs('erase', path);
82+
}
5083
},
51-
ls: function (path, fs = "idbfs") {
52-
return this.askwfs('ls', path);
84+
ls: function (path, filesystem = "opfs") {
85+
if(filesystem == "opfs") {
86+
return this.askwfsOPFS('ls', path);
87+
} else if(filesystem == "idbfs") {
88+
return this.askwfs('ls', path);
89+
}
5390
},
91+
mkdir: function (path, filesystem = "opfs") {
92+
if(filesystem == "opfs") {
93+
return this.askwfsOPFS('mkdir', path);
94+
} else if(filesystem == "idbfs") {
95+
fs.write("/user/Documents/.", '', "idbfs");
96+
}
97+
}
5498
};
5599
setTimeout(function () {
56100
fs.ls("/user/info/name").then(async (namefile) => {

0 commit comments

Comments
 (0)