-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
55 lines (50 loc) · 1.54 KB
/
Copy pathmain.js
File metadata and controls
55 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// eslint-disable-next-line no-undef
const { app, BrowserWindow } = require('electron')
const path = require('path')
const dotenv = require('dotenv')
dotenv.config({ path: path.join(__dirname, '.env') });
const isDEV = app.isPackaged
if (isDEV) {
dotenv.config({ path: path.join(__dirname, '.env.production') });
} else {
dotenv.config({ path: path.join(__dirname, '.env.development') });
}
let mainWindow = null
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 1800,
height: 1200,
// 关闭默认顶部菜单
autoHideMenuBar: true,
webPreferences: {
// 实现用操作系统级别的线程来跑JavaScript
nodeIntegrationInWorker: true
}
})
if (process.env.NODE_ENV === 'development') {
mainWindow.loadURL('http://localhost:5173')
} else {
mainWindow.loadFile(path.join(__dirname, 'dist', 'index.html'))
}
mainWindow.setTitle(process.env.VITE_APP_TITLE)
// 开发环境下打开调试工具
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools({ mode: 'detach' })
} else {
// mainWindow.webContents.openDevTools({ mode: 'detach' })
}
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
// eslint-disable-next-line no-undef
if (process.platform !== 'darwin') {
app.quit()
}
})