1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
ipcMain.handle('save-file', async (_, { content }: { content: string }) => { const { canceled, filePath } = await dialog.showSaveDialog(mainWindow, { title: '保存文件', defaultPath: join(app.getPath('documents'), 'example.txt') }) if (!canceled && filePath) { fs.writeFileSync(filePath, content, 'utf-8') return filePath } return null })
ipcMain.handle('read-file', async () => { const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, { title: '打开文件', defaultPath: app.getPath('documents'), properties: ['openFile'], filters: [{ name: '文本文件', extensions: ['txt'] }] }) if (!canceled && filePaths.length > 0) { const content = fs.readFileSync(filePaths[0], 'utf-8') return { filePath: filePaths[0], content } } return null })
|