embed-files: double-click icon to open

This commit is contained in:
Omar Rizwan 2021-07-03 08:31:45 -07:00
parent 9e8eda4531
commit 09e5b6b95c

View file

@ -6,29 +6,35 @@ 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) => {
let {entries} = await Routes["/tabs/by-id/#TAB_ID"] if (request.op === 'LS') {
.readdir({path: `/tabs/by-id/${sender.tab.id}`}); let {entries} = await Routes["/tabs/by-id/#TAB_ID"]
entries = await Promise.all(entries.map(filename => { .readdir({path: `/tabs/by-id/${sender.tab.id}`});
let path = `/tabs/by-id/${sender.tab.id}/${filename}`; entries = await Promise.all(entries.map(filename => {
if (filename === '.') { let path = `/tabs/by-id/${sender.tab.id}/${filename}`;
path = `/tabs/by-id/${sender.tab.id}`; if (filename === '.') {
} else if (filename === '..') { path = `/tabs/by-id/${sender.tab.id}`;
path = `/tabs/by-id`; } else if (filename === '..') {
} path = `/tabs/by-id`;
return doRequest({op: 'getattr', path}) }
.then(stat => ({ ...stat, filename })); // how to store X, Y?
})); return doRequest({op: 'getattr', path})
// TODO: report back not as reply, but as general msg .then(stat => ({ ...stat, filename, path }));
return entries; }));
// TODO: report back not as reply, but as general msg
return entries;
} else if (request.op === 'OPEN') {
chrome.tabs.create({
url: `file:///Users/osnr/t${request.path}`,
index: sender.tab.index + 1,
});
} else if (request.op === 'RELOCATE') {
// TODO: store new pos as local cached attr ?
}
}); });
// send the file list to the page
// receive events from the page of
// they dragged a new file in,
// or they moved a file,
// or they double-clicked a file
} else { } else {
// When running in page: // When running in page:
// Content script that injects a file manager into the page. // Content script that injects a file manager into the page.
@ -122,10 +128,14 @@ if (chrome.extension.getBackgroundPage) {
}; };
icon.addEventListener('mousedown', mouseDownHandler); icon.addEventListener('mousedown', mouseDownHandler);
icon.addEventListener('dblclick', () => {
chrome.runtime.sendMessage({op: 'OPEN', path: stat.path});
return false;
});
}; };
// ask for what the files are // ask for what the files are
chrome.runtime.sendMessage({hello: 'hello'}, function(response) { chrome.runtime.sendMessage({op: 'LS'}, function(response) {
response.forEach(stat => addFile(stat)); response.forEach(stat => addFile(stat));
}); });