-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainBuild.js
51 lines (48 loc) · 1.3 KB
/
mainBuild.js
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
/**
* app 模块,它控制应用程序的事件生命周期
* BrowserWindow 模块,它创建和管理应用程序 窗口。
*/
const { app, BrowserWindow } = require('electron')
const path = require('path')
const initialiseEventListeners = require('./server/event/event')
const initialiseTerminalListeners = require('./server/event/terminalEvent')
const url = require('url')
function createWindow() {
let win = new BrowserWindow({
width: 1024,
height: 760,
frame: true, //设置为 false 时可以创建一个无边框窗口
minHeight: 760,
minWidth: 1024,
webPreferences: {
nodeIntegration: true,
contextIsolation: true,
preload: path.resolve(__dirname, './server/preload.js'),
webSecurity: false, //解决跨域
},
show: false, // new BrowserWindow创建后先隐藏
})
// 加载页面
win.loadURL(
url.format({
pathname: path.join(__dirname, './index.html'), // 修改这里
protocol: 'file:',
slashes: true,
})
)
// mainWindow.loadFile(path.join(__dirname, 'index.html'))
//关闭页面
win.on('closed', function () {
win = null
})
// 开发者工具
win.openDevTools()
win.on('ready-to-show', function () {
win.show() // 初始化后再显示
})
initialiseEventListeners()
initialiseTerminalListeners(win)
}
app.whenReady().then(() => {
createWindow()
})