44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const { app, BrowserWindow, Menu, shell } = 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)
|
|
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()
|
|
})
|