file-handling
file-handling copied to clipboard
Folder Handlers
Chrome Apps currently have the ability to register as handlers for folders. It would be great to have the same capability as part of this API.
https://developer.chrome.com/apps/manifest/file_handlers
This is what it looks like:

Sorry it's taken me so long to get back to you on this.
This is definitely on our roadmap (it'd be really handy for IDE like tools), but probably won't be part of the initial API. We're hoping to add it later, depending on how the initial API is received.
Thanks for taking the time to give feedback :) If you have some specific use cases it'll help us with prioritization.
Now that the spec is complete and File Handling has shipped in Chrome, I think we should extend it with directory handling. This feature would be awesome for all sorts of PWAs, especially for code editors like VSCode.dev.
For the API design I'm thinking of something like this:
- A new web app manifest member called
"directory_handlers"with the following structure:
[
{
"action": string, // destination URL
"title": string, // title that gets displayed in the file explorer's context menu, e.g. "Open with Foo", "Play in Bar", ... (default is `Open with ${PWA_NAME}`)
"icons": [ // the icon to display in the file explorer's context menu (default is the PWA's icon)
{
"src": string,
"sizes": string,
"type": string,
},
...
],
"launch_type": "single-client" | "multiple-clients", // defines whether multiple directories should be opened in a single client or in multiple clients (default is "single-client")
},
...
]
- A new property on the
LaunchParamsinterface calleddirectorieswhich is an array ofFileSystemDirectoryHandles
If multiple directory handlers are specified in "directory_handlers", all of them are shown in the file explorer's context menu among themselves. For example, an IDE application might want to give the user the option to either "Edit folder in Foo" or "Run folder contents with Foo".
I'm tagging @tomayac here; I think they might be interested in this discussion.
I think one problem might be OS interoperability. For example, macOS doesn't seem to expose special directory actions. If VS Code is installed, VS Code could offer itself as a directory handler, but I'm not even sure if this is possible on Mac—it's not implemented for the native VS Code app as far as I can tell.
Looking at Electron.js (which I believe the native VS Code app is based upon), it seems like passed files are handled as arguments for process.argv judging from this StackOverflow answer, so the app would then need to open said file. So technically it might be possible to deal with folders here, but I haven't personally seen it in practice.
@tomayac MacOS provides a way to customize the "Quick Actions" menu in the contextmenu of MacOS' finder. It is possible for a human to manually add an "Open folder in VSCode" shortcut to this quick actions menu (see this StackOverflow answer). If a human can do this manually, there should probably be a way for browsers to do this automatically.
Can apps automatically add QuickActions? Is there an equivalent on other operating systems? On Windows 11, the "Show more options" reveals a secondary context menu where you can, for example, scan the folder for viruses. I'm not sure apps can hook into this?!
Can apps automatically add QuickActions?
Hmm, this is a tricky one indeed. My idea was that it would be somehow possible to control MacOS Automator from the terminal using some fancy commands and add quick actions that way. The browser would then run these terminal commands internally. I could not find much information about this on the internet, except maybe for this blog post, which does not seem to be a solution to the problem.
On Windows, native applications definitely can register their shortcuts in the "more options" menu that you have already pointed out. Native VSCode actually uses this:

Hmm, this is a tricky one indeed. My idea was that it would be somehow possible to control MacOS Automator from the terminal using some fancy commands and add quick actions that way. The browser would then run these terminal commands internally. I could not find much information about this on the internet, except maybe for this blog post, which does not seem to be a solution to the problem.
If it involves hackery, I (personally) wouldn't consider it supported.
On Windows, native applications definitely can register their shortcuts in the "more options" menu that you have already pointed out.
This I would very much consider supported then.
So we have at least one major desktop OS with native support. What about Gnome or KDE as major (at least as far as I know) Linux desktop window managers?
If it involves hackery, I (personally) wouldn't consider it supported.
Yep, the MacOS one is definitely hackery, if it is even possible to register quick actions as an application. But if it is somehow possible, I still think this would be worth it. And if it's not possible, an option would be to provide folder handling only on Windows & Linux.
I've now tried out opening VSCode from the file explorer in both my Zorin OS (uses GNOME) VM...
...and in my Manjaro (uses KDE Plasma) VM...
...and both desktop environments seem to support opening folders with applications.
Sounds good to me, we seem to have decent enough OS support then. The next step would be to drum up some developer excitement.
On Mac, you can open a folder by dragging and dropping it onto the app icon. VSCode supports this.
Some applications (such as Godot) register a file association for the project file, which opens the parent directory for editing.
Perhaps there should be an option to expose the parent directory handle at launch?