0

I am working on an electron project which uses Monaco Editor.

To load a file I use this code:

dialog.showOpenDialog({}, (files) => {
  if(files && files.length > 0) {
    fs.readFile(files[0], 'utf8', (err, res) => {
      if (!err) {
        editor.setModel(monaco.editor.createModel(res, 'javascript'));
      }
    })
  }
})

This issue is that I already know the location of the file and the filename that I need to load.

So my question is...how do I load the file without having the dialog popping up asking for the file?

1 Answers1

1

Don't show the dialog...? Just replace files[0] with the known filename and path.

e.g.

fs.readFile('/path/to/your/file', 'utf8', (err, res) => {
  if (!err) {
    editor.setModel(monaco.editor.createModel(res, 'javascript'));
  }
})
Alex Warren
  • 6,132
  • 2
  • 26
  • 26