fix: 修复导出下载链路(Electron 保存对话框 + 原生文件写入 + revoke 竞态)

This commit is contained in:
root
2026-10-16 13:02:33 +08:00
parent b87e895766
commit 599aa09ab8
15 changed files with 115 additions and 43 deletions
+15 -1
View File
@@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu, shell } = require('electron')
const { app, BrowserWindow, Menu, shell, dialog } = require('electron')
const path = require('path')
const DEV_URL = process.env.VITE_DEV_SERVER_URL || ''
@@ -20,6 +20,20 @@ function createWindow() {
}
})
Menu.setApplicationMenu(null)
// 下载接管:导出的 JSON/CSV/Markdown 弹出标准保存对话框
win.webContents.session.on('will-download', (event, item, webContents) => {
const result = dialog.showSaveDialogSync(win, {
title: '保存文件',
defaultPath: path.join(app.getPath('downloads'), item.getFilename())
})
if (!result) {
event.preventDefault()
return
}
item.setSavePath(result)
})
win.webContents.setWindowOpenHandler(({ url }) => {
if (/^https?:/i.test(url)) shell.openExternal(url)
return { action: 'deny' }