mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-11 10:06:34 +02:00
background,embed-files: different icons for files and folders
refactor background so you can synthetically invoke the request logic
This commit is contained in:
parent
e076193982
commit
9e8eda4531
|
@ -880,6 +880,12 @@ function tryMatchRoute(path) {
|
|||
}
|
||||
throw new UnixError(unix.ENOENT);
|
||||
}
|
||||
async function doRequest(req) {
|
||||
const [route, vars] = tryMatchRoute(req.path);
|
||||
const response = await route[req.op]({...req, ...vars});
|
||||
response.op = req.op;
|
||||
return response;
|
||||
}
|
||||
|
||||
let port;
|
||||
async function onMessage(req) {
|
||||
|
@ -896,9 +902,7 @@ async function onMessage(req) {
|
|||
|
||||
/* console.time(req.op + ':' + req.path);*/
|
||||
try {
|
||||
const [route, vars] = tryMatchRoute(req.path);
|
||||
response = await route[req.op]({...req, ...vars});
|
||||
response.op = req.op;
|
||||
response = await doRequest(req);
|
||||
if (response.buf) { response.buf = btoa(response.buf); }
|
||||
|
||||
} catch (e) {
|
||||
|
|
|
@ -6,7 +6,19 @@ if (chrome.extension.getBackgroundPage) {
|
|||
// accept requests from the page
|
||||
|
||||
browser.runtime.onMessage.addListener(async (request, sender) => {
|
||||
const {entries} = await Routes["/tabs/by-id/#TAB_ID"].readdir({path: `/tabs/by-id/${sender.tab.id}`});
|
||||
let {entries} = await Routes["/tabs/by-id/#TAB_ID"]
|
||||
.readdir({path: `/tabs/by-id/${sender.tab.id}`});
|
||||
entries = await Promise.all(entries.map(filename => {
|
||||
let path = `/tabs/by-id/${sender.tab.id}/${filename}`;
|
||||
if (filename === '.') {
|
||||
path = `/tabs/by-id/${sender.tab.id}`;
|
||||
} else if (filename === '..') {
|
||||
path = `/tabs/by-id`;
|
||||
}
|
||||
return doRequest({op: 'getattr', path})
|
||||
.then(stat => ({ ...stat, filename }));
|
||||
}));
|
||||
// TODO: report back not as reply, but as general msg
|
||||
return entries;
|
||||
});
|
||||
|
||||
|
@ -35,7 +47,13 @@ if (chrome.extension.getBackgroundPage) {
|
|||
}
|
||||
|
||||
.--tabfs-file-container .--tabfs-file::before {
|
||||
content: '📁'; display: block; font-size: 48px;
|
||||
display: block; font-size: 48px;
|
||||
}
|
||||
.--tabfs-file-container .--tabfs-file::before {
|
||||
content: '📄';
|
||||
}
|
||||
.--tabfs-file-container .--tabfs-file--directory::before {
|
||||
content: '📁';
|
||||
}
|
||||
</style>
|
||||
|
||||
|
@ -47,16 +65,14 @@ if (chrome.extension.getBackgroundPage) {
|
|||
const icons = {};
|
||||
|
||||
let frontierX = 0, frontierY = 0;
|
||||
const addFile = function(name, x, y, file) {
|
||||
// TODO: report into the extension
|
||||
|
||||
const addFile = function(stat, x, y, file) {
|
||||
if (!x) {
|
||||
x = frontierX; frontierX += 64;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
container.insertAdjacentHTML('beforeend', `
|
||||
<div class="--tabfs-file">${name}</div>
|
||||
<div class="--tabfs-file ${stat.st_mode & 040000 !== 0 ? '--tabfs-file--directory' : ''}">${stat.filename}</div>
|
||||
`);
|
||||
const icon = container.lastElementChild;
|
||||
icon.style.left = `${x}px`; icon.style.top = `${y}px`;
|
||||
|
@ -101,6 +117,8 @@ if (chrome.extension.getBackgroundPage) {
|
|||
// Remove the handlers of `mousemove` and `mouseup`
|
||||
document.removeEventListener('mousemove', mouseMoveHandler);
|
||||
document.removeEventListener('mouseup', mouseUpHandler);
|
||||
|
||||
// TODO: report into extension
|
||||
};
|
||||
|
||||
icon.addEventListener('mousedown', mouseDownHandler);
|
||||
|
@ -108,7 +126,7 @@ if (chrome.extension.getBackgroundPage) {
|
|||
|
||||
// ask for what the files are
|
||||
chrome.runtime.sendMessage({hello: 'hello'}, function(response) {
|
||||
response.forEach(name => addFile(name));
|
||||
response.forEach(stat => addFile(stat));
|
||||
});
|
||||
|
||||
document.body.addEventListener('dragenter', function(e) {
|
||||
|
|
Loading…
Reference in a new issue