Save files to VFS from integrated github1s editor


I have used the github1s code to integrate VSCode into OS.js. However, I am stuck at trying to save the files from the editor. I am not sure how to proceed with saving files to VFS. Can someone please help?


You need a reference to the “core instance” and then you can call the VFS API:

const { writefile } = core.make('osjs/vfs');
await writefile('home://filename', data)

More info here:

You can also prompt the user where to save this:

const promptAndSave = (data) => {
  const { writefile } = core.make('osjs/vfs');
  core.make('osjs/dialog', 'file', {}, {}, async (btn, item) => {
    if (btn === 'ok') {
      await writefile(file, data)

More information:

If you’re using React: If you’re not sure how to get a reference, check out my example on how to use React Context to reach this from anywhere: