Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wow i fell behind gotta patch what i can in and then i can adjust and create new features #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 107 additions & 34 deletions assets/code/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var app = {
// General pane
tk.p('General', undefined, generalPane);
tk.cb('b1 b2 red', 'Erase This WebDesk', () => wm.wal(`<p>Warning: Erasing this WebDesk will destroy all data stored on it, and you'll need to do setup again.</p>`, () => fs.erase('reboot'), 'Erase'), generalPane);
tk.cb('b1 b2 red', 'Preload SelfQNA content', function () { fs.write('/user/demo/steak', `A steak is a thick cut of meat generally sliced across the muscle fibers, sometimes including a bone. It is normally grilled or fried. Steak can be diced, cooked in sauce, such as in steak and kidney pie, or minced and formed into patties, such as hamburgers. Steaks are cut from animals including cattle, bison, buffalo, camel, goat, horse, kangaroo,[1][2] sheep, ostrich, pigs, turkey, and deer, as well as various types of fish, especially salmon and large fish such as swordfish, shark, and marlin. For some meats, such as pork, lamb and mutton, chevon, and veal, these cuts are often referred to as chops. Some cured meat, such as gammon, is commonly served as steak.`); wm.wal(`<p>Preloaded article on steak, ask SelfQNA "what is steak"</p>`) }, generalPane);
tk.cb('b1', 'Back', () => ui.sw2(generalPane, mainPane), generalPane);
// Appearance pane
tk.p('Appearance', undefined, appearPane);
Expand Down Expand Up @@ -114,7 +115,7 @@ var app = {
const sum = tk.c('div', main, 'setb hide');
tk.img('./assets/img/setup/check.svg', 'setupi', sum);
tk.p('All done!', 'h2', sum);
tk.p('Have fun! Make sure to check Settings for more options.', undefined, sum);
tk.p('Make sure to check Settings for more options.', undefined, sum);
tk.cb('b1 rb', 'Erase & restart', function () { fs.erase('reboot'); }, sum); tk.cb('b1', 'Finish setup', function () { wd.reboot(); }, sum);
sum.id = "setupdone";
}
Expand Down Expand Up @@ -164,55 +165,127 @@ var app = {
tk.p(`Latest update: ${abt.lastmod}`, undefined, win.main);
}
},
ach: {
runs: true,
name: 'Achievements',
init: async function () {
const win = tk.mbw('Achievements', '300px', 'auto', true, undefined, undefined);
tk.p(`WebDesk Achievements`, 'h2', win.main);
tk.p(`Unlocked 0/0 achievements`, undefined, win.main);
}
},
selfqna: {
runs: true,
name: 'SelfQNA',
init: async function () {
const win = tk.mbw('SelfQNA', '380px', 'auto', true, undefined, undefined);
const main = tk.c('div', win.main, '');
tk.p(`Searches WebDesk's filesystem for something you ask for, and might return an answer.`, undefined, main);
const i = tk.c('input', main, 'i1');
i.placeholder = "Ask your WebDesk a question...";
let finish;
const unload = tk.cb('b1', 'Unload model from RAM', async () => {
sys.model = undefined;
finish.innerText = "Model unloaded successfully";
setTimeout(function () { finish.innerText = "Ask your WebDesk a question..."; }, 3000)
}, main);
const button = tk.cb('b1', 'Ask!', async () => {
finish.innerText = "Loading files...";
try {
const context = await fs.getall();
const answer = await ai.find(context, i.value, finish);
finish.innerText = answer;
} catch (error) {
finish.innerText = "Error occurred: " + error.message;
}
}, main);
finish = tk.p('Answers will appear here', undefined, main);
}
},
browser: {
runs: true,
name: 'Browser',
init: async function () {
const win = tk.mbw('Browser', '80vw', '82vh', true, undefined, undefined);
tk.css('./assets/lib/browse.css');
const win = tk.mbw('Browser', '80vw', '82vh', true);
ui.dest(win.title, 0);

const tabs = tk.c('div', win.main, 'tabbar d');
let currenttab = tk.c('div', win.main, 'hide');
let currentbtn = tk.c('div', win.main, 'hide');
win.main.classList = "browsercont";
tk.css('./assets/lib/browse.css');
const btnnest = tk.c('div', tabs, 'tnav');
const addbtn = tk.cb('b4 browserbutton', '+', function () {
const okiedokie = tk.c('div', tabs, 'browsertitle');
const searchbtns = tk.c('div', okiedokie, 'tnav');
const searchnest = tk.c('div', tabs, 'title');

let currentTab = tk.c('div', win.main, 'hide');
let currentBtn = tk.c('div', win.main, 'hide');
let currentName = tk.c('div', win.main, 'hide');
let lastUrl = "";
const urls = [];
win.main.classList = "browsercont";

function checkUrlChange(embed) {
setTimeout(function () {
const currentUrl = embed.src;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
urls.push(currentUrl);
}
}, 200);
}

function addtab() {
const tab = tk.c('embed', win.main, 'browsertab');
tab.src = "https://meower.xyz";
ui.sw2(currenttab, tab);
currenttab = tab;
const tabbtn = tk.cb('b4', 'meower.xyz', function () {
ui.sw2(currenttab, tab);
currenttab = tab;
currentbtn = tabtitle;
ui.sw2(currentTab, tab);
currentTab = tab;

const tabBtn = tk.cb('b4 browserpad', '', function () {
ui.sw2(currentTab, tab);
currentTab = tab;
currentBtn = tabTitle;
}, btnnest);
const tabtitle = tk.c('span', tabbtn);
currentbtn = tabtitle;
const closetab = tk.cb('browserclosetab', 'X', function () {
ui.dest(tabbtn); ui.dest(currenttab);
}, tabbtn);
}, btnnest);
const okiedokie = tk.c('div', tabs, 'browsertitle')
const searchbtns = tk.c('div', okiedokie, 'tnav');
const close = tk.cb('b4 rb browserbutton', 'x', function () {
const tabTitle = tk.c('span', tabBtn);
tabTitle.innerText = "meower.xyz";
currentName = tabTitle;
currentBtn = tabTitle;

const closeTabBtn = tk.cb('browserclosetab', 'x', function () {
ui.dest(tabBtn);
ui.dest(currentTab);
}, tabBtn);

checkUrlChange(tab);
}

tk.cb('b4 browserbutton', '+', addtab, searchbtns);
tk.cb('b4 rb browserbutton', 'x', function () {
ui.dest(win.win, 150);
ui.dest(win.tbn, 150);
}, btnnest);
tk.cb('b4 yb browserbutton', '-', function () {
ui.hide(win.win, 150);
}, btnnest);
tk.cb('b4 browserbutton', '⟳', function () {
currentTab.src = currentTab.src;
}, searchbtns);
const rel = tk.cb('b4 browserbutton', '⟳', function () {
}, searchbtns);
const back = tk.cb('b4 browserbutton', '<', function () {
tk.cb('b4 browserbutton', '<', function () {
currentTab.contentWindow.history.go(-1);
}, searchbtns);
const rev = tk.cb('b4 browserbutton', '>', function () {

tk.cb('b4 browserbutton', '>', function () {
currentTab.contentWindow.history.go(1);
}, searchbtns);
const searchnest = tk.c('div', tabs, 'title');
const search = tk.c('input', okiedokie, 'i1 browserbutton');
search.placeholder = "Enter URL";
const go = tk.cb('b4 browserbutton', 'Go!', function () {
currenttab.src = search.value;
currentbtn.innerText = search.value;

// Add the search input and button
const searchInput = tk.c('input', okiedokie, 'i1 browserbutton');
searchInput.placeholder = "Enter URL";
tk.cb('b4 browserbutton', 'Go!', function () {
currentTab.src = "https://" + searchInput.value;
currentBtn.innerText = searchInput.value;
}, okiedokie);

// Initialize the browser window with one tab
wd.win();
addTab();
}
}
}
};
1 change: 0 additions & 1 deletion assets/code/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ var wd = {
for (var key in app) {
if (app.hasOwnProperty(key)) {
if (app[key].hasOwnProperty("runs") && app[key].runs === true) {
console.log('<i> This app can run normally!');
const btn = tk.cb('b1', app[key].name, app[key].init.bind(app[key]), el.sm);
btn.addEventListener('click', function () {
ui.dest(el.sm, 150);
Expand Down
3 changes: 3 additions & 0 deletions assets/code/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ var fs = {
ls: function (path) {
return this.askwfs('ls', path);
},
getall: function () {
return this.askwfs('all');
},
};
4 changes: 2 additions & 2 deletions assets/code/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var ui = {
const dr2 = document.getElementById(d2);
$(dr1).fadeOut(160, function () { $(dr2).fadeIn(160); });
},
sw2: function (d1, d2) {
$(d1).fadeOut(160, function () { $(d2).fadeIn(160); });
sw2: function (d1, d2, fadetime) {
$(d1).fadeOut(140, function () { $(d2).fadeIn(140); });
},
hide: function (dr1, anim) {
if (dr1) {
Expand Down
53 changes: 50 additions & 3 deletions assets/code/wfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ function idbop(operation, params, opt, requestId) {
case 'list':
fs2.list(params);
break;
case 'all':
fs2.all().then(files => {
self.postMessage({ type: 'result', data: files, requestId });
}).catch(error => {
console.error('Error fetching files:', error);
});
break;
case 'ls':
fs2.folder(params).then(result => {
self.postMessage({ type: 'result', data: result, requestId });
Expand Down Expand Up @@ -142,16 +149,16 @@ var fs2 = {
const transaction = db.transaction(['main'], 'readonly');
const objectStore = transaction.objectStore('main');
const items = new Map();

objectStore.openCursor().onsuccess = function (event) {
const cursor = event.target.result;
if (cursor) {
if (cursor.key.startsWith(path)) {
const relativePath = cursor.key.substring(path.length);
const parts = relativePath.split('/');

if (parts.length > 1) {
items.set(parts[0], { path: path + parts[0], name: parts[0], type: 'folder'});
items.set(parts[0], { path: path + parts[0], name: parts[0], type: 'folder' });
} else {
items.set(relativePath, { path: cursor.key, name: relativePath, type: 'file' });
}
Expand All @@ -161,6 +168,46 @@ var fs2 = {
resolve({ items: Array.from(items.values()) });
}
};

objectStore.openCursor().onerror = function (event) {
reject(event.target.error);
};
});
},
all: function () {
return new Promise((resolve, reject) => {
const transaction = db.transaction(['main'], 'readonly');
const objectStore = transaction.objectStore('main');
const fileContentsPromises = [];

objectStore.openCursor().onsuccess = function (event) {
const cursor = event.target.result;
if (cursor) {
const key = cursor.key;
const relativePath = key.split('/').pop();

if (!relativePath.includes('.png')) {
const request = objectStore.get(key);
request.onsuccess = function (event) {
const item = event.target.result;
if (item && item.data) {
const decoded = new TextDecoder().decode(item.data);
fileContentsPromises.push(relativePath + ": " + decoded);
} else {
fileContentsPromises.push(null);
}
};
request.onerror = function (event) {
reject(event.target.error);
};
}
cursor.continue();
} else {
transaction.oncomplete = function () {
resolve(fileContentsPromises);
};
}
};

objectStore.openCursor().onerror = function (event) {
reject(event.target.error);
Expand Down
Binary file modified assets/fonts/Poppins-Bold.ttf
Binary file not shown.
13 changes: 13 additions & 0 deletions assets/img/icons/disk.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/lib/browse.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@
width: 100%;
box-sizing: border-box;
user-select: none;
}

.browserpad {
padding-left: 6px;
}
Loading