1. Use Nodemon hot update

npm i nodemon -D
Copy the code

In the package. The json:

  "scripts": {
    "start": "nodemon --watch main.js --exec electron ."
  },
Copy the code

Error: ‘require’ is undefine

Solution:

const mainWindow = new BrowserWindow({ webPreferences: { nodeIntegration: Node contextIsolation: false}})Copy the code

3. Console debugging

Solution:

mainWindow.webContents.openDevTools();
Copy the code

3. The file path cannot be obtained when the showOpenDialog command is used to open the file

To solve

ipcMain.on('open-music-file', () => {
    dialog.showOpenDialog({
        properties: ['openFile', 'multiSelections'],
        filters: [{ name: 'Music', extensions: ['mp3'] }]
    },(files) => {
        console.log(files)
    })
})
Copy the code

The above methods may not be printed, you can use the following methods:

ipcMain.on('open-music-file', () => { dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'], filters: [{ name: 'Music', extensions: ['mp3'] }] }).then(result => { console.log(result); })})Copy the code