johnnesky / beepbox

An online tool for sketching and sharing instrumental melodies.
https://beepbox.co
MIT License
789 stars 163 forks source link

File System Access API #101

Open aMyTimed opened 2 months ago

aMyTimed commented 2 months ago

With the web's File System Access API, developers can open files and save changes to them without creating a new file.

Here's how it works:

let [fileHandle] = await window.showOpenFilePicker();

// Get file content
const file = await fileHandle.getFile();
const contents = await file.text();

const newContents = "...";

// Save changes to the file
const writable = await fileHandle.createWritable();
await writable.write(newContents);
await writable.close();

// Changes have been saved to the file the user opened!

Proposed Behavior

What I think would be great for BeepBox is for users to be able to open and edit files, then CTRL+S to write changes to the file they opened. BeepBox would keep track of if a certain file is opened, and would create a save dialog if the user does not have a .json file open.

CTRL+Shift+S could be used a Save As keyboard shortcut which would open a dialog to save in a new file instead of an existing one.

This would create a distinction between Open, Import, Save and Export:

What problem does this solve?

When I'm using BeepBox, I have to export to multiple formats each time I update my tracks (.json and .wav) in order to both keep the source file of the track, and also the actual audio file. With this solution, I could instead just CTRL+S each time I make a change, and export to audio when I need.

This would also make BeepBox behave more like most software, which typically have Save and Export as distinct features.

Mid-The-Modder commented 2 months ago

That would be lovely ngl

I have problems thinking in my head how the saving would exactly detect which .json file the original song came from unless given some extra special properties, but saving changes to a selected file would be very convenient so you don't gotta fill your downloads with 20 .jsons of the same song :p