58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
const { app, BrowserWindow, Menu, shell, dialog } = require('electron')
|
|
const path = require('path')
|
|
|
|
const DEV_URL = process.env.VITE_DEV_SERVER_URL || ''
|
|
|
|
function createWindow() {
|
|
const win = new BrowserWindow({
|
|
width: 1240,
|
|
height: 820,
|
|
minWidth: 940,
|
|
minHeight: 620,
|
|
title: '实习工作日志',
|
|
icon: path.join(__dirname, '..', 'build', 'icon.png'),
|
|
autoHideMenuBar: true,
|
|
backgroundColor: '#FFFFFF',
|
|
webPreferences: {
|
|
contextIsolation: true,
|
|
nodeIntegration: false,
|
|
spellcheck: false
|
|
}
|
|
})
|
|
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' }
|
|
})
|
|
if (DEV_URL) {
|
|
win.loadURL(DEV_URL)
|
|
} else {
|
|
win.loadFile(path.join(__dirname, '..', 'dist', 'index.html'))
|
|
}
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
createWindow()
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
})
|
|
})
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit()
|
|
})
|