Electron でファイルを保存するパターン
意外と簡単に書けるので、面倒くさがらずに書くとすぐです。
レンダラ側
document.getElementById('saveButton').addEventListener('click', () => { ipcRenderer.send('save-state', JSON.stringify(state)); });
メイン側
ipcMain.on('save-state', (event, stateString) => { const defaultPath = 'my-data.json'; dialog.showSaveDialog( { defaultPath, properties: { multiSelections: false, }, }, filePath => { if (filePath == null) { return; } fs.writeFileSync(filePath, stateString); }, ); });
開くときもだいたい同じ