mirror of
https://github.com/osnr/TabFS.git
synced 2024-06-15 20:25:18 +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);
|
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;
|
let port;
|
||||||
async function onMessage(req) {
|
async function onMessage(req) {
|
||||||
|
@ -896,9 +902,7 @@ async function onMessage(req) {
|
||||||
|
|
||||||
/* console.time(req.op + ':' + req.path);*/
|
/* console.time(req.op + ':' + req.path);*/
|
||||||
try {
|
try {
|
||||||
const [route, vars] = tryMatchRoute(req.path);
|
response = await doRequest(req);
|
||||||
response = await route[req.op]({...req, ...vars});
|
|
||||||
response.op = req.op;
|
|
||||||
if (response.buf) { response.buf = btoa(response.buf); }
|
if (response.buf) { response.buf = btoa(response.buf); }
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -6,7 +6,19 @@ if (chrome.extension.getBackgroundPage) {
|
||||||
// accept requests from the page
|
// accept requests from the page
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(async (request, sender) => {
|
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;
|
return entries;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,7 +47,13 @@ if (chrome.extension.getBackgroundPage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
.--tabfs-file-container .--tabfs-file::before {
|
.--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>
|
</style>
|
||||||
|
|
||||||
|
@ -47,16 +65,14 @@ if (chrome.extension.getBackgroundPage) {
|
||||||
const icons = {};
|
const icons = {};
|
||||||
|
|
||||||
let frontierX = 0, frontierY = 0;
|
let frontierX = 0, frontierY = 0;
|
||||||
const addFile = function(name, x, y, file) {
|
const addFile = function(stat, x, y, file) {
|
||||||
// TODO: report into the extension
|
|
||||||
|
|
||||||
if (!x) {
|
if (!x) {
|
||||||
x = frontierX; frontierX += 64;
|
x = frontierX; frontierX += 64;
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.insertAdjacentHTML('beforeend', `
|
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;
|
const icon = container.lastElementChild;
|
||||||
icon.style.left = `${x}px`; icon.style.top = `${y}px`;
|
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`
|
// Remove the handlers of `mousemove` and `mouseup`
|
||||||
document.removeEventListener('mousemove', mouseMoveHandler);
|
document.removeEventListener('mousemove', mouseMoveHandler);
|
||||||
document.removeEventListener('mouseup', mouseUpHandler);
|
document.removeEventListener('mouseup', mouseUpHandler);
|
||||||
|
|
||||||
|
// TODO: report into extension
|
||||||
};
|
};
|
||||||
|
|
||||||
icon.addEventListener('mousedown', mouseDownHandler);
|
icon.addEventListener('mousedown', mouseDownHandler);
|
||||||
|
@ -108,7 +126,7 @@ if (chrome.extension.getBackgroundPage) {
|
||||||
|
|
||||||
// ask for what the files are
|
// ask for what the files are
|
||||||
chrome.runtime.sendMessage({hello: 'hello'}, function(response) {
|
chrome.runtime.sendMessage({hello: 'hello'}, function(response) {
|
||||||
response.forEach(name => addFile(name));
|
response.forEach(stat => addFile(stat));
|
||||||
});
|
});
|
||||||
|
|
||||||
document.body.addEventListener('dragenter', function(e) {
|
document.body.addEventListener('dragenter', function(e) {
|
||||||
|
|
Loading…
Reference in a new issue