fix: 修复导出下载链路(Electron 保存对话框 + 原生文件写入 + revoke 竞态)
This commit is contained in:
@@ -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' }
|
||||
|
||||
Reference in New Issue
Block a user