UC-Davis-molecular-computing / scadnano

Web application for designing DNA structures such as DNA origami.
https://scadnano.org
MIT License
21 stars 13 forks source link

save files with fewer mouse/keystrokes using new File System Access API #619

Open dave-doty opened 3 years ago

dave-doty commented 3 years ago

There is a draft report for an API to access the file system more naturally from the browser: https://wicg.github.io/file-system-access/

See also https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API

For example, one could save the current design via Ctrl+S without having to then click or type a filename in a file dialog.

It would also make the Boolean * that appears next to the filename in the browser tab more accurate, as well as the associated reminder prompt to save the design before closing the tab. It is supposed to represent that changes have been made to the design but not saved. But currently, all it does is reset (remove the *) when the user presses Ctrl+S or File→Save, even if they cancel and end up not saving the file, because current browser security restrictions prevent us from determining if the file was actually saved.

See also https://fjolt.com/article/javascript-new-file-system-api for usage examples.

Unfortunately this API is not yet implemented by Firefox, so we can't use it yet. This issue will stay as a reminder to check on that report and see if Firefox is moving towards implementing the API.

tcosmo commented 2 years ago

https://boxy-svg.com/ is a nice example of this (you need to register to experience it)

dave-doty commented 2 years ago

We could implement this now if we're happy to have different behavior for different browsers, e.g., Firefox pops up the file save dialog on Ctrl+S, but Chrome just goes through the File System API.

But, there are some decisions to make about expected behavior when multiple tabs are open.

Right now it's not well-defined what happens to localStorage when multiple tabs are open. I think essentially the last tab to be edited writes what appears in localStorage, and there's lots of warnings about not relying on the localStorage-saved design for saving the design. (It's just a convenience that lets you refresh the page without the design changing, assuming you have only one tab open, or the refreshed page is the last one to write to localStorage.) But of course with this feature request, you'd expect if you have 2 tabs open, each somehow "tied" to their own local file, to be able to edit them independently of each other.

If the local file path is itself stored in localStorage, this would be a problem, since different tabs would be overwriting the same localStorage key for that file path. So unless I come up with a better idea, the local file path would NOT be stored in local storage, so each time you open scadnano, you'd have to reopen the file you want to edit (even if you only ever open it one tab at a time and always edit the same file). I think there's something called sessionStorage that is specific to one tab, but then I assume it doesn't persist when the tab is closed.