fix: 桌面导出改用 IPC 直写(另存为对话框),设置页显示版本号
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const { app, BrowserWindow, Menu, shell, dialog } = require('electron')
|
||||
const { app, BrowserWindow, Menu, shell, dialog, ipcMain } = require('electron')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const DEV_URL = process.env.VITE_DEV_SERVER_URL || ''
|
||||
|
||||
@@ -16,6 +17,7 @@ function createWindow() {
|
||||
webPreferences: {
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
preload: path.join(__dirname, 'preload.cjs'),
|
||||
spellcheck: false
|
||||
}
|
||||
})
|
||||
@@ -45,6 +47,18 @@ function createWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
// 导出文件:渲染进程请求主进程保存(标准另存为对话框 + 直接写盘)
|
||||
ipcMain.handle('export-file', async (event, payload) => {
|
||||
const win = BrowserWindow.fromWebContents(event.sender)
|
||||
const result = await dialog.showSaveDialog(win, {
|
||||
title: '保存文件',
|
||||
defaultPath: path.join(app.getPath('downloads'), payload.filename)
|
||||
})
|
||||
if (result.canceled || !result.filePath) return { saved: false, path: '' }
|
||||
fs.writeFileSync(result.filePath, payload.content, 'utf-8')
|
||||
return { saved: true, path: result.filePath }
|
||||
})
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
app.on('activate', () => {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
const { contextBridge, ipcRenderer } = require('electron')
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
saveFile: (filename, content) => ipcRenderer.invoke('export-file', { filename, content })
|
||||
})
|
||||
Reference in New Issue
Block a user