-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
91 lines (75 loc) · 2.27 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { app, BrowserWindow, ipcMain, Menu } = require('electron')
const path = require("path")
function createWindow() {
Menu.setApplicationMenu(null)
// 创建浏览器窗口
let win = new BrowserWindow({
title: "聚合渠道打包",
width: 1000,
height: 800,
minWidth: 1000,
minHeight: 800,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true
}
})
// win.webContents.openDevTools()
// 加载index.html文件
win.loadFile('index.html')
}
app.on('window-all-closed', function (event) {
//...
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('ready', createWindow)
var fork = require('child_process').fork
var gamepath = ""
var workers = []
var packagedCount = 0
var worker = fork(`${__dirname}/works.js`)
var sender
worker.on('message', m => {
if (m.type == "caches") {
sender.send("caches", "已清除")
} else if (m.type == "game_package") {
sender.send("game_package", "已编绎")
}
})
ipcMain.on('gameinfo', (event, path) => {
gamepath = path
event.sender.send("msg", "I: 游戏编绎中...")
sender = event.sender
worker.send({ type: "game_package", value: gamepath })
})
ipcMain.on('caches', (event) => {
sender = event.sender
event.sender.send("msg", "I: 缓存清除中...")
worker.send({ type: "caches", value: "" })
})
ipcMain.on('packages', (event, packages) => {
for (var i = 0; i < packages.length; i++) {
var worker = fork(`${__dirname}/works.js`)
workers.push(worker)
}
workers.forEach((worker, i) => {
worker.on('message', (m) => {
if (m.type == "end") {
packagedCount++
if (packagedCount == workers.length) {
event.sender.send('end', '')
packagedCount = 0
delete workers
workers = []
}
} else {
event.sender.send(m.type, m.value)
}
})
worker.send({ type: 'package', value: packages[i], path: gamepath })
})
})