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?
Save files to VFS from integrated github1s editor
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: https://manual.os-js.org/tutorial/vfs/
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: https://manual.os-js.org/tutorial/dialog/
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: https://codesandbox.io/s/osjs-react-context-example-056ul